[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aK68qXqStIwBrejF@stanley.mountain>
Date: Wed, 27 Aug 2025 11:07:05 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Osama Abdelkader <osama.abdelkader@...il.com>
Cc: gregkh@...uxfoundation.org, dpenkler@...il.com,
matchstick@...erthere.org, arnd@...db.de,
linux-kernel@...r.kernel.org, linux-staging@...ts.linux.dev
Subject: Re: [PATCH] staging: gpib: simplify and fix get_data_lines
On Wed, Aug 27, 2025 at 10:15:33AM +0300, Dan Carpenter wrote:
> On Wed, Aug 27, 2025 at 12:05:02AM +0200, Osama Abdelkader wrote:
> > The function `get_data_lines()` in gpib_bitbang.c currently reads 8
> > GPIO descriptors individually and combines them into a byte.
> > This has two issues:
> >
> > * `gpiod_get_value()` returns an `int` which may be negative on
> > error. Assigning it directly into a `u8` may propagate unexpected
> > values. Masking ensures only the LSB is used.
>
> Using the last bit in an error code is not really "error handling"...
>
> What you could do instead would be something like:
>
> int ret;
>
> for (i = 0; i < 8; i++) {
> ret |= (gpiod_get_value(lines[i]) & 1) << i;
> if (ret < 0) {
> pr_err("something failed\n");
> return -EINVAL;
I meant to write "return 0;". It's type u8.
Also that doesn't work. The masks and shift mess it up.
u8 val = 0;
int ret;
for (i = 0; i < 8; i++) {
ret = gpiod_get_value(lines[i]);
if (ret < 0) {
pr_err("something failed\n");
continue;
}
val |= ret << i;
}
return ~val;
regards,
dan carpenter
Powered by blists - more mailing lists