Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ieee802154: ca8210: Use proper setters and getters for bitwise types

Sparse complains that the driver doesn't respect the bitwise types:

drivers/net/ieee802154/ca8210.c:1796:27: warning: incorrect type in assignment (different base types)
drivers/net/ieee802154/ca8210.c:1796:27: expected restricted __le16 [addressable] [assigned] [usertype] pan_id
drivers/net/ieee802154/ca8210.c:1796:27: got unsigned short [usertype]
drivers/net/ieee802154/ca8210.c:1801:25: warning: incorrect type in assignment (different base types)
drivers/net/ieee802154/ca8210.c:1801:25: expected restricted __le16 [addressable] [assigned] [usertype] pan_id
drivers/net/ieee802154/ca8210.c:1801:25: got unsigned short [usertype]
drivers/net/ieee802154/ca8210.c:1928:28: warning: incorrect type in argument 3 (different base types)
drivers/net/ieee802154/ca8210.c:1928:28: expected unsigned short [usertype] dst_pan_id
drivers/net/ieee802154/ca8210.c:1928:28: got restricted __le16 [addressable] [usertype] pan_id

Use proper setters and getters for bitwise types.

Note, in accordance with [1] the protocol is little endian.

Link: https://www.cascoda.com/wp-content/uploads/2018/11/CA-8210_datasheet_0418.pdf [1]
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/20250305105656.2133487-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>

authored by

Andy Shevchenko and committed by
Stefan Schmidt
169b2262 f130a0cc

+4 -5
+4 -5
drivers/net/ieee802154/ca8210.c
··· 1446 1446 command.pdata.data_req.src_addr_mode = src_addr_mode; 1447 1447 command.pdata.data_req.dst.mode = dst_address_mode; 1448 1448 if (dst_address_mode != MAC_MODE_NO_ADDR) { 1449 - command.pdata.data_req.dst.pan_id[0] = LS_BYTE(dst_pan_id); 1450 - command.pdata.data_req.dst.pan_id[1] = MS_BYTE(dst_pan_id); 1449 + put_unaligned_le16(dst_pan_id, command.pdata.data_req.dst.pan_id); 1451 1450 if (dst_address_mode == MAC_MODE_SHORT_ADDR) { 1452 1451 command.pdata.data_req.dst.address[0] = LS_BYTE( 1453 1452 dst_addr->short_address ··· 1794 1795 } 1795 1796 hdr.source.mode = data_ind[0]; 1796 1797 dev_dbg(&priv->spi->dev, "srcAddrMode: %#03x\n", hdr.source.mode); 1797 - hdr.source.pan_id = *(u16 *)&data_ind[1]; 1798 + hdr.source.pan_id = cpu_to_le16(get_unaligned_le16(&data_ind[1])); 1798 1799 dev_dbg(&priv->spi->dev, "srcPanId: %#06x\n", hdr.source.pan_id); 1799 1800 memcpy(&hdr.source.extended_addr, &data_ind[3], 8); 1800 1801 hdr.dest.mode = data_ind[11]; 1801 1802 dev_dbg(&priv->spi->dev, "dstAddrMode: %#03x\n", hdr.dest.mode); 1802 - hdr.dest.pan_id = *(u16 *)&data_ind[12]; 1803 + hdr.dest.pan_id = cpu_to_le16(get_unaligned_le16(&data_ind[12])); 1803 1804 dev_dbg(&priv->spi->dev, "dstPanId: %#06x\n", hdr.dest.pan_id); 1804 1805 memcpy(&hdr.dest.extended_addr, &data_ind[14], 8); 1805 1806 ··· 1926 1927 status = mcps_data_request( 1927 1928 header.source.mode, 1928 1929 header.dest.mode, 1929 - header.dest.pan_id, 1930 + le16_to_cpu(header.dest.pan_id), 1930 1931 (union macaddr *)&header.dest.extended_addr, 1931 1932 skb->len - mac_len, 1932 1933 &skb->data[mac_len],