linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] net/usb/ax88179_178a: Adjustments for ax88179_chk_eee()
@ 2018-03-10 18:22 SF Markus Elfring
  2018-03-10 18:24 ` [PATCH 1/2] net/usb/ax88179_178a: Use common code in ax88179_chk_eee() SF Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: SF Markus Elfring @ 2018-03-10 18:22 UTC (permalink / raw)
  To: linux-usb, netdev, Andrew F. Davis, Bjørn Mork,
	David S. Miller, Philippe Reynes, Yuval Shaia
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Mar 2018 19:05:45 +0100

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Use common code
  Delete three unnecessary variables

 drivers/net/usb/ax88179_178a.c | 45 +++++++++++++++---------------------------
 1 file changed, 16 insertions(+), 29 deletions(-)

-- 
2.16.2


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

* [PATCH 1/2] net/usb/ax88179_178a: Use common code in ax88179_chk_eee()
  2018-03-10 18:22 [PATCH 0/2] net/usb/ax88179_178a: Adjustments for ax88179_chk_eee() SF Markus Elfring
@ 2018-03-10 18:24 ` SF Markus Elfring
  2018-03-10 18:41   ` Joe Perches
  2018-03-10 18:26 ` [PATCH 2/2] net/usb/ax88179_178a: Delete three unnecessary variables " SF Markus Elfring
  2018-03-10 19:17 ` [PATCH 0/2] net/usb/ax88179_178a: Adjustments for ax88179_chk_eee() Andrew Lunn
  2 siblings, 1 reply; 9+ messages in thread
From: SF Markus Elfring @ 2018-03-10 18:24 UTC (permalink / raw)
  To: linux-usb, netdev, Andrew F. Davis, Bjørn Mork,
	David S. Miller, Philippe Reynes, Yuval Shaia
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Mar 2018 18:22:43 +0100

Adjust a jump target so that a bit of common code can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/usb/ax88179_178a.c | 34 +++++++++++-----------------------
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c
index f32261ecd215..e4b0baa98e9a 100644
--- a/drivers/net/usb/ax88179_178a.c
+++ b/drivers/net/usb/ax88179_178a.c
@@ -689,49 +689,37 @@ static int ax88179_chk_eee(struct usbnet *dev)
 		eee_cap = ax88179_phy_read_mmd_indirect(dev,
 							MDIO_PCS_EEE_ABLE,
 							MDIO_MMD_PCS);
-		if (eee_cap < 0) {
-			priv->eee_active = 0;
-			return false;
-		}
+		if (eee_cap < 0)
+			goto set_inactive;
 
 		cap = mmd_eee_cap_to_ethtool_sup_t(eee_cap);
-		if (!cap) {
-			priv->eee_active = 0;
-			return false;
-		}
+		if (!cap)
+			goto set_inactive;
 
 		eee_lp = ax88179_phy_read_mmd_indirect(dev,
 						       MDIO_AN_EEE_LPABLE,
 						       MDIO_MMD_AN);
-		if (eee_lp < 0) {
-			priv->eee_active = 0;
-			return false;
-		}
+		if (eee_lp < 0)
+			goto set_inactive;
 
 		eee_adv = ax88179_phy_read_mmd_indirect(dev,
 							MDIO_AN_EEE_ADV,
 							MDIO_MMD_AN);
-
-		if (eee_adv < 0) {
-			priv->eee_active = 0;
-			return false;
-		}
+		if (eee_adv < 0)
+			goto set_inactive;
 
 		adv = mmd_eee_adv_to_ethtool_adv_t(eee_adv);
 		lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp);
 		supported = (ecmd.speed == SPEED_1000) ?
 			     SUPPORTED_1000baseT_Full :
 			     SUPPORTED_100baseT_Full;
-
-		if (!(lp & adv & supported)) {
-			priv->eee_active = 0;
-			return false;
-		}
+		if (!(lp & adv & supported))
+			goto set_inactive;
 
 		priv->eee_active = 1;
 		return true;
 	}
-
+set_inactive:
 	priv->eee_active = 0;
 	return false;
 }
-- 
2.16.2


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

* [PATCH 2/2] net/usb/ax88179_178a: Delete three unnecessary variables in ax88179_chk_eee()
  2018-03-10 18:22 [PATCH 0/2] net/usb/ax88179_178a: Adjustments for ax88179_chk_eee() SF Markus Elfring
  2018-03-10 18:24 ` [PATCH 1/2] net/usb/ax88179_178a: Use common code in ax88179_chk_eee() SF Markus Elfring
@ 2018-03-10 18:26 ` SF Markus Elfring
  2018-03-12 10:03   ` Oliver Neukum
  2018-03-10 19:17 ` [PATCH 0/2] net/usb/ax88179_178a: Adjustments for ax88179_chk_eee() Andrew Lunn
  2 siblings, 1 reply; 9+ messages in thread
From: SF Markus Elfring @ 2018-03-10 18:26 UTC (permalink / raw)
  To: linux-usb, netdev, Andrew F. Davis, Bjørn Mork,
	David S. Miller, Philippe Reynes, Yuval Shaia
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Mar 2018 18:53:28 +0100

Use three values directly for a condition check without assigning them
to intermediate variables.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/usb/ax88179_178a.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c
index e4b0baa98e9a..3e83be232504 100644
--- a/drivers/net/usb/ax88179_178a.c
+++ b/drivers/net/usb/ax88179_178a.c
@@ -684,7 +684,7 @@ static int ax88179_chk_eee(struct usbnet *dev)
 
 	if (ecmd.duplex & DUPLEX_FULL) {
 		int eee_lp, eee_cap, eee_adv;
-		u32 lp, cap, adv, supported = 0;
+		u32 cap;
 
 		eee_cap = ax88179_phy_read_mmd_indirect(dev,
 							MDIO_PCS_EEE_ABLE,
@@ -708,12 +708,11 @@ static int ax88179_chk_eee(struct usbnet *dev)
 		if (eee_adv < 0)
 			goto set_inactive;
 
-		adv = mmd_eee_adv_to_ethtool_adv_t(eee_adv);
-		lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp);
-		supported = (ecmd.speed == SPEED_1000) ?
-			     SUPPORTED_1000baseT_Full :
-			     SUPPORTED_100baseT_Full;
-		if (!(lp & adv & supported))
+		if (!(mmd_eee_adv_to_ethtool_adv_t(eee_lp) &
+		      mmd_eee_adv_to_ethtool_adv_t(eee_adv) &
+		      ((ecmd.speed == SPEED_1000)
+		       ? SUPPORTED_1000baseT_Full
+		       : SUPPORTED_100baseT_Full)))
 			goto set_inactive;
 
 		priv->eee_active = 1;
-- 
2.16.2


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

* Re: [PATCH 1/2] net/usb/ax88179_178a: Use common code in ax88179_chk_eee()
  2018-03-10 18:24 ` [PATCH 1/2] net/usb/ax88179_178a: Use common code in ax88179_chk_eee() SF Markus Elfring
@ 2018-03-10 18:41   ` Joe Perches
  2018-03-10 18:48     ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Joe Perches @ 2018-03-10 18:41 UTC (permalink / raw)
  To: SF Markus Elfring, linux-usb, netdev, Andrew F. Davis,
	Bjørn Mork, David S. Miller, Philippe Reynes, Yuval Shaia
  Cc: LKML, kernel-janitors

On Sat, 2018-03-10 at 19:24 +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 10 Mar 2018 18:22:43 +0100
> 
> Adjust a jump target so that a bit of common code can be better reused
> at the end of this function.

Please stop mindlessly sending patching Markus.

How about looking at the code being modified and
thinking about what it does?

Try unindenting the block by reversing the first test
and using the same goto set_inactive.

Look at the last & tests
+		if (!(lp & adv & supported))
and see if it should use && or be more simple to read
by using
	if (!condition || !

> ---
>  drivers/net/usb/ax88179_178a.c | 34 +++++++++++-----------------------
>  1 file changed, 11 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c
> index f32261ecd215..e4b0baa98e9a 100644
> --- a/drivers/net/usb/ax88179_178a.c
> +++ b/drivers/net/usb/ax88179_178a.c
> @@ -689,49 +689,37 @@ static int ax88179_chk_eee(struct usbnet *dev)
>  		eee_cap = ax88179_phy_read_mmd_indirect(dev,
>  							MDIO_PCS_EEE_ABLE,
>  							MDIO_MMD_PCS);
> -		if (eee_cap < 0) {
> -			priv->eee_active = 0;
> -			return false;
> -		}
> +		if (eee_cap < 0)
> +			goto set_inactive;
>  
>  		cap = mmd_eee_cap_to_ethtool_sup_t(eee_cap);
> -		if (!cap) {
> -			priv->eee_active = 0;
> -			return false;
> -		}
> +		if (!cap)
> +			goto set_inactive;
>  
>  		eee_lp = ax88179_phy_read_mmd_indirect(dev,
>  						       MDIO_AN_EEE_LPABLE,
>  						       MDIO_MMD_AN);
> -		if (eee_lp < 0) {
> -			priv->eee_active = 0;
> -			return false;
> -		}
> +		if (eee_lp < 0)
> +			goto set_inactive;
>  
>  		eee_adv = ax88179_phy_read_mmd_indirect(dev,
>  							MDIO_AN_EEE_ADV,
>  							MDIO_MMD_AN);
> -
> -		if (eee_adv < 0) {
> -			priv->eee_active = 0;
> -			return false;
> -		}
> +		if (eee_adv < 0)
> +			goto set_inactive;
>  
>  		adv = mmd_eee_adv_to_ethtool_adv_t(eee_adv);
>  		lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp);
>  		supported = (ecmd.speed == SPEED_1000) ?
>  			     SUPPORTED_1000baseT_Full :
>  			     SUPPORTED_100baseT_Full;
> -
> -		if (!(lp & adv & supported)) {
> -			priv->eee_active = 0;
> -			return false;
> -		}
> +		if (!(lp & adv & supported))
> +			goto set_inactive;
>  
>  		priv->eee_active = 1;
>  		return true;
>  	}
> -
> +set_inactive:
>  	priv->eee_active = 0;
>  	return false;
>  }

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

* Re: [PATCH 1/2] net/usb/ax88179_178a: Use common code in ax88179_chk_eee()
  2018-03-10 18:41   ` Joe Perches
@ 2018-03-10 18:48     ` Andy Shevchenko
  0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2018-03-10 18:48 UTC (permalink / raw)
  To: Joe Perches
  Cc: SF Markus Elfring, USB, netdev, Andrew F. Davis, Bjørn Mork,
	David S. Miller, Philippe Reynes, Yuval Shaia, LKML,
	kernel-janitors

On Sat, Mar 10, 2018 at 8:41 PM, Joe Perches <joe@perches.com> wrote:
> On Sat, 2018-03-10 at 19:24 +0100, SF Markus Elfring wrote:
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Sat, 10 Mar 2018 18:22:43 +0100
>>
>> Adjust a jump target so that a bit of common code can be better reused
>> at the end of this function.
>
> Please stop mindlessly sending patching Markus.
>
> How about looking at the code being modified and
> thinking about what it does?

You have a strong nerve, I gave up on him and would rather simple ban.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH 0/2] net/usb/ax88179_178a: Adjustments for ax88179_chk_eee()
  2018-03-10 18:22 [PATCH 0/2] net/usb/ax88179_178a: Adjustments for ax88179_chk_eee() SF Markus Elfring
  2018-03-10 18:24 ` [PATCH 1/2] net/usb/ax88179_178a: Use common code in ax88179_chk_eee() SF Markus Elfring
  2018-03-10 18:26 ` [PATCH 2/2] net/usb/ax88179_178a: Delete three unnecessary variables " SF Markus Elfring
@ 2018-03-10 19:17 ` Andrew Lunn
  2 siblings, 0 replies; 9+ messages in thread
From: Andrew Lunn @ 2018-03-10 19:17 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-usb, netdev, Andrew F. Davis, Bjørn Mork,
	David S. Miller, Philippe Reynes, Yuval Shaia, LKML,
	kernel-janitors

On Sat, Mar 10, 2018 at 07:22:55PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 10 Mar 2018 19:05:45 +0100
> 
> Two update suggestions were taken into account
> from static source code analysis.

Hi Markus

How about re-writing this driver to use phylib. The whole of
ax88179_chk_eee() would then go away, since it is a duplication of
phy_init_eee().

	Andrew

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

* Re: [PATCH 2/2] net/usb/ax88179_178a: Delete three unnecessary variables in ax88179_chk_eee()
  2018-03-10 18:26 ` [PATCH 2/2] net/usb/ax88179_178a: Delete three unnecessary variables " SF Markus Elfring
@ 2018-03-12 10:03   ` Oliver Neukum
  2018-03-13  7:24     ` [2/2] " SF Markus Elfring
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Neukum @ 2018-03-12 10:03 UTC (permalink / raw)
  To: SF Markus Elfring, David S. Miller, Philippe Reynes,
	Bjørn Mork, Yuval Shaia, Andrew F. Davis, linux-usb, netdev
  Cc: kernel-janitors, LKML

Am Samstag, den 10.03.2018, 19:26 +0100 schrieb SF Markus Elfring:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 10 Mar 2018 18:53:28 +0100
> 
> Use three values directly for a condition check without assigning them
> to intermediate variables.

Hi,

what is the benefit of this? It looks like needless code churn to me.

	Regards
		Oliver


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

* Re: [2/2] net/usb/ax88179_178a: Delete three unnecessary variables in ax88179_chk_eee()
  2018-03-12 10:03   ` Oliver Neukum
@ 2018-03-13  7:24     ` SF Markus Elfring
  2018-03-13 10:26       ` Oliver Neukum
  0 siblings, 1 reply; 9+ messages in thread
From: SF Markus Elfring @ 2018-03-13  7:24 UTC (permalink / raw)
  To: Oliver Neukum, linux-usb, netdev
  Cc: kernel-janitors, LKML, Andrew F. Davis, Andrew Lunn,
	Bjørn Mork, David S. Miller, Philippe Reynes, Yuval Shaia

>> Use three values directly for a condition check without assigning them
>> to intermediate variables.
> 
> Hi,
> 
> what is the benefit of this?

I proposed a small source code reduction.

Other software design directions might become more interesting for this use case.

Regards,
Markus

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

* Re: [2/2] net/usb/ax88179_178a: Delete three unnecessary variables in ax88179_chk_eee()
  2018-03-13  7:24     ` [2/2] " SF Markus Elfring
@ 2018-03-13 10:26       ` Oliver Neukum
  0 siblings, 0 replies; 9+ messages in thread
From: Oliver Neukum @ 2018-03-13 10:26 UTC (permalink / raw)
  To: SF Markus Elfring, linux-usb, netdev
  Cc: David S. Miller, Philippe Reynes, Andrew Lunn, Bjørn Mork,
	Yuval Shaia, Andrew F. Davis, kernel-janitors, LKML

Am Dienstag, den 13.03.2018, 08:24 +0100 schrieb SF Markus Elfring:
> > 
> > > 
> > > Use three values directly for a condition check without assigning them
> > > to intermediate variables.
> > 
> > Hi,
> > 
> > what is the benefit of this?
> 
> I proposed a small source code reduction.
> 
> Other software design directions might become more interesting for this use case.

Yes and doing so you killed three meaningful names that tell
us what these checks actually test for. That is not an improvement.

	Regards
		Oliver


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

end of thread, other threads:[~2018-03-13 10:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-10 18:22 [PATCH 0/2] net/usb/ax88179_178a: Adjustments for ax88179_chk_eee() SF Markus Elfring
2018-03-10 18:24 ` [PATCH 1/2] net/usb/ax88179_178a: Use common code in ax88179_chk_eee() SF Markus Elfring
2018-03-10 18:41   ` Joe Perches
2018-03-10 18:48     ` Andy Shevchenko
2018-03-10 18:26 ` [PATCH 2/2] net/usb/ax88179_178a: Delete three unnecessary variables " SF Markus Elfring
2018-03-12 10:03   ` Oliver Neukum
2018-03-13  7:24     ` [2/2] " SF Markus Elfring
2018-03-13 10:26       ` Oliver Neukum
2018-03-10 19:17 ` [PATCH 0/2] net/usb/ax88179_178a: Adjustments for ax88179_chk_eee() Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).