netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] net: mdio: Use helper function IS_ERR_OR_NULL()
       [not found] <20230907071705.3907-1-liubo03@inspur.com>
@ 2023-09-07  8:38 ` Russell King (Oracle)
  0 siblings, 0 replies; only message in thread
From: Russell King (Oracle) @ 2023-09-07  8:38 UTC (permalink / raw)
  To: Bo Liu
  Cc: iyappan, keyur, quan, andrew, hkallweit1, davem, edumazet, kuba,
	pabeni, netdev, linux-kernel

On Thu, Sep 07, 2023 at 03:17:05AM -0400, Bo Liu wrote:
> Use IS_ERR_OR_NULL() to detect an error pointer or a null pointer
> open-coding to simplify the code.
> 
> Signed-off-by: Bo Liu <liubo03@inspur.com>

Please do a more thorough review of the code before proposing changes
to discover what the correct solution should be.

> diff --git a/drivers/net/mdio/mdio-xgene.c b/drivers/net/mdio/mdio-xgene.c
> index 1190a793555a..1518abfc3e22 100644
> --- a/drivers/net/mdio/mdio-xgene.c
> +++ b/drivers/net/mdio/mdio-xgene.c
> @@ -263,7 +263,7 @@ struct phy_device *xgene_enet_phy_register(struct mii_bus *bus, int phy_addr)
>  	struct phy_device *phy_dev;
>  
>  	phy_dev = get_phy_device(bus, phy_addr, false);
> -	if (!phy_dev || IS_ERR(phy_dev))
> +	if (IS_ERR_OR_NULL(phy_dev))

Looking at get_phy_device(), the returns from this function are either:

        if (r)
                return ERR_PTR(r);

which can't return NULL, or the return value from phy_device_create().

Looking at phy_device_create(), the returns from this function are:

        if (!dev)
                return ERR_PTR(-ENOMEM);

        if (ret) {
...
                dev = ERR_PTR(ret);
...
        return dev;

so I don't see any of this being able to return NULL either. Therefore,
the code that you are modifying should be:


-	if (!phy_dev || IS_ERR(phy_dev))
+	if (IS_ERR(phy_dev))

and the commit description needs to be updated to state that
get_phy_device() does not return NULL.

Thanks.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-07 16:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20230907071705.3907-1-liubo03@inspur.com>
2023-09-07  8:38 ` [PATCH] net: mdio: Use helper function IS_ERR_OR_NULL() Russell King (Oracle)

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).