diff mbox series

net: 3com: 3c59x: Change the conditional processing for vortex_ioctl

Message ID 20220317043344.15317-1-tangmeng@uniontech.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: 3com: 3c59x: Change the conditional processing for vortex_ioctl | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 25 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Meng Tang March 17, 2022, 4:33 a.m. UTC
In the vortex_ioctl, there are two places where there can be better
and easier to understand:
First, it should be better to reverse the check on 'VORTEX_PCI(vp)'
and returned early in order to be easier to understand.
Second, no need to make two 'if(state != 0)' judgments, we can
simplify the execution process.

Signed-off-by: Meng Tang <tangmeng@uniontech.com>
---
 drivers/net/ethernet/3com/3c59x.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

Comments

Ondrej Zary March 17, 2022, 8 a.m. UTC | #1
On Thursday 17 March 2022, Meng Tang wrote:
> In the vortex_ioctl, there are two places where there can be better
> and easier to understand:
> First, it should be better to reverse the check on 'VORTEX_PCI(vp)'
> and returned early in order to be easier to understand.
> Second, no need to make two 'if(state != 0)' judgments, we can
> simplify the execution process.

Congratulations, you've just added 3 lines of code and broke a driver.
Your "simplified" version does not work with EISA devices.

Why? Please stop "improving" drivers if you can't test them.
 
> Signed-off-by: Meng Tang <tangmeng@uniontech.com>
> ---
>  drivers/net/ethernet/3com/3c59x.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/3com/3c59x.c b/drivers/net/ethernet/3com/3c59x.c
> index ccf07667aa5e..c22de3c8cd12 100644
> --- a/drivers/net/ethernet/3com/3c59x.c
> +++ b/drivers/net/ethernet/3com/3c59x.c
> @@ -3032,16 +3032,19 @@ static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
>  	struct vortex_private *vp = netdev_priv(dev);
>  	pci_power_t state = 0;
>  
> -	if(VORTEX_PCI(vp))
> -		state = VORTEX_PCI(vp)->current_state;
> +	if (!VORTEX_PCI(vp))
> +		return -EOPNOTSUPP;
>  
> -	/* The kernel core really should have pci_get_power_state() */
> +	state = VORTEX_PCI(vp)->current_state;
>  
> -	if(state != 0)
> +	/* The kernel core really should have pci_get_power_state() */
> +	if (!state) {
> +		err = generic_mii_ioctl(&vp->mii, if_mii(rq), cmd, NULL);
> +	} else {
>  		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);
> -	err = generic_mii_ioctl(&vp->mii, if_mii(rq), cmd, NULL);
> -	if(state != 0)
> +		err = generic_mii_ioctl(&vp->mii, if_mii(rq), cmd, NULL);
>  		pci_set_power_state(VORTEX_PCI(vp), state);
> +	}
>  
>  	return err;
>  }
diff mbox series

Patch

diff --git a/drivers/net/ethernet/3com/3c59x.c b/drivers/net/ethernet/3com/3c59x.c
index ccf07667aa5e..c22de3c8cd12 100644
--- a/drivers/net/ethernet/3com/3c59x.c
+++ b/drivers/net/ethernet/3com/3c59x.c
@@ -3032,16 +3032,19 @@  static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 	struct vortex_private *vp = netdev_priv(dev);
 	pci_power_t state = 0;
 
-	if(VORTEX_PCI(vp))
-		state = VORTEX_PCI(vp)->current_state;
+	if (!VORTEX_PCI(vp))
+		return -EOPNOTSUPP;
 
-	/* The kernel core really should have pci_get_power_state() */
+	state = VORTEX_PCI(vp)->current_state;
 
-	if(state != 0)
+	/* The kernel core really should have pci_get_power_state() */
+	if (!state) {
+		err = generic_mii_ioctl(&vp->mii, if_mii(rq), cmd, NULL);
+	} else {
 		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);
-	err = generic_mii_ioctl(&vp->mii, if_mii(rq), cmd, NULL);
-	if(state != 0)
+		err = generic_mii_ioctl(&vp->mii, if_mii(rq), cmd, NULL);
 		pci_set_power_state(VORTEX_PCI(vp), state);
+	}
 
 	return err;
 }