* [PATCH net v4] net: usb: sr9700: fix uninitialized variable use in sr_mdio_read
@ 2024-07-25 2:29 Ma Ke
2024-07-25 3:01 ` Shigeru Yoshida
2024-07-26 10:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 4+ messages in thread
From: Ma Ke @ 2024-07-25 2:29 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, make24, liujunliang_ljl, syoshida,
andrew, horms
Cc: linux-usb, netdev, linux-kernel, stable
It could lead to error happen because the variable res is not updated if
the call to sr_share_read_word returns an error. In this particular case
error code was returned and res stayed uninitialized. Same issue also
applies to sr_read_reg.
This can be avoided by checking the return value of sr_share_read_word
and sr_read_reg, and propagating the error if the read operation failed.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: c9b37458e956 ("USB2NET : SR9700 : One chip USB 1.1 USB2NET SR9700Device Driver Support")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
Changes in v4:
- added a check for sr_read_reg() as suggestions.
Changes in v3:
- added Cc stable line as suggestions.
Changes in v2:
- modified the subject as suggestions.
---
drivers/net/usb/sr9700.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/net/usb/sr9700.c b/drivers/net/usb/sr9700.c
index 0a662e42ed96..cb7d2f798fb4 100644
--- a/drivers/net/usb/sr9700.c
+++ b/drivers/net/usb/sr9700.c
@@ -179,6 +179,7 @@ static int sr_mdio_read(struct net_device *netdev, int phy_id, int loc)
struct usbnet *dev = netdev_priv(netdev);
__le16 res;
int rc = 0;
+ int err;
if (phy_id) {
netdev_dbg(netdev, "Only internal phy supported\n");
@@ -189,11 +190,17 @@ static int sr_mdio_read(struct net_device *netdev, int phy_id, int loc)
if (loc == MII_BMSR) {
u8 value;
- sr_read_reg(dev, SR_NSR, &value);
+ err = sr_read_reg(dev, SR_NSR, &value);
+ if (err < 0)
+ return err;
+
if (value & NSR_LINKST)
rc = 1;
}
- sr_share_read_word(dev, 1, loc, &res);
+ err = sr_share_read_word(dev, 1, loc, &res);
+ if (err < 0)
+ return err;
+
if (rc == 1)
res = le16_to_cpu(res) | BMSR_LSTATUS;
else
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net v4] net: usb: sr9700: fix uninitialized variable use in sr_mdio_read
2024-07-25 2:29 [PATCH net v4] net: usb: sr9700: fix uninitialized variable use in sr_mdio_read Ma Ke
@ 2024-07-25 3:01 ` Shigeru Yoshida
2024-07-25 8:06 ` Hariprasad Kelam
2024-07-26 10:20 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 4+ messages in thread
From: Shigeru Yoshida @ 2024-07-25 3:01 UTC (permalink / raw)
To: make24
Cc: davem, edumazet, kuba, pabeni, liujunliang_ljl, andrew, horms,
linux-usb, netdev, linux-kernel, stable
On Thu, 25 Jul 2024 10:29:42 +0800, Ma Ke wrote:
> It could lead to error happen because the variable res is not updated if
> the call to sr_share_read_word returns an error. In this particular case
> error code was returned and res stayed uninitialized. Same issue also
> applies to sr_read_reg.
>
> This can be avoided by checking the return value of sr_share_read_word
> and sr_read_reg, and propagating the error if the read operation failed.
>
> Found by code review.
>
> Cc: stable@vger.kernel.org
> Fixes: c9b37458e956 ("USB2NET : SR9700 : One chip USB 1.1 USB2NET SR9700Device Driver Support")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
I did a quick check for sr9700.c and there seems to be other
suspicious usage of sr_read_reg(). But, for sr_mdio_read(), I think
the patch is sufficient.
Reviewed-by: Shigeru Yoshida <syoshida@redhat.com>
> ---
> Changes in v4:
> - added a check for sr_read_reg() as suggestions.
> Changes in v3:
> - added Cc stable line as suggestions.
> Changes in v2:
> - modified the subject as suggestions.
> ---
> drivers/net/usb/sr9700.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/usb/sr9700.c b/drivers/net/usb/sr9700.c
> index 0a662e42ed96..cb7d2f798fb4 100644
> --- a/drivers/net/usb/sr9700.c
> +++ b/drivers/net/usb/sr9700.c
> @@ -179,6 +179,7 @@ static int sr_mdio_read(struct net_device *netdev, int phy_id, int loc)
> struct usbnet *dev = netdev_priv(netdev);
> __le16 res;
> int rc = 0;
> + int err;
>
> if (phy_id) {
> netdev_dbg(netdev, "Only internal phy supported\n");
> @@ -189,11 +190,17 @@ static int sr_mdio_read(struct net_device *netdev, int phy_id, int loc)
> if (loc == MII_BMSR) {
> u8 value;
>
> - sr_read_reg(dev, SR_NSR, &value);
> + err = sr_read_reg(dev, SR_NSR, &value);
> + if (err < 0)
> + return err;
> +
> if (value & NSR_LINKST)
> rc = 1;
> }
> - sr_share_read_word(dev, 1, loc, &res);
> + err = sr_share_read_word(dev, 1, loc, &res);
> + if (err < 0)
> + return err;
> +
> if (rc == 1)
> res = le16_to_cpu(res) | BMSR_LSTATUS;
> else
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v4] net: usb: sr9700: fix uninitialized variable use in sr_mdio_read
2024-07-25 3:01 ` Shigeru Yoshida
@ 2024-07-25 8:06 ` Hariprasad Kelam
0 siblings, 0 replies; 4+ messages in thread
From: Hariprasad Kelam @ 2024-07-25 8:06 UTC (permalink / raw)
To: Shigeru Yoshida
Cc: make24, davem, edumazet, kuba, pabeni, liujunliang_ljl, andrew,
horms, linux-usb, netdev, linux-kernel, stable
On 2024-07-25 at 08:31:00, Shigeru Yoshida (syoshida@redhat.com) wrote:
> On Thu, 25 Jul 2024 10:29:42 +0800, Ma Ke wrote:
> > It could lead to error happen because the variable res is not updated if
> > the call to sr_share_read_word returns an error. In this particular case
> > error code was returned and res stayed uninitialized. Same issue also
> > applies to sr_read_reg.
> >
> > This can be avoided by checking the return value of sr_share_read_word
> > and sr_read_reg, and propagating the error if the read operation failed.
> >
> > Found by code review.
> >
> > Cc: stable@vger.kernel.org
> > Fixes: c9b37458e956 ("USB2NET : SR9700 : One chip USB 1.1 USB2NET SR9700Device Driver Support")
> > Signed-off-by: Ma Ke <make24@iscas.ac.cn>
>
> I did a quick check for sr9700.c and there seems to be other
> suspicious usage of sr_read_reg(). But, for sr_mdio_read(), I think
> the patch is sufficient.
>
> Reviewed-by: Shigeru Yoshida <syoshida@redhat.com>
>
> Agree with Shigeru, may be you can submit another patch addressing
> "suspicious usage of sr_read_reg" this patch looks good
Reviewed-by: Hariprasad Kelam <hkelam@marvell.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v4] net: usb: sr9700: fix uninitialized variable use in sr_mdio_read
2024-07-25 2:29 [PATCH net v4] net: usb: sr9700: fix uninitialized variable use in sr_mdio_read Ma Ke
2024-07-25 3:01 ` Shigeru Yoshida
@ 2024-07-26 10:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-07-26 10:20 UTC (permalink / raw)
To: Ma Ke
Cc: davem, edumazet, kuba, pabeni, liujunliang_ljl, syoshida, andrew,
horms, linux-usb, netdev, linux-kernel, stable
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:
On Thu, 25 Jul 2024 10:29:42 +0800 you wrote:
> It could lead to error happen because the variable res is not updated if
> the call to sr_share_read_word returns an error. In this particular case
> error code was returned and res stayed uninitialized. Same issue also
> applies to sr_read_reg.
>
> This can be avoided by checking the return value of sr_share_read_word
> and sr_read_reg, and propagating the error if the read operation failed.
>
> [...]
Here is the summary with links:
- [net,v4] net: usb: sr9700: fix uninitialized variable use in sr_mdio_read
https://git.kernel.org/netdev/net/c/08f3a5c38087
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-07-26 10:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-25 2:29 [PATCH net v4] net: usb: sr9700: fix uninitialized variable use in sr_mdio_read Ma Ke
2024-07-25 3:01 ` Shigeru Yoshida
2024-07-25 8:06 ` Hariprasad Kelam
2024-07-26 10:20 ` patchwork-bot+netdevbpf
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).