Netdev List
 help / color / mirror / Atom feed
From: Antoine Tenart <atenart@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
	Andrew Lunn <andrew@lunn.ch>, Eric Dumazet <edumazet@google.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Russell King <linux@armlinux.org.uk>,
	Wan Jiabing <wanjiabing@vivo.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH v2 net] net: phy: mscc: Add error check when __phy_read() failed
Date: Tue, 10 May 2022 16:48:33 +0200	[thread overview]
Message-ID: <165219411356.3924.11722336879963021691@kwain> (raw)
In-Reply-To: <20220510142247.16071-1-wanjiabing@vivo.com>

Hello,

Quoting Wan Jiabing (2022-05-10 16:22:45)
> Calling __phy_read() might return a negative error code. Use 'int'
> to declare variables which call __phy_read() and also add error check
> for them.
> 
> The numerous callers of vsc8584_macsec_phy_read() don't expect it to
> fail. So don't return the error code from __phy_read(), but also don't
> return random values if it does fail.
> 
> Fixes: fa164e40c53b ("net: phy: mscc: split the driver into separate files")

Does this fix an actual issue or was this found by code inspection? If
that is not fixing a real issue I don't think it should go to stable
trees.

Also this is not the right commit, the __phy_read call was introduced
before splitting the file.

>  static u32 vsc8584_macsec_phy_read(struct phy_device *phydev,
>                                    enum macsec_bank bank, u32 reg)
>  {
> -       u32 val, val_l = 0, val_h = 0;
> +       int rc, val, val_l, val_h;
>         unsigned long deadline;
> -       int rc;
> +       u32 ret = 0;
>  
>         rc = phy_select_page(phydev, MSCC_PHY_PAGE_MACSEC);
>         if (rc < 0)
> @@ -47,15 +47,20 @@ static u32 vsc8584_macsec_phy_read(struct phy_device *phydev,
>         deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
>         do {
>                 val = __phy_read(phydev, MSCC_EXT_PAGE_MACSEC_19);
> +               if (val < 0)
> +                       goto failed;
>         } while (time_before(jiffies, deadline) && !(val & MSCC_PHY_MACSEC_19_CMD));
>  
>         val_l = __phy_read(phydev, MSCC_EXT_PAGE_MACSEC_17);
>         val_h = __phy_read(phydev, MSCC_EXT_PAGE_MACSEC_18);
>  
> +       if (val_l > 0 && val_h > 0)
> +               ret = (val_h << 16) | val_l;

Both values have to be non-0 for the function to return a value? I
haven't checked but I would assume it is valid to have one of the two
being 0.

>  failed:
>         phy_restore_page(phydev, rc, rc);
>  
> -       return (val_h << 16) | val_l;
> +       return ret;
>  }

Thanks,
Antoine

  reply	other threads:[~2022-05-10 15:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-10 14:22 [PATCH v2 net] net: phy: mscc: Add error check when __phy_read() failed Wan Jiabing
2022-05-10 14:48 ` Antoine Tenart [this message]
2022-05-10 15:08   ` Andrew Lunn
2022-05-10 15:33     ` Antoine Tenart
2022-05-11  3:23       ` Jiabing Wan
2022-05-11 10:45 ` Russell King (Oracle)

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=165219411356.3924.11722336879963021691@kwain \
    --to=atenart@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=wanjiabing@vivo.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