All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: 3com: 3c59x: remove set but not used variable 'mii_reg1'
@ 2020-01-03 12:19 yu kuai
  2020-01-03 14:46 ` Matthew Wilcox
  0 siblings, 1 reply; 10+ messages in thread
From: yu kuai @ 2020-01-03 12:19 UTC (permalink / raw)
  To: klassert, davem, hkallweit1, jakub.kicinski, hslester96, mst
  Cc: yang.wei9, willy, netdev, linux-kernel, yukuai3, yi.zhang, zhengbin13

Fixes gcc '-Wunused-but-set-variable' warning:

drivers/net/ethernet/3com/3c59x.c: In function ‘vortex_up’:
drivers/net/ethernet/3com/3c59x.c:1551:9: warning: variable
‘mii_reg1’ set but not used [-Wunused-but-set-variable]

It is never used, and so can be removed.

Signed-off-by: yu kuai <yukuai3@huawei.com>
---
 drivers/net/ethernet/3com/3c59x.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/3com/3c59x.c b/drivers/net/ethernet/3com/3c59x.c
index fc046797c0ea..6e537e5dc208 100644
--- a/drivers/net/ethernet/3com/3c59x.c
+++ b/drivers/net/ethernet/3com/3c59x.c
@@ -1548,7 +1548,7 @@ vortex_up(struct net_device *dev)
 	struct vortex_private *vp = netdev_priv(dev);
 	void __iomem *ioaddr = vp->ioaddr;
 	unsigned int config;
-	int i, mii_reg1, mii_reg5, err = 0;
+	int i, mii_reg5, err = 0;
 
 	if (VORTEX_PCI(vp)) {
 		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);	/* Go active */
@@ -1605,7 +1605,6 @@ vortex_up(struct net_device *dev)
 	window_write32(vp, config, 3, Wn3_Config);
 
 	if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
-		mii_reg1 = mdio_read(dev, vp->phys[0], MII_BMSR);
 		mii_reg5 = mdio_read(dev, vp->phys[0], MII_LPA);
 		vp->partner_flow_ctrl = ((mii_reg5 & 0x0400) != 0);
 		vp->mii.full_duplex = vp->full_duplex;
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] net: 3com: 3c59x: remove set but not used variable 'mii_reg1'
  2020-01-03 12:19 [PATCH] net: 3com: 3c59x: remove set but not used variable 'mii_reg1' yu kuai
@ 2020-01-03 14:46 ` Matthew Wilcox
  2020-01-03 14:59   ` Michal Kubecek
  2020-01-03 17:53   ` Andrew Lunn
  0 siblings, 2 replies; 10+ messages in thread
From: Matthew Wilcox @ 2020-01-03 14:46 UTC (permalink / raw)
  To: yu kuai
  Cc: klassert, davem, hkallweit1, jakub.kicinski, hslester96, mst,
	yang.wei9, netdev, linux-kernel, yi.zhang, zhengbin13

On Fri, Jan 03, 2020 at 08:19:07PM +0800, yu kuai wrote:
> Fixes gcc '-Wunused-but-set-variable' warning:
> 
> drivers/net/ethernet/3com/3c59x.c: In function ‘vortex_up’:
> drivers/net/ethernet/3com/3c59x.c:1551:9: warning: variable
> ‘mii_reg1’ set but not used [-Wunused-but-set-variable]
> 
> It is never used, and so can be removed.
...
>  	if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
> -		mii_reg1 = mdio_read(dev, vp->phys[0], MII_BMSR);
>  		mii_reg5 = mdio_read(dev, vp->phys[0], MII_LPA);

I know nothing about the MII interface, but in general this is not
a safe thing to do.  You're removing a read from a device register.
Register reads can have side effects.  I'm actually quite surprised
that GCC emits this warning, since there should be some kind of
volatile cast in mdio_read() to let GCC know that something unusual
is going on here.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] net: 3com: 3c59x: remove set but not used variable 'mii_reg1'
  2020-01-03 14:46 ` Matthew Wilcox
@ 2020-01-03 14:59   ` Michal Kubecek
  2020-01-03 17:53   ` Andrew Lunn
  1 sibling, 0 replies; 10+ messages in thread
From: Michal Kubecek @ 2020-01-03 14:59 UTC (permalink / raw)
  To: netdev
  Cc: Matthew Wilcox, yu kuai, klassert, davem, hkallweit1,
	jakub.kicinski, hslester96, mst, yang.wei9, linux-kernel,
	yi.zhang, zhengbin13

On Fri, Jan 03, 2020 at 06:46:23AM -0800, Matthew Wilcox wrote:
> On Fri, Jan 03, 2020 at 08:19:07PM +0800, yu kuai wrote:
> > Fixes gcc '-Wunused-but-set-variable' warning:
> > 
> > drivers/net/ethernet/3com/3c59x.c: In function ‘vortex_up’:
> > drivers/net/ethernet/3com/3c59x.c:1551:9: warning: variable
> > ‘mii_reg1’ set but not used [-Wunused-but-set-variable]
> > 
> > It is never used, and so can be removed.
> ...
> >  	if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
> > -		mii_reg1 = mdio_read(dev, vp->phys[0], MII_BMSR);
> >  		mii_reg5 = mdio_read(dev, vp->phys[0], MII_LPA);
> 
> I know nothing about the MII interface, but in general this is not
> a safe thing to do.  You're removing a read from a device register.
> Register reads can have side effects.  I'm actually quite surprised
> that GCC emits this warning, since there should be some kind of
> volatile cast in mdio_read() to let GCC know that something unusual
> is going on here.

Removing the call may be wrong (and certainly isn't obviously correct)
but the warning makes sense, IMHO: if the return value is not used
anywhere, there is no point assigning it to a variable.

Michal Kubecek

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] net: 3com: 3c59x: remove set but not used variable 'mii_reg1'
  2020-01-03 14:46 ` Matthew Wilcox
  2020-01-03 14:59   ` Michal Kubecek
@ 2020-01-03 17:53   ` Andrew Lunn
  2020-01-03 18:17     ` Michal Kubecek
  2020-01-03 19:13     ` Vladimir Oltean
  1 sibling, 2 replies; 10+ messages in thread
From: Andrew Lunn @ 2020-01-03 17:53 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: yu kuai, klassert, davem, hkallweit1, jakub.kicinski, hslester96,
	mst, yang.wei9, netdev, linux-kernel, yi.zhang, zhengbin13

On Fri, Jan 03, 2020 at 06:46:23AM -0800, Matthew Wilcox wrote:
> On Fri, Jan 03, 2020 at 08:19:07PM +0800, yu kuai wrote:
> > Fixes gcc '-Wunused-but-set-variable' warning:
> > 
> > drivers/net/ethernet/3com/3c59x.c: In function ‘vortex_up’:
> > drivers/net/ethernet/3com/3c59x.c:1551:9: warning: variable
> > ‘mii_reg1’ set but not used [-Wunused-but-set-variable]
> > 
> > It is never used, and so can be removed.
> ...
> >  	if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
> > -		mii_reg1 = mdio_read(dev, vp->phys[0], MII_BMSR);
> >  		mii_reg5 = mdio_read(dev, vp->phys[0], MII_LPA);
> 
> I know nothing about the MII interface, but in general this is not
> a safe thing to do.

Hi Matthew

I fully agree about the general case. However, reading the MII_BMSR
should not have any side affects. It would be an odd Ethernet PHY if
it did.

But I am curious why this read is here. There is a slim change the
MDIO bus is broken, and this is a workaround. So it would be good if
somebody dug into the history and found out when this read was added
and if there are any comments about why it is there. Or if the usage
of mii_reg1 as been removed at some point, and the read was not
cleaned up.

   Andrew

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] net: 3com: 3c59x: remove set but not used variable 'mii_reg1'
  2020-01-03 17:53   ` Andrew Lunn
@ 2020-01-03 18:17     ` Michal Kubecek
  2020-01-03 19:13     ` Vladimir Oltean
  1 sibling, 0 replies; 10+ messages in thread
From: Michal Kubecek @ 2020-01-03 18:17 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, Matthew Wilcox, yu kuai, klassert, davem,
	hkallweit1, jakub.kicinski, hslester96, mst, yang.wei9,
	linux-kernel, yi.zhang, zhengbin13

On Fri, Jan 03, 2020 at 06:53:18PM +0100, Andrew Lunn wrote:
> On Fri, Jan 03, 2020 at 06:46:23AM -0800, Matthew Wilcox wrote:
> > On Fri, Jan 03, 2020 at 08:19:07PM +0800, yu kuai wrote:
> > > Fixes gcc '-Wunused-but-set-variable' warning:
> > > 
> > > drivers/net/ethernet/3com/3c59x.c: In function ‘vortex_up’:
> > > drivers/net/ethernet/3com/3c59x.c:1551:9: warning: variable
> > > ‘mii_reg1’ set but not used [-Wunused-but-set-variable]
> > > 
> > > It is never used, and so can be removed.
> > ...
> > >  	if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
> > > -		mii_reg1 = mdio_read(dev, vp->phys[0], MII_BMSR);
> > >  		mii_reg5 = mdio_read(dev, vp->phys[0], MII_LPA);
> > 
> > I know nothing about the MII interface, but in general this is not
> > a safe thing to do.
> 
> Hi Matthew
> 
> I fully agree about the general case. However, reading the MII_BMSR
> should not have any side affects. It would be an odd Ethernet PHY if
> it did.
> 
> But I am curious why this read is here. There is a slim change the
> MDIO bus is broken, and this is a workaround. So it would be good if
> somebody dug into the history and found out when this read was added
> and if there are any comments about why it is there. Or if the usage
> of mii_reg1 as been removed at some point, and the read was not
> cleaned up.

I tried to dig a bit and found that originally (before git), there was
also

	if (vortex_debug > 1)
		printk(KERN_INFO "%s: MII #%d status %4.4x, link partner capability %4.4x,"
		       " info1 %04x, setting %s-duplex.\n",
		       dev->name, vp->phys[0],
		       mii_reg1, mii_reg5,
		       vp->info1, ((vp->info1 & 0x8000) || vp->full_duplex) ? "full" : "half");

The whole mii code in vortex_up() was removed by commit 125d5ce8a4e9
("[PATCH] 3c59x: use mii_check_media") and later the mdio_read() calls
were restored by commit 09ce3512dcad ("[PATCH] 3c59x: fix networking for
10base2 NICs") with "Also brought back some mii stuff to be sure that it
does not break something else", but without the debugging printk().

It's not really a proof that reading MII_BMSR was only needed for the
log message but there is a good chance it was. I'm afraid we won't be
able to find anyone who would be able to tell for sure after all those
years.

Michal

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] net: 3com: 3c59x: remove set but not used variable 'mii_reg1'
  2020-01-03 17:53   ` Andrew Lunn
  2020-01-03 18:17     ` Michal Kubecek
@ 2020-01-03 19:13     ` Vladimir Oltean
  2020-01-03 19:17       ` Florian Fainelli
  1 sibling, 1 reply; 10+ messages in thread
From: Vladimir Oltean @ 2020-01-03 19:13 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Matthew Wilcox, yu kuai, klassert, David S. Miller,
	Heiner Kallweit, Jakub Kicinski, hslester96, mst, yang.wei9,
	netdev, lkml, yi.zhang, zhengbin13

Hi Andrew,

On Fri, 3 Jan 2020 at 19:54, Andrew Lunn <andrew@lunn.ch> wrote:
>
> I fully agree about the general case. However, reading the MII_BMSR
> should not have any side affects. It would be an odd Ethernet PHY if
> it did.

This is not really correct. As far as I know the clause 22 spec
requires the link status bit in BMSR to be latching low, so that
momentary losses of link can be caught post-facto.
In fact, even genphy_update_link treats this case:

    /* The link state is latched low so that momentary link
     * drops can be detected. Do not double-read the status
     * in polling mode to detect such short link drops.
     */
    if (!phy_polling_mode(phydev)) {
        status = phy_read(phydev, MII_BMSR);
        if (status < 0)
            return status;
        else if (status & BMSR_LSTATUS)
            goto done;
    }

So no, reading BMSR generally is not without side effects, and that
does not make the PHY odd.

Whether clearing the latching-low status bits is of any relevance to
the 3com 3c59x driver bookkeeping, that I have not clue.

>
>    Andrew

Regards,
-Vladimir

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] net: 3com: 3c59x: remove set but not used variable 'mii_reg1'
  2020-01-03 19:13     ` Vladimir Oltean
@ 2020-01-03 19:17       ` Florian Fainelli
  2020-01-03 19:37         ` Andrew Lunn
  0 siblings, 1 reply; 10+ messages in thread
From: Florian Fainelli @ 2020-01-03 19:17 UTC (permalink / raw)
  To: Vladimir Oltean, Andrew Lunn
  Cc: Matthew Wilcox, yu kuai, klassert, David S. Miller,
	Heiner Kallweit, Jakub Kicinski, hslester96, mst, yang.wei9,
	netdev, lkml, yi.zhang, zhengbin13

On 1/3/20 11:13 AM, Vladimir Oltean wrote:
> Hi Andrew,
> 
> On Fri, 3 Jan 2020 at 19:54, Andrew Lunn <andrew@lunn.ch> wrote:
>>
>> I fully agree about the general case. However, reading the MII_BMSR
>> should not have any side affects. It would be an odd Ethernet PHY if
>> it did.
> 
> This is not really correct. As far as I know the clause 22 spec
> requires the link status bit in BMSR to be latching low, so that
> momentary losses of link can be caught post-facto.
> In fact, even genphy_update_link treats this case:
> 
>     /* The link state is latched low so that momentary link
>      * drops can be detected. Do not double-read the status
>      * in polling mode to detect such short link drops.
>      */
>     if (!phy_polling_mode(phydev)) {
>         status = phy_read(phydev, MII_BMSR);
>         if (status < 0)
>             return status;
>         else if (status & BMSR_LSTATUS)
>             goto done;
>     }
> 
> So no, reading BMSR generally is not without side effects, and that
> does not make the PHY odd.
> 
> Whether clearing the latching-low status bits is of any relevance to
> the 3com 3c59x driver bookkeeping, that I have not clue.

And since more reviewers are on the same boat, the fix should probably
look to eliminate the warning by doing something like:

(void)mdio_read(dev, vp->phys[0], MII_BMSR);
-- 
Florian

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] net: 3com: 3c59x: remove set but not used variable 'mii_reg1'
  2020-01-03 19:17       ` Florian Fainelli
@ 2020-01-03 19:37         ` Andrew Lunn
       [not found]           ` <CAP8WD_a6QJNz2mUpz_eCaNReoZKVAdL0TpoF-m+gA4VPWRrrMg@mail.gmail.com>
  2020-01-06 12:48           ` yukuai (C)
  0 siblings, 2 replies; 10+ messages in thread
From: Andrew Lunn @ 2020-01-03 19:37 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Vladimir Oltean, Matthew Wilcox, yu kuai, klassert,
	David S. Miller, Heiner Kallweit, Jakub Kicinski, hslester96,
	mst, yang.wei9, netdev, lkml, yi.zhang, zhengbin13

> And since more reviewers are on the same boat, the fix should probably
> look to eliminate the warning by doing something like:
> 
> (void)mdio_read(dev, vp->phys[0], MII_BMSR);

Yes, this is the safe option.

     Andrew

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] net: 3com: 3c59x: remove set but not used variable 'mii_reg1'
       [not found]           ` <CAP8WD_a6QJNz2mUpz_eCaNReoZKVAdL0TpoF-m+gA4VPWRrrMg@mail.gmail.com>
@ 2020-01-03 20:03             ` tedheadster
  0 siblings, 0 replies; 10+ messages in thread
From: tedheadster @ 2020-01-03 20:03 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Florian Fainelli, Vladimir Oltean, Matthew Wilcox, yu kuai,
	klassert, David S. Miller, Heiner Kallweit, Jakub Kicinski,
	hslester96, Michael S. Tsirkin, yang.wei9, netdev, lkml,
	yi.zhang, zhengbin13

On Fri, Jan 3, 2020 at 2:40 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> > And since more reviewers are on the same boat, the fix should probably
> > look to eliminate the warning by doing something like:
> >
> > (void)mdio_read(dev, vp->phys[0], MII_BMSR);
>
> Yes, this is the safe option.


I have actual hardware I can test the proposed patches on, if desired.

- Matthew Whitehead

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] net: 3com: 3c59x: remove set but not used variable 'mii_reg1'
  2020-01-03 19:37         ` Andrew Lunn
       [not found]           ` <CAP8WD_a6QJNz2mUpz_eCaNReoZKVAdL0TpoF-m+gA4VPWRrrMg@mail.gmail.com>
@ 2020-01-06 12:48           ` yukuai (C)
  1 sibling, 0 replies; 10+ messages in thread
From: yukuai (C) @ 2020-01-06 12:48 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli
  Cc: Vladimir Oltean, Matthew Wilcox, klassert, David S. Miller,
	Heiner Kallweit, Jakub Kicinski, hslester96, mst, yang.wei9,
	netdev, lkml, yi.zhang, zhengbin13

On 2020/1/4 3:37, Andrew Lunn wrote:
>> And since more reviewers are on the same boat, the fix should probably
>> look to eliminate the warning by doing something like:
>>
>> (void)mdio_read(dev, vp->phys[0], MII_BMSR);
> 
> Yes, this is the safe option.
> 
>       Andrew
> 
> .
Thank you all for your response!

Yu Kuai



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-01-06 12:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-03 12:19 [PATCH] net: 3com: 3c59x: remove set but not used variable 'mii_reg1' yu kuai
2020-01-03 14:46 ` Matthew Wilcox
2020-01-03 14:59   ` Michal Kubecek
2020-01-03 17:53   ` Andrew Lunn
2020-01-03 18:17     ` Michal Kubecek
2020-01-03 19:13     ` Vladimir Oltean
2020-01-03 19:17       ` Florian Fainelli
2020-01-03 19:37         ` Andrew Lunn
     [not found]           ` <CAP8WD_a6QJNz2mUpz_eCaNReoZKVAdL0TpoF-m+gA4VPWRrrMg@mail.gmail.com>
2020-01-03 20:03             ` tedheadster
2020-01-06 12:48           ` yukuai (C)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.