Skip to content

Commit 5652d17

Browse files
elkablodavem330
authored andcommitted
net: dsa: qca8k: fix regmap bulk read/write methods on big endian systems
Commit c766e07 ("net: dsa: qca8k: convert to regmap read/write API") introduced bulk read/write methods to qca8k's regmap. The regmap bulk read/write methods get the register address in a buffer passed as a void pointer parameter (the same buffer contains also the read/written values). The register address occupies only as many bytes as it requires at the beginning of this buffer. For example if the .reg_bits member in regmap_config is 16 (as is the case for this driver), the register address occupies only the first 2 bytes in this buffer, so it can be cast to u16. But the original commit implementing these bulk read/write methods cast the buffer to u32: u32 reg = *(u32 *)reg_buf & U16_MAX; taking the first 4 bytes. This works on little endian systems where the first 2 bytes of the buffer correspond to the low 16-bits, but it obviously cannot work on big endian systems. Fix this by casting the beginning of the buffer to u16 as u32 reg = *(u16 *)reg_buf; Fixes: c766e07 ("net: dsa: qca8k: convert to regmap read/write API") Signed-off-by: Marek Behún <kabel@kernel.org> Tested-by: Christian Marangi <ansuelsmth@gmail.com> Reviewed-by: Christian Marangi <ansuelsmth@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 109c2de commit 5652d17

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/net/dsa/qca/qca8k-8xxx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ qca8k_bulk_read(void *ctx, const void *reg_buf, size_t reg_len,
505505
void *val_buf, size_t val_len)
506506
{
507507
int i, count = val_len / sizeof(u32), ret;
508-
u32 reg = *(u32 *)reg_buf & U16_MAX;
509508
struct qca8k_priv *priv = ctx;
509+
u32 reg = *(u16 *)reg_buf;
510510

511511
if (priv->mgmt_master &&
512512
!qca8k_read_eth(priv, reg, val_buf, val_len))
@@ -527,8 +527,8 @@ qca8k_bulk_gather_write(void *ctx, const void *reg_buf, size_t reg_len,
527527
const void *val_buf, size_t val_len)
528528
{
529529
int i, count = val_len / sizeof(u32), ret;
530-
u32 reg = *(u32 *)reg_buf & U16_MAX;
531530
struct qca8k_priv *priv = ctx;
531+
u32 reg = *(u16 *)reg_buf;
532532
u32 *val = (u32 *)val_buf;
533533

534534
if (priv->mgmt_master &&

0 commit comments

Comments
 (0)