All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: paskripkin@gmail.com
Cc: kernel-janitors@vger.kernel.org
Subject: [bug report] asix: fix uninit-value in asix_mdio_read()
Date: Thu, 6 Jan 2022 13:05:31 +0300	[thread overview]
Message-ID: <20220106100531.GA25074@kili> (raw)

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

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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-06 10:05 Dan Carpenter [this message]
2022-01-06 10:09 ` [bug report] asix: fix uninit-value in asix_mdio_read() Pavel Skripkin

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=20220106100531.GA25074@kili \
    --to=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=paskripkin@gmail.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 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.