From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Ruan Jinjie <ruanjinjie@huawei.com>
Cc: rafal@milecki.pl, bcm-kernel-feedback-list@broadcom.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, opendmb@gmail.com,
florian.fainelli@broadcom.com, bryan.whitehead@microchip.com,
andrew@lunn.ch, hkallweit1@gmail.com, mdf@kernel.org,
pgynther@google.com, Pavithra.Sathyanarayanan@microchip.com,
netdev@vger.kernel.org
Subject: Re: [PATCH net-next v2 1/4] net: phy: fixed_phy: Fix return value check for fixed_phy_get_gpiod
Date: Thu, 17 Aug 2023 14:10:11 +0100 [thread overview]
Message-ID: <ZN4cM+EvXUtTqNwH@shell.armlinux.org.uk> (raw)
In-Reply-To: <20230817121631.1878897-2-ruanjinjie@huawei.com>
On Thu, Aug 17, 2023 at 08:16:28PM +0800, Ruan Jinjie wrote:
> Since fixed_phy_get_gpiod() return NULL instead of ERR_PTR(),
> if it fails, the IS_ERR() can never return the error. So check NULL
> and return ERR_PTR(-EINVAL) if fails.
No, this is totally and utterly wrong, and this patch introduces a new
bug. The original code is _correct_.
> Fixes: 71bd106d2567 ("net: fixed-phy: Add fixed_phy_register_with_gpiod() API")
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> ---
> drivers/net/phy/fixed_phy.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c
> index aef739c20ac4..4e7406455b6e 100644
> --- a/drivers/net/phy/fixed_phy.c
> +++ b/drivers/net/phy/fixed_phy.c
> @@ -239,8 +239,8 @@ static struct phy_device *__fixed_phy_register(unsigned int irq,
> /* Check if we have a GPIO associated with this fixed phy */
> if (!gpiod) {
> gpiod = fixed_phy_get_gpiod(np);
> - if (IS_ERR(gpiod))
> - return ERR_CAST(gpiod);
> + if (!gpiod)
> + return ERR_PTR(-EINVAL);
Let's look at fixed_phy_get_gpiod():
gpiod = fwnode_gpiod_get_index(of_fwnode_handle(fixed_link_node),
"link", 0, GPIOD_IN, "mdio");
if (IS_ERR(gpiod) && PTR_ERR(gpiod) != -EPROBE_DEFER) {
...
gpiod = NULL;
}
...
return gpiod;
If fwnode_gpiod_get_index() returns -EPROBE_DEFER, _then_ we return an
error pointer. So it _does_ return an error pointer.
It also returns NULL when there is no device node passed to it, or
if there is no fixed-link specifier, or there is some other error
from fwnode_gpiod_get_index().
Otherwise, it returns a valid pointer to a gpio descriptor.
The gpio is optional. The device node is optional. When
fixed_phy_get_gpiod() returns NULL, it is _not_ an error, it means
that we don't have a GPIO. Just because something returns NULL does
_not_ mean it's an error - please get out of that thinking, because
if you don't your patches will introduce lots of new bugs.
Only when fwnode_gpiod_get_index() wants to defer probe do we return
an error.
So, sorry but NAK to this patch, it is incorrect.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
next prev parent reply other threads:[~2023-08-17 13:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-17 12:16 [PATCH net-next v2 0/4] net: Fix return value check for fixed_phy_register() Ruan Jinjie
2023-08-17 12:16 ` [PATCH net-next v2 1/4] net: phy: fixed_phy: Fix return value check for fixed_phy_get_gpiod Ruan Jinjie
2023-08-17 12:39 ` Andrew Lunn
2023-08-17 13:10 ` Russell King (Oracle) [this message]
2023-08-17 13:32 ` Ruan Jinjie
2023-08-17 12:16 ` [PATCH net-next v2 2/4] net: bgmac: Fix return value check for fixed_phy_register() Ruan Jinjie
2023-08-17 12:41 ` Andrew Lunn
2023-08-17 13:01 ` Ruan Jinjie
2023-08-17 12:16 ` [PATCH net-next v2 3/4] net: bcmgenet: " Ruan Jinjie
2023-08-17 12:36 ` Heiner Kallweit
2023-08-17 13:14 ` Ruan Jinjie
2023-08-17 12:16 ` [PATCH net-next v2 4/4] net: lan743x: " Ruan Jinjie
2023-08-17 12:43 ` Heiner Kallweit
2023-08-17 13:20 ` Ruan Jinjie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZN4cM+EvXUtTqNwH@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=Pavithra.Sathyanarayanan@microchip.com \
--cc=andrew@lunn.ch \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bryan.whitehead@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=florian.fainelli@broadcom.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=mdf@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=opendmb@gmail.com \
--cc=pabeni@redhat.com \
--cc=pgynther@google.com \
--cc=rafal@milecki.pl \
--cc=ruanjinjie@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.