2020-08-27 06:55:40

by Himadri Pandya

[permalink] [raw]
Subject: [PATCH] net: usb: Fix uninit-was-stored issue in asix_read_phy_addr()

The buffer size is 2 Bytes and we expect to receive the same amount of
data. But sometimes we receive less data and run into uninit-was-stored
issue upon read. Hence modify the error check on the return value to match
with the buffer size as a prevention.

Reported-and-tested by: [email protected]
Signed-off-by: Himadri Pandya <[email protected]>
---
drivers/net/usb/asix_common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
index e39f41efda3e..7bc6e8f856fe 100644
--- a/drivers/net/usb/asix_common.c
+++ b/drivers/net/usb/asix_common.c
@@ -296,7 +296,7 @@ int asix_read_phy_addr(struct usbnet *dev, int internal)

netdev_dbg(dev->net, "asix_get_phy_addr()\n");

- if (ret < 0) {
+ if (ret < 2) {
netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);
goto out;
}
--
2.17.1


2020-08-27 08:00:09

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH] net: usb: Fix uninit-was-stored issue in asix_read_phy_addr()

Hello!

On 27.08.2020 9:53, Himadri Pandya wrote:

> The buffer size is 2 Bytes and we expect to receive the same amount of
> data. But sometimes we receive less data and run into uninit-was-stored
> issue upon read. Hence modify the error check on the return value to match
> with the buffer size as a prevention.
>
> Reported-and-tested by: [email protected]
> Signed-off-by: Himadri Pandya <[email protected]>
> ---
> drivers/net/usb/asix_common.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
> index e39f41efda3e..7bc6e8f856fe 100644
> --- a/drivers/net/usb/asix_common.c
> +++ b/drivers/net/usb/asix_common.c
> @@ -296,7 +296,7 @@ int asix_read_phy_addr(struct usbnet *dev, int internal)
>
> netdev_dbg(dev->net, "asix_get_phy_addr()\n");
>
> - if (ret < 0) {
> + if (ret < 2) {
> netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);

Hm... printing possibly negative values as hex?

[...]

MBR, Sergei

2020-08-27 14:45:51

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] net: usb: Fix uninit-was-stored issue in asix_read_phy_addr()

From: Himadri Pandya <[email protected]>
Date: Thu, 27 Aug 2020 12:23:55 +0530

> The buffer size is 2 Bytes and we expect to receive the same amount of
> data. But sometimes we receive less data and run into uninit-was-stored
> issue upon read. Hence modify the error check on the return value to match
> with the buffer size as a prevention.
>
> Reported-and-tested by: [email protected]
> Signed-off-by: Himadri Pandya <[email protected]>

Applied, thanks.

2020-08-27 17:55:59

by Eric Biggers

[permalink] [raw]
Subject: Re: [PATCH] net: usb: Fix uninit-was-stored issue in asix_read_phy_addr()

On Thu, Aug 27, 2020 at 12:23:55PM +0530, Himadri Pandya wrote:
> The buffer size is 2 Bytes and we expect to receive the same amount of
> data. But sometimes we receive less data and run into uninit-was-stored
> issue upon read. Hence modify the error check on the return value to match
> with the buffer size as a prevention.
>
> Reported-and-tested by: [email protected]
> Signed-off-by: Himadri Pandya <[email protected]>
> ---
> drivers/net/usb/asix_common.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
> index e39f41efda3e..7bc6e8f856fe 100644
> --- a/drivers/net/usb/asix_common.c
> +++ b/drivers/net/usb/asix_common.c
> @@ -296,7 +296,7 @@ int asix_read_phy_addr(struct usbnet *dev, int internal)
>
> netdev_dbg(dev->net, "asix_get_phy_addr()\n");
>
> - if (ret < 0) {
> + if (ret < 2) {
> netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);
> goto out;
> }

If ret is 0 or 1 here, shouldn't asix_read_phy_addr() return an error code
instead of 0 or 1?

- Eric

2020-08-28 11:17:20

by Himadri Pandya

[permalink] [raw]
Subject: Re: [PATCH] net: usb: Fix uninit-was-stored issue in asix_read_phy_addr()

On Thu, Aug 27, 2020 at 1:28 PM Sergei Shtylyov
<[email protected]> wrote:
>
> Hello!
>
> On 27.08.2020 9:53, Himadri Pandya wrote:
>
> > The buffer size is 2 Bytes and we expect to receive the same amount of
> > data. But sometimes we receive less data and run into uninit-was-stored
> > issue upon read. Hence modify the error check on the return value to match
> > with the buffer size as a prevention.
> >
> > Reported-and-tested by: [email protected]
> > Signed-off-by: Himadri Pandya <[email protected]>
> > ---
> > drivers/net/usb/asix_common.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
> > index e39f41efda3e..7bc6e8f856fe 100644
> > --- a/drivers/net/usb/asix_common.c
> > +++ b/drivers/net/usb/asix_common.c
> > @@ -296,7 +296,7 @@ int asix_read_phy_addr(struct usbnet *dev, int internal)
> >
> > netdev_dbg(dev->net, "asix_get_phy_addr()\n");
> >
> > - if (ret < 0) {
> > + if (ret < 2) {
> > netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);
>
> Hm... printing possibly negative values as hex?
>

Yeah. That's odd! Fixing it.

Thanks,
Himadri

> [...]
>
> MBR, Sergei