From: Leon Romanovsky <leon@kernel.org>
To: Ruan Jinjie <ruanjinjie@huawei.com>
Cc: netdev@vger.kernel.org, "Rafał Miłecki" <rafal@milecki.pl>,
"Broadcom internal kernel review list"
<bcm-kernel-feedback-list@broadcom.com>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Doug Berger" <opendmb@gmail.com>,
"Florian Fainelli" <florian.fainelli@broadcom.com>
Subject: Re: [PATCH -next] net: broadcom: Use helper function IS_ERR_OR_NULL()
Date: Fri, 18 Aug 2023 21:41:16 +0300 [thread overview]
Message-ID: <20230818184116.GB22185@unreal> (raw)
In-Reply-To: <dd7e3f9a-1348-1d13-3b0b-5165070dd342@huawei.com>
On Thu, Aug 17, 2023 at 05:01:51PM +0800, Ruan Jinjie wrote:
>
>
> On 2023/8/17 15:19, Leon Romanovsky wrote:
> > On Wed, Aug 16, 2023 at 05:53:56PM +0800, Ruan Jinjie wrote:
> >> Use IS_ERR_OR_NULL() instead of open-coding it
> >> to simplify the code.
> >>
> >> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> >> ---
> >> drivers/net/ethernet/broadcom/bgmac.c | 2 +-
> >> drivers/net/ethernet/broadcom/genet/bcmmii.c | 2 +-
> >> 2 files changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
> >> index 10c7c232cc4e..4cd7c6abb548 100644
> >> --- a/drivers/net/ethernet/broadcom/bgmac.c
> >> +++ b/drivers/net/ethernet/broadcom/bgmac.c
> >> @@ -1448,7 +1448,7 @@ int bgmac_phy_connect_direct(struct bgmac *bgmac)
> >> int err;
> >>
> >> phy_dev = fixed_phy_register(PHY_POLL, &fphy_status, NULL);
> >
> > When can fixed_phy_register() return NULL?
> > It looks like it returns or valid phy_dev or ERR_PTR().
>
> It seems the following code has a problem:
>
> 226 static struct phy_device *__fixed_phy_register(unsigned int irq,
> 227 struct fixed_phy_status *status,
> 228 struct device_node *np,
> 229 struct gpio_desc *gpiod)
> 230 {
> 231 struct fixed_mdio_bus *fmb = &platform_fmb;
> 232 struct phy_device *phy;
> 233 int phy_addr;
> 234 int ret;
> 235
> 236 if (!fmb->mii_bus || fmb->mii_bus->state != MDIOBUS_REGISTERED)
> 237 return ERR_PTR(-EPROBE_DEFER);
> 238
> 239 /* Check if we have a GPIO associated with this fixed phy */
> 240 if (!gpiod) {
> 241 gpiod = fixed_phy_get_gpiod(np);
> 242 if (IS_ERR(gpiod))
> 243 return ERR_CAST(gpiod);
> 244 }
>
> fixed_phy_get_gpiod() return valid gpio_desc or NULL.If
> fixed_phy_get_gpiod(np) failed, the error can not be returned with
> IS_ERR(gpiod) is true, so the 243 line code is a dead code.
Not really, gpiod can be ERR_PTR(-EPROBE_DEFER) too.
Thanks
>
> >
> > Thanks
> >
> >
> >> - if (!phy_dev || IS_ERR(phy_dev)) {
> >> + if (IS_ERR_OR_NULL(phy_dev)) {
> >> dev_err(bgmac->dev, "Failed to register fixed PHY device\n");
> >> return -ENODEV;
> >> }
> >> diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c
> >> index 0092e46c46f8..aa9a436fb3ce 100644
> >> --- a/drivers/net/ethernet/broadcom/genet/bcmmii.c
> >> +++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c
> >> @@ -617,7 +617,7 @@ static int bcmgenet_mii_pd_init(struct bcmgenet_priv *priv)
> >> };
> >>
> >> phydev = fixed_phy_register(PHY_POLL, &fphy_status, NULL);
> >> - if (!phydev || IS_ERR(phydev)) {
> >> + if (IS_ERR_OR_NULL(phydev)) {
> >> dev_err(kdev, "failed to register fixed PHY device\n");
> >> return -ENODEV;
> >> }
> >> --
> >> 2.34.1
> >>
> >>
>
prev parent reply other threads:[~2023-08-18 18:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-16 9:53 [PATCH -next] net: broadcom: Use helper function IS_ERR_OR_NULL() Ruan Jinjie
2023-08-17 7:19 ` Leon Romanovsky
2023-08-17 7:25 ` Ruan Jinjie
2023-08-17 9:01 ` Ruan Jinjie
2023-08-18 18:41 ` Leon Romanovsky [this message]
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=20230818184116.GB22185@unreal \
--to=leon@kernel.org \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=florian.fainelli@broadcom.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=opendmb@gmail.com \
--cc=pabeni@redhat.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 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).