[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aK6wlcLBN1HclMpl@stanley.mountain>
Date: Wed, 27 Aug 2025 10:15:33 +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 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;
}
}
return ~ret;
Which might also not be correct, but it's probably closer to being okay.
regards,
dan carpenter
Powered by blists - more mailing lists