From: Michael Zaidman <michael.zaidman@gmail.com>
To: Tom Rix <trix@redhat.com>
Cc: jikos@kernel.org, benjamin.tissoires@redhat.com,
linux-i2c@vger.kernel.org, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org, michael.zaidman@gmail.com
Subject: Re: [PATCH v4] HID: ft260: improve error handling of ft260_hid_feature_report_get()
Date: Tue, 11 May 2021 17:34:27 +0300 [thread overview]
Message-ID: <20210511143427.GA1572@michael-VirtualBox> (raw)
In-Reply-To: <30c2857d-5094-402e-25a8-48f5be83fa3f@redhat.com>
On Tue, May 11, 2021 at 06:10:36AM -0700, Tom Rix wrote:
> Generally change is fine.
>
> a nit below.
>
> On 5/11/21 3:12 AM, Michael Zaidman wrote:
> > Fixes: 6a82582d9fa4 ("HID: ft260: add usb hid to i2c host bridge driver")
> >
> > The ft260_hid_feature_report_get() checks if the return size matches
> > the requested size. But the function can also fail with at least -ENOMEM.
> > Add the < 0 checks.
> >
> > In ft260_hid_feature_report_get(), do not do the memcpy to the caller's
> > buffer if there is an error.
> >
> > ---
> > v4 Fixed commit message
> > ---
> > v3 Simplify and optimize the changes
> > ---
> > v2: add unlikely()'s for error conditions
> > ---
> >
> > Signed-off-by: Tom Rix <trix@redhat.com>
> > Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
> > ---
> > drivers/hid/hid-ft260.c | 24 ++++++++++++------------
> > 1 file changed, 12 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c
> > index 047aa85a7c83..7f4cb823129e 100644
> > --- a/drivers/hid/hid-ft260.c
> > +++ b/drivers/hid/hid-ft260.c
> > @@ -249,7 +249,10 @@ static int ft260_hid_feature_report_get(struct hid_device *hdev,
> > ret = hid_hw_raw_request(hdev, report_id, buf, len, HID_FEATURE_REPORT,
> > HID_REQ_GET_REPORT);
> > - memcpy(data, buf, len);
> > + if (likely(ret == len))
> > + memcpy(data, buf, len);
> > + else if (ret >= 0)
> > + ret = -EIO;
> > kfree(buf);
> > return ret;
> > }
> > @@ -298,7 +301,7 @@ static int ft260_xfer_status(struct ft260_device *dev)
> > ret = ft260_hid_feature_report_get(hdev, FT260_I2C_STATUS,
> > (u8 *)&report, sizeof(report));
> > - if (ret < 0) {
> > + if (unlikely(ret < 0)) {
> > hid_err(hdev, "failed to retrieve status: %d\n", ret);
> > return ret;
> > }
> > @@ -720,10 +723,9 @@ static int ft260_get_system_config(struct hid_device *hdev,
> > ret = ft260_hid_feature_report_get(hdev, FT260_SYSTEM_SETTINGS,
> > (u8 *)cfg, len);
> > - if (ret != len) {
> > + if (ret < 0) {
>
> nit: should be consistent and use unlikely(ret < 0) for this and other
> similar checks.
>
> Tom
I preserved the likely/unlikely hints in the critical path where the
performance matters. And for the sake of consistency, I removed them from
the rest of the places that are called rarely and are not performance-critical
to be aligned to the other "if" statements in the code.
Michael
next prev parent reply other threads:[~2021-05-11 14:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-11 10:12 [PATCH v4] HID: ft260: improve error handling of ft260_hid_feature_report_get() Michael Zaidman
2021-05-11 13:10 ` Tom Rix
2021-05-11 14:34 ` Michael Zaidman [this message]
2021-05-11 15:03 ` Tom Rix
2021-05-13 11:09 ` Jiri Kosina
2021-05-13 13:15 ` Tom Rix
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=20210511143427.GA1572@michael-VirtualBox \
--to=michael.zaidman@gmail.com \
--cc=benjamin.tissoires@redhat.com \
--cc=jikos@kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=trix@redhat.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;
as well as URLs for NNTP newsgroup(s).