From: Dan Carpenter <dan.carpenter@linaro.org>
To: Osama Abdelkader <osama.abdelkader@gmail.com>
Cc: gregkh@linuxfoundation.org, dpenkler@gmail.com,
matchstick@neverthere.org, arnd@arndb.de,
linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev
Subject: Re: [PATCH] staging: gpib: simplify and fix get_data_lines
Date: Wed, 27 Aug 2025 10:15:33 +0300 [thread overview]
Message-ID: <aK6wlcLBN1HclMpl@stanley.mountain> (raw)
In-Reply-To: <20250826220502.210485-1-osama.abdelkader@gmail.com>
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
next prev parent reply other threads:[~2025-08-27 7:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-26 22:05 [PATCH] staging: gpib: simplify and fix get_data_lines Osama Abdelkader
2025-08-27 7:15 ` Dan Carpenter [this message]
2025-08-27 8:07 ` Dan Carpenter
2025-08-27 9:28 ` Osama Abdelkader
2025-08-27 10:09 ` 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=aK6wlcLBN1HclMpl@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=arnd@arndb.de \
--cc=dpenkler@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=matchstick@neverthere.org \
--cc=osama.abdelkader@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox