All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: Dave Penkler <dpenkler@gmail.com>
Cc: linux-staging@lists.linux.dev
Subject: [bug report] staging: gpib: Add National Instruments USB GPIB driver
Date: Sat, 25 Apr 2026 12:22:20 +0300	[thread overview]
Message-ID: <aeyHzI1Xe_AIjTSG@stanley.mountain> (raw)

Hello Dave Penkler,

Commit 4e127de14fa7 ("staging: gpib: Add National Instruments USB
GPIB driver") from Sep 18, 2024 (linux-next), leads to the following
Smatch static checker warning:

drivers/gpib/ni_usb/ni_usb_gpib.c:783 ni_usb_write() warn: set error code if 'usb_bytes_written != i'
drivers/gpib/ni_usb/ni_usb_gpib.c:882 ni_usb_command_chunk() warn: set error code if 'bytes_written != i'
drivers/gpib/ni_usb/ni_usb_gpib.c:981 ni_usb_take_control() warn: set error code if 'bytes_written != i'
drivers/gpib/ni_usb/ni_usb_gpib.c:1040 ni_usb_go_to_standby() warn: set error code if 'bytes_written != i'
drivers/gpib/ni_usb/ni_usb_gpib.c:1056 ni_usb_go_to_standby() warn: set error code if 'bytes_read != 12'
drivers/gpib/ni_usb/ni_usb_gpib.c:1384 ni_usb_parallel_poll() warn: set error code if 'bytes_written != i'
drivers/gpib/ni_usb/ni_usb_gpib.c:1555 ni_usb_line_status() warn: set error code if 'bytes_written != i'

drivers/gpib/ni_usb/ni_usb_gpib.c
    772         i += ni_usb_bulk_termination(&out_data[i]);
    773 
    774         mutex_lock(&ni_priv->addressed_transfer_lock);
    775 
    776         retval = ni_usb_send_bulk_msg(ni_priv, out_data, i, &usb_bytes_written,
    777                                       ni_usb_timeout_msecs(board->usec_timeout));
    778         kfree(out_data);
    779         if (retval || usb_bytes_written != i)        {
                              ^^^^^^^^^^^^^^^^^^^^^^

We should set an error code if the usb_bytes_written are not what we
expect.  But actually since most callers get this wrong it would be
better not return usb_bytes_written but instead just check that we
get what we expect in ni_usb_send_bulk_msg() and return a negative error
cdoe when it fails.

    780                 mutex_unlock(&ni_priv->addressed_transfer_lock);
    781                 dev_err(&usb_dev->dev, "send_bulk_msg returned %i, usb_bytes_written=%i, i=%i\n",
    782                         retval, usb_bytes_written, i);
--> 783                 return retval;
    784         }
    785 
    786         in_data = kmalloc(in_data_length, GFP_KERNEL);
    787         if (!in_data) {
    788                 mutex_unlock(&ni_priv->addressed_transfer_lock);
    789                 return -ENOMEM;
    790         }
    791         retval = ni_usb_receive_bulk_msg(ni_priv, in_data, in_data_length, &usb_bytes_read,
    792                                          ni_usb_timeout_msecs(board->usec_timeout), 1);
    793 
    794         mutex_unlock(&ni_priv->addressed_transfer_lock);
    795 
    796         if ((retval && retval != -ERESTARTSYS) || usb_bytes_read != 12) {
                                                          ^^^^^^^^^^^^^^^^^^^^
Same.  Except if retval is -ERESTARTSYS then probably usb_bytes_read is
not going to be 12 so that might be another issue as well.

    797                 dev_err(&usb_dev->dev, "receive_bulk_msg returned %i, usb_bytes_read=%i\n",
    798                         retval, usb_bytes_read);
    799                 kfree(in_data);
    800                 return retval;
    801         }
    802         ni_usb_parse_status_block(in_data, &status);
    803         kfree(in_data);
    804         switch        (status.error_code) {
    805         case NIUSB_NO_ERROR:
    806                 retval = 0;
    807                 break;
    808         case NIUSB_ABORTED_ERROR:
    809                 /*
    810                  * this is expected if ni_usb_receive_bulk_msg got

This email is a free service from the Smatch-CI project [smatch.sf.net].

regards,
dan carpenter

                 reply	other threads:[~2026-04-25  9:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=aeyHzI1Xe_AIjTSG@stanley.mountain \
    --to=error27@gmail.com \
    --cc=dpenkler@gmail.com \
    --cc=linux-staging@lists.linux.dev \
    /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.