mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Rodrigo Gobbi <rodrigo.gobbi.7@gmail.com>
Cc: gregkh@linuxfoundation.org, dpenkler@gmail.com,
	~lkcamp/patches@lists.sr.ht, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] staging: gpib: change return type of t1_delay function to report errors
Date: Wed, 12 Feb 2025 10:05:20 +0300	[thread overview]
Message-ID: <90c2bfc7-9a76-483c-8cb6-4dfd358d586f@stanley.mountain> (raw)
In-Reply-To: <20250212024247.176572-2-rodrigo.gobbi.7@gmail.com>

On Tue, Feb 11, 2025 at 11:35:36PM -0300, Rodrigo Gobbi wrote:
> Propagate t1 delay configuration error to userspace
> 

Better to spell out the problem a bit more.  What is the effect in terms
of what the user experiences and explain why what you are doing is safe.

  The current code returns "unsigned int" and it doesn't handle errors
  correctly.

  The ni_usb_t1_delay() is the only function which returned an error (-1).
  The caller, t1_delay_ioctl() doesn't check for errors and sets
  board->t1_nano_sec to -1 and returns success.  The board->t1_nano_sec
  value is used in ni_usb_setup_t1_delay() and a value of -1 is treated as
  being above 1100ns.  It may or may not have a noticeable effect, but
  it's obviously not right.

  Typical delays are in the 200-2000 range, but definitely not more
  than INT_MAX so we can fix this code by changing the return type to int
  and adding a check for errors.  While we're at it, lets change the error
  code in ni_usb_t1_delay() from -1 and instead propagate the error from
  ni_usb_write_registers().

You should add a Fixes tag.


> diff --git a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
> index d0656dc520f5..cb8840f2a461 100644
> --- a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
> +++ b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
> @@ -1591,7 +1591,7 @@ static int ni_usb_setup_t1_delay(struct ni_usb_register *reg, unsigned int nano_
>  	return i;
>  }
>  
> -static unsigned int ni_usb_t1_delay(gpib_board_t *board, unsigned int nano_sec)
> +static int ni_usb_t1_delay(gpib_board_t *board, unsigned int nano_sec)
>  {
>  	int retval;
>  	struct ni_usb_priv *ni_priv = board->private_data;
> @@ -1605,7 +1605,7 @@ static unsigned int ni_usb_t1_delay(gpib_board_t *board, unsigned int nano_sec)
>  	retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
>  	if (retval < 0) {
>  		dev_err(&usb_dev->dev, "%s: register write failed, retval=%i\n", __func__, retval);
> -		return -1;	//FIXME should change return type to int for error reporting
> +		return -EIO;

Better to "return retval;"

>  	}
>  	board->t1_nano_sec = actual_ns;
>  	ni_usb_soft_update_status(board, ibsta, 0);

regards,
dan carpenter

  reply	other threads:[~2025-02-12  7:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12  2:35 [PATCH 0/2] " Rodrigo Gobbi
2025-02-12  2:35 ` [PATCH 1/2] " Rodrigo Gobbi
2025-02-12  7:05   ` Dan Carpenter [this message]
2025-02-12  2:35 ` [PATCH 2/2] staging: gpib: fix style at nec7210_t1_delay definition Rodrigo Gobbi
2025-02-12  7:07   ` Dan Carpenter

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=90c2bfc7-9a76-483c-8cb6-4dfd358d586f@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=dpenkler@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=rodrigo.gobbi.7@gmail.com \
    --cc=~lkcamp/patches@lists.sr.ht \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®