All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] asix: fix uninit-value in asix_mdio_read()
@ 2022-01-06 10:05 Dan Carpenter
  2022-01-06 10:09 ` Pavel Skripkin
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2022-01-06 10:05 UTC (permalink / raw)
  To: paskripkin; +Cc: kernel-janitors

Hello Pavel Skripkin,

The patch 8035b1a2a37a: "asix: fix uninit-value in asix_mdio_read()"
from Dec 21, 2021, leads to the following Smatch static checker
warning:

	drivers/net/usb/asix_common.c:82 asix_check_host_enable()
	warn: 'ret' possible negative type promoted to high

drivers/net/usb/asix_common.c
    68 static int asix_check_host_enable(struct usbnet *dev, int in_pm)
    69 {
    70         int i, ret;
    71         u8 smsr;
    72 
    73         for (i = 0; i < AX_HOST_EN_RETRIES; ++i) {
    74                 ret = asix_set_sw_mii(dev, in_pm);
    75                 if (ret == -ENODEV || ret == -ETIMEDOUT)
    76                         break;
    77                 usleep_range(1000, 1100);
    78                 ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG,
    79                                     0, 0, 1, &smsr, in_pm);
    80                 if (ret == -ENODEV)
    81                         break;
--> 82                 else if (ret < sizeof(smsr))

This has to be: if (ret < 0 || ret < sizeof(smsr)) { but even better
would be to fix asix_read_cmd() to not allow partial reads.  It should
print the netdev_warn() for partial reads but right now it doesn't.

    83                         continue;
    84                 else if (smsr & AX_HOST_EN)
    85                         break;
    86         }
    87 
    88         return i >= AX_HOST_EN_RETRIES ? -ETIMEDOUT : ret;
    89 }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [bug report] asix: fix uninit-value in asix_mdio_read()
  2022-01-06 10:05 [bug report] asix: fix uninit-value in asix_mdio_read() Dan Carpenter
@ 2022-01-06 10:09 ` Pavel Skripkin
  0 siblings, 0 replies; 2+ messages in thread
From: Pavel Skripkin @ 2022-01-06 10:09 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: kernel-janitors

Hi Dan,

On 1/6/22 13:05, Dan Carpenter wrote:
> Hello Pavel Skripkin,
> 
> The patch 8035b1a2a37a: "asix: fix uninit-value in asix_mdio_read()"
> from Dec 21, 2021, leads to the following Smatch static checker
> warning:
> 
> 	drivers/net/usb/asix_common.c:82 asix_check_host_enable()
> 	warn: 'ret' possible negative type promoted to high
> 
> drivers/net/usb/asix_common.c
>      68 static int asix_check_host_enable(struct usbnet *dev, int in_pm)
>      69 {
>      70         int i, ret;
>      71         u8 smsr;
>      72
>      73         for (i = 0; i < AX_HOST_EN_RETRIES; ++i) {
>      74                 ret = asix_set_sw_mii(dev, in_pm);
>      75                 if (ret == -ENODEV || ret == -ETIMEDOUT)
>      76                         break;
>      77                 usleep_range(1000, 1100);
>      78                 ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG,
>      79                                     0, 0, 1, &smsr, in_pm);
>      80                 if (ret == -ENODEV)
>      81                         break;
> --> 82                 else if (ret < sizeof(smsr))
> 
> This has to be: if (ret < 0 || ret < sizeof(smsr)) { but even better
> would be to fix asix_read_cmd() to not allow partial reads.  It should

Thanks for reporting this. It's indeed a bug.

I sent the fix yesterday, that disallows partial reads inside 
asix_read_cmd()

Please see

https://lore.kernel.org/all/20220105131952.15693-1-paskripkin@gmail.com/


With regards,
Pavel Skripkin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-06 10:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-06 10:05 [bug report] asix: fix uninit-value in asix_mdio_read() Dan Carpenter
2022-01-06 10:09 ` Pavel Skripkin

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.