632f422d1ff7e8431a61c82097bfc33e7172af07
[openwrt/staging/ldir.git] /
1 From 5652d1741574eb89cc02576e50ee3e348bd6dd77 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= <kabel@kernel.org>
3 Date: Wed, 4 Oct 2023 11:19:03 +0200
4 Subject: [PATCH 1/2] net: dsa: qca8k: fix regmap bulk read/write methods on
5 big endian systems
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 Commit c766e077d927 ("net: dsa: qca8k: convert to regmap read/write
11 API") introduced bulk read/write methods to qca8k's regmap.
12
13 The regmap bulk read/write methods get the register address in a buffer
14 passed as a void pointer parameter (the same buffer contains also the
15 read/written values). The register address occupies only as many bytes
16 as it requires at the beginning of this buffer. For example if the
17 .reg_bits member in regmap_config is 16 (as is the case for this
18 driver), the register address occupies only the first 2 bytes in this
19 buffer, so it can be cast to u16.
20
21 But the original commit implementing these bulk read/write methods cast
22 the buffer to u32:
23 u32 reg = *(u32 *)reg_buf & U16_MAX;
24 taking the first 4 bytes. This works on little endian systems where the
25 first 2 bytes of the buffer correspond to the low 16-bits, but it
26 obviously cannot work on big endian systems.
27
28 Fix this by casting the beginning of the buffer to u16 as
29 u32 reg = *(u16 *)reg_buf;
30
31 Fixes: c766e077d927 ("net: dsa: qca8k: convert to regmap read/write API")
32 Signed-off-by: Marek BehĂșn <kabel@kernel.org>
33 Tested-by: Christian Marangi <ansuelsmth@gmail.com>
34 Reviewed-by: Christian Marangi <ansuelsmth@gmail.com>
35 Signed-off-by: David S. Miller <davem@davemloft.net>
36 ---
37 drivers/net/dsa/qca/qca8k-8xxx.c | 4 ++--
38 1 file changed, 2 insertions(+), 2 deletions(-)
39
40 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
41 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
42 @@ -504,8 +504,8 @@ qca8k_bulk_read(void *ctx, const void *r
43 void *val_buf, size_t val_len)
44 {
45 int i, count = val_len / sizeof(u32), ret;
46 - u32 reg = *(u32 *)reg_buf & U16_MAX;
47 struct qca8k_priv *priv = ctx;
48 + u32 reg = *(u16 *)reg_buf;
49
50 if (priv->mgmt_master &&
51 !qca8k_read_eth(priv, reg, val_buf, val_len))
52 @@ -526,8 +526,8 @@ qca8k_bulk_gather_write(void *ctx, const
53 const void *val_buf, size_t val_len)
54 {
55 int i, count = val_len / sizeof(u32), ret;
56 - u32 reg = *(u32 *)reg_buf & U16_MAX;
57 struct qca8k_priv *priv = ctx;
58 + u32 reg = *(u16 *)reg_buf;
59 u32 *val = (u32 *)val_buf;
60
61 if (priv->mgmt_master &&