From: Antonio Ospite <ao2@ao2.it>
To: Goffredo Baroncelli <kreijack@libero.it>
Cc: linux-input@vger.kernel.org,
Benjamin Tissoires <benjamin.tissoires@gmail.com>,
Nestor Lopez Casado <nlopezcasad@logitech.com>,
Dario Righelli <drighelli@gmail.com>,
Goffredo Baroncelli <kreijack@inwind.it>
Subject: Re: [PATCH] Add driver for mouse logitech M560
Date: Wed, 6 May 2015 09:35:58 +0200 [thread overview]
Message-ID: <20150506093558.c479b8499fb63c5f9b05cc31@ao2.it> (raw)
In-Reply-To: <20150506084814.3937e2e816eab76bd0012a55@ao2.it>
On Wed, 6 May 2015 08:48:14 +0200
Antonio Ospite <ao2@ao2.it> wrote:
> On Tue, 5 May 2015 17:36:59 +0200
> Antonio Ospite <ao2@ao2.it> wrote:
>
> > On Fri, 1 May 2015 10:43:33 +0200
> > Goffredo Baroncelli <kreijack@libero.it> wrote:
> >
> [...]
> > > + /* exit if the data is not a mouse related report */
> > > + if (data[0] != 0x02 && data[2] != M560_SUB_ID)
> >
> > What are the possible values of data[0] that you observed?
> > Can it only be 0x02 and 0x11?
> >
> > If we wanted to be stricter we could anticipate the full validation and
> > then simplify the ifs below to just check the report type, something
> > like:
> >
> > bool valid_mouse_report;
> > ...
> >
> > valid_mouse_report = (data[0] == 0x02 ||
> > (data[0] == REPORT_ID_HIDPP_LONG &&
> > data[2] == M560_SUB_ID &&
> > data[6] == 0x00))
> >
> > if (!valid_mouse_report)
> > return 0;
> >
> > if (data[0] == REPORT_ID_HIDPP_LONG) {
> > ...
> > } else /* if (data[0] == 0x02) */ {
> > ...
> > }
> >
> > but maybe this is overkill.
> >
>
> Or maybe just using an else, without the preventive validation, would
> already improve readability, checking things only once:
>
> if (data[0] == REPORT_ID_HIDPP_LONG &&
> data[2] == M560_SUB_ID && data[6] == 0x00) {
> ...
> } else if (data[0] == 0x02) {
> ...
> } else {
> /* unsupported report */
> return 0;
> }
>
If the function returns 0 at the end, then the else here is even
redundant.
We may return 1 at the end of the function to differentiate between "no
action performed (0)" and "no further processing (1)" like stated in
include/linux/hid.h line 661, even if I don't see the core handling the
difference between the two return values when calling the raw_event
callback.
Benjamin, can you comment about what the convention is here? I am
referring also to the checks at the begin of m560_raw_event().
Thanks,
Antonio
--
Antonio Ospite
http://ao2.it
A: Because it messes up the order in which people normally read text.
See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?
next prev parent reply other threads:[~2015-05-06 7:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-01 8:43 [PATCH] Add driver for mouse logitech M560 Goffredo Baroncelli
2015-05-01 8:56 ` [PATCH V4] Add support for mouse logitech m560 Goffredo Baroncelli
2015-05-05 15:36 ` [PATCH] Add driver for mouse logitech M560 Antonio Ospite
2015-05-06 6:48 ` Antonio Ospite
2015-05-06 7:35 ` Antonio Ospite [this message]
2015-05-06 13:27 ` Benjamin Tissoires
-- strict thread matches above, loose matches on Subject: below --
2015-05-10 16:49 [PATCH V5] Add support for mouse logitech m560 Goffredo Baroncelli
2015-05-10 16:49 ` [PATCH] Add driver for mouse logitech M560 Goffredo Baroncelli
2015-05-11 15:28 ` Benjamin Tissoires
[not found] ` <555D839F.5030304@libero.it>
2015-05-21 13:58 ` Benjamin Tissoires
2015-05-29 14:38 ` Jiri Kosina
2015-05-29 14:41 ` Benjamin Tissoires
2015-05-29 14:44 ` Jiri Kosina
2015-05-29 16:52 ` Goffredo Baroncelli
2015-04-29 18:24 [PATCH V3] Add support for mouse logitech m560 Goffredo Baroncelli
2015-04-29 18:24 ` [PATCH] Add driver for mouse logitech M560 Goffredo Baroncelli
2015-04-29 19:31 ` Benjamin Tissoires
2015-04-29 21:47 ` Antonio Ospite
2015-04-29 18:17 Goffredo Baroncelli
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=20150506093558.c479b8499fb63c5f9b05cc31@ao2.it \
--to=ao2@ao2.it \
--cc=benjamin.tissoires@gmail.com \
--cc=drighelli@gmail.com \
--cc=kreijack@inwind.it \
--cc=kreijack@libero.it \
--cc=linux-input@vger.kernel.org \
--cc=nlopezcasad@logitech.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).