Re: [PATCH 1/2] HID: ntrig don't dereference unclaimed hidinput

From: Jiri Kosina
Date: Sat Feb 26 2011 - 05:58:53 EST


On Fri, 25 Feb 2011, Rafi Rubin wrote:

> Moved the claimed input check before dereferencing field->hidinput to
> fix a reported invalid deference bug.
>
> Switched to a goto instead of an extra indent for most of the function.
>
> Signed-off-by: Rafi Rubin <rafi@xxxxxxxxxxxxxx>
> ---
> Peter Hutterer reported seeing ntrig_event called when field->hidinput
> is NULL.
>
> Seems like a reasonable opportunity to adjust the whitespace a bit.

Hi Rafi,

thanks for the fix. Even though it's obvious in this case what the actual
fix is, I'd prefer to have it separate from the other cleanup changes ...

> ---
> drivers/hid/hid-ntrig.c | 466 ++++++++++++++++++++++++-----------------------
> 1 files changed, 236 insertions(+), 230 deletions(-)
>
> diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
> index beb4034..616f091 100644
> --- a/drivers/hid/hid-ntrig.c
> +++ b/drivers/hid/hid-ntrig.c
> @@ -539,277 +539,283 @@ static int ntrig_input_mapped(struct hid_device *hdev, struct hid_input *hi,
> static int ntrig_event (struct hid_device *hid, struct hid_field *field,
> struct hid_usage *usage, __s32 value)
> {
> - struct input_dev *input = field->hidinput->input;
> struct ntrig_data *nd = hid_get_drvdata(hid);
> + struct input_dev *input;
> +
> + /* Skip processing if not a claimed input */
> + if (!(hid->claimed & HID_CLAIMED_INPUT))
> + goto not_claimed_input;

Makes me wonder why ntrig would be the only driver needing this ...
perhaps pushing it up the stack would make more sense?

--
Jiri Kosina
SUSE Labs, Novell Inc.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/