smsc W=1 warning fixes
Subsystems (3)
v3 cover smsc W=1 warning fixes
Fixup various W=1 warnings, and then add COMPILE_TEST support, which explains why these where missed on the previous pass.
v2:
Use while (0)
Rework buffer alignment to make it clearer
v3:
Access the length from the hardware and Use __always_unused to tell the compiler we want to discard the value.
Andrew Lunn (7):
drivers: net: smc91x: Fix set but unused W=1 warning
drivers: net: smc91x: Fix missing kerneldoc reported by W=1
drivers: net: smc911x: Work around set but unused status
drivers: net: smc911x: Fix set but unused status because of DBG macro
drivers: net: smc911x: Fix passing wrong number of parameters to DBG()
macro
drivers: net: smc911x: Fix cast from pointer to integer of different
size
drivers: net: smsc: Add COMPILE_TEST support
drivers/net/ethernet/smsc/Kconfig | 6 +++--- drivers/net/ethernet/smsc/smc911x.c | 17 +++++++++-------- drivers/net/ethernet/smsc/smc91x.c | 9 ++++++++- 3 files changed, 20 insertions(+), 12 deletions(-)
Signature · 1 line
2.29.2
PATCH v3 1/7 drivers: net: smc91x: Fix set but unused W=1 warning
drivers/net/ethernet/smsc/smc91x.c:706:51: warning: variable ‘pkt_len’ set but not used [-Wunused-but-set-variable]
706 | unsigned int saved_packet, packet_no, tx_status, pkt_len;
The read of the packet length in the descriptor probably needs to be kept in order to keep the hardware happy. So tell the compiler we don't expect to use the value by using the __always_unused attribute.
--- drivers/net/ethernet/smsc/smc91x.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/smsc/smc91x.c +2 -1
@@ -703,7 +703,8 @@ static void smc_tx(struct net_device *dev) {struct smc_local *lp =netdev_priv (dev);void __iomem *ioaddr = lp->base; -unsigned int saved_packet, packet_no, tx_status, pkt_len; +unsigned int saved_packet, packet_no, tx_status; +unsigned int pkt_len__always_unused ;DBG (3 , dev,"%s\n" , __func__);
Signature · 1 line
2.29.2
PATCH v3 2/7 drivers: net: smc91x: Fix missing kerneldoc reported by W=1
In reply to Andrew Lunndrivers/net/ethernet/smsc/smc91x.c:2199: warning: Function parameter or member 'dev' not described in 'try_toggle_control_gpio' drivers/net/ethernet/smsc/smc91x.c:2199: warning: Function parameter or member 'desc' not described in 'try_toggle_control_gpio' drivers/net/ethernet/smsc/smc91x.c:2199: warning: Function parameter or member 'name' not described in 'try_toggle_control_gpio' drivers/net/ethernet/smsc/smc91x.c:2199: warning: Function parameter or member 'index' not described in 'try_toggle_control_gpio' drivers/net/ethernet/smsc/smc91x.c:2199: warning: Function parameter or member 'value' not described in 'try_toggle_control_gpio' drivers/net/ethernet/smsc/smc91x.c:2199: warning: Function parameter or member 'nsdelay' not described in 'try_toggle_control_gpio'
Document these parameters.
--- drivers/net/ethernet/smsc/smc91x.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/smsc/smc91x.c +6 -0
@@ -2192,6 +2192,12 @@ MODULE_DEVICE_TABLE(of, smc91x_match);/** * of_try_set_control_gpio - configure a gpio if it exists +* @dev: net device +* @desc: where to store the GPIO descriptor, if it exists +* @name: name of the GPIO in DT +* @index: index of the GPIO in DT +* @value: set the GPIO to this value +* @nsdelay: delay before setting the GPIO */ static int try_toggle_control_gpio(struct device *dev, struct gpio_desc **desc,
Signature · 1 line
2.29.2
PATCH v3 3/7 drivers: net: smc911x: Work around set but unused status
In reply to Andrew Lunndrivers/net/ethernet/smsc/smc911x.c: In function ‘smc911x_phy_interrupt’:drivers/net/ethernet/smsc/smc911x.c:976:6: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
976 | int status;
A comment indicates the status needs to be read from the PHY, otherwise bad things happen. But due to the macro magic, it is hard to perform the read without assigning it to a variable. So add _always_unused attribute to status to tell the compiler we don't expect to use the value.
--- drivers/net/ethernet/smsc/smc911x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/smsc/smc911x.c +2 -2
@@ -879,7 +879,7 @@ static void smc911x_phy_configure(struct work_struct *work)int phyaddr = lp->mii.phy_id;int my_phy_caps;/* My PHY capabilities */ int my_ad_caps;/* My Advertised capabilities */ -int status; +int status__always_unused ;unsigned long flags;DBG (SMC_DEBUG_FUNC , dev,"--> %s()\n" , __func__);
@@ -973,7 +973,7 @@ static void smc911x_phy_interrupt(struct net_device *dev) {struct smc911x_local *lp =netdev_priv (dev);int phyaddr = lp->mii.phy_id; -int status; +int status__always_unused ;DBG (SMC_DEBUG_FUNC , dev,"--> %s\n" , __func__);
Signature · 1 line
2.29.2
PATCH v3 4/7 drivers: net: smc911x: Fix set but unused status because of DBG macro
In reply to Andrew Lunndrivers/net/ethernet/smsc/smc911x.c: In function ‘smc911x_timeout’:drivers/net/ethernet/smsc/smc911x.c:1251:6: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
1251 | int status, mask;
The status is read in order to print it via the DBG macro. However, due to the way DBG is disabled, the compiler never sees it being used.
Change the DBG macro to actually make use of the passed parameters, and the leave the optimiser to remove the unwanted code inside the while (0).
--- drivers/net/ethernet/smsc/smc911x.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/smsc/smc911x.c +4 -1
@@ -102,7 +102,10 @@ MODULE_ALIAS("platform:smc911x"); #define PRINTK(dev, args...) netdev_info(dev, args)#else -#define DBG(n, dev, args...) do { } while (0) +#define DBG(n, dev, args...) \ + while (0) { \ + netdev_dbg(dev, args); \ + } #define PRINTK(dev, args...) netdev_dbg(dev, args)#endif
Signature · 1 line
2.29.2
PATCH v3 5/7 drivers: net: smc911x: Fix passing wrong number of parameters to DBG() macro
In reply to Andrew LunnNow that the compiler always sees the parameters passed to the DBG() macro, it gives an error message about wrong parameters. The comment says it all:
/* ndev is not valid yet, so avoid passing it in. */ DBG(SMC_DEBUG_FUNC, "--> %s\n", __func__);
You cannot not just pass a parameter!
The DBG does not seem to have any real value, to just remove it.
--- drivers/net/ethernet/smsc/smc911x.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/ethernet/smsc/smc911x.c +0 -2
@@ -2047,8 +2047,6 @@ static int smc911x_drv_probe(struct platform_device *pdev)void __iomem *addr;int ret; -/* ndev is not valid yet, so avoid passing it in. */ -DBG (SMC_DEBUG_FUNC ,"--> %s\n" , __func__); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res) { ret = -ENODEV ;
Signature · 1 line
2.29.2
PATCH v3 6/7 drivers: net: smc911x: Fix cast from pointer to integer of different size
In reply to Andrew Lunndrivers/net/ethernet/smsc/smc911x.c: In function ‘smc911x_hardware_send_pkt’:drivers/net/ethernet/smsc/smc911x.c:471:11: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
471 | cmdA = (((u32)skb->data & 0x3) << 16) |
When built on 64bit targets, the skb->data pointer cannot be cast to a u32 in a meaningful way. Use uintptr_t instead.
--- drivers/net/ethernet/smsc/smc911x.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/smsc/smc911x.c +3 -3
@@ -465,9 +465,9 @@ static void smc911x_hardware_send_pkt(struct net_device *dev)TX_CMD_A_INT_FIRST_SEG_ |TX_CMD_A_INT_LAST_SEG_ | skb->len;#else - buf = (char *)((u32 )skb->data & ~0x3 ); - len = (skb->len +3 + ((u32 )skb->data &3 )) & ~0x3 ; - cmdA = (((u32 )skb->data &0x3 ) <<16 ) | + buf = (char *)((uintptr_t )skb->data & ~0x3 ); + len = (skb->len +3 + ((uintptr_t )skb->data &3 )) & ~0x3 ; + cmdA = (((uintptr_t )skb->data &0x3 ) <<16 ) |TX_CMD_A_INT_FIRST_SEG_ |TX_CMD_A_INT_LAST_SEG_ | skb->len;#endif
Signature · 1 line
2.29.2
PATCH v3 7/7 drivers: net: smsc: Add COMPILE_TEST support
In reply to Andrew LunnImprove the build testing of these SMSC drivers by enabling them when COMPILE_TEST is selected.
--- drivers/net/ethernet/smsc/Kconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/smsc/Kconfig +3 -3
@@ -8,7 +8,7 @@ config NET_VENDOR_SMSC default y depends on ARM || ARM64 || ATARI_ETHERNAT || COLDFIRE || \ ISA || MAC || MIPS || NIOS2 || PCI || \ - PCMCIA || SUPERH || XTENSA || H8300 + PCMCIA || SUPERH || XTENSA || H8300 || COMPILE_TEST help If you have a network (Ethernet) card belonging to this class, say Y.
@@ -39,7 +39,7 @@ config SMC91X select MII depends on !OF || GPIOLIB depends on ARM || ARM64 || ATARI_ETHERNAT || COLDFIRE || \ - MIPS || NIOS2 || SUPERH || XTENSA || H8300 + MIPS || NIOS2 || SUPERH || XTENSA || H8300 || COMPILE_TEST help This is a driver for SMC's 91x series of Ethernet chipsets, including the SMC91C94 and the SMC91C111. Say Y if you want it
@@ -78,7 +78,7 @@ config SMC911X tristate "SMSC LAN911[5678] support" select CRC32 select MII - depends on (ARM || SUPERH) + depends on (ARM || SUPERH || COMPILE_TEST) help This is a driver for SMSC's LAN911x series of Ethernet chipsets including the new LAN9115, LAN9116, LAN9117, and LAN9118.
Signature · 1 line
2.29.2
Quoted 10 lines · On Tue, 10 Nov 2020 04:02:41 +0100 Andrew Lunn wrote:
Fixup various W=1 warnings, and then add
COMPILE_TESTsupport, which explains why these where missed on the previous pass.v2:
Use while (0)
Rework buffer alignment to make it clearerv3:
Access the length from the hardware and Use__always_unusedto tell the compiler we want to discard the value.
Applied, thank you!