On Tue, 5 May 2015 17:36:59 +0200 Antonio Ospite <ao2@xxxxxx> wrote: > On Fri, 1 May 2015 10:43:33 +0200 > Goffredo Baroncelli <kreijack@xxxxxxxxx> 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; } But again, this is just a suggestion. Ciao, 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? -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html