From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: Michael Banken <michael.banken@mathe.stud.uni-erlangen.de>
Cc: linux-kernel@vger.kernel.org, rydberg@euromail.se,
srinivas.pandruvada@intel.com, erazor_de@users.sourceforge.net,
jkosina@suse.cz, lorenz@badgers.com,
linux-kernel@i4.informatik.uni-erlangen.de,
linux-input@vger.kernel.org
Subject: Re: [PATCH] Added a check for NULL pointer in hid_add_device
Date: Wed, 26 Jun 2013 16:03:53 +0200 [thread overview]
Message-ID: <51CAF4C9.20407@redhat.com> (raw)
In-Reply-To: <1372182701-12256-1-git-send-email-michael.banken@mathe.stud.uni-erlangen.de>
Hi Michael,
On 06/25/2013 07:51 PM, Michael Banken wrote:
> This check greatly simplifies creating a dummy hid device.
Could you elaborate a little here? If you want to create a hid device
from the user space, I encourage you to use uhid, which is available
since v3.6.
> With this check in place a hid dummy can be created simply by allocating and adding the device.
> This used to be possible in earlier Kernel versions.
>
> Signed-off-by: Michael Banken <michael.banken@mathe.stud.uni-erlangen.de>
> Signed-off-by: Lorenz Haspel <lorenz@badgers.com>
> ---
> drivers/hid/hid-core.c | 37 ++++++++++++++++++++-----------------
> 1 file changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index 0951a9a..88c573e 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -2289,24 +2289,27 @@ int hid_add_device(struct hid_device *hdev)
> if (hid_ignore(hdev))
> return -ENODEV;
>
> - /*
> - * Read the device report descriptor once and use as template
> - * for the driver-specific modifications.
> - */
> - ret = hdev->ll_driver->parse(hdev);
> - if (ret)
> - return ret;
> - if (!hdev->dev_rdesc)
> - return -ENODEV;
> -
> - /*
> - * Scan generic devices for group information
> - */
> - if (hid_ignore_special_drivers ||
> - !hid_match_id(hdev, hid_have_special_driver)) {
> - ret = hid_scan_report(hdev);
> + if (hdev->ll_driver != NULL) {
I am concerned by the fact that *every* hid specific driver will have to
call hid_hw_start and hid_hw_stop at some point. These 2 functions are
not protected against a null pointer in hdev->ll_driver, so allowing
here a null pointer will introduce a kernel oops later.
I think it would be safer to have:
if (!hdev->ll_driver)
return -ENODEV;
But if I understood correctly, this is not your point.
So definitively, I need your usage scenarios of such hid "dummy" device.
Cheers,
Benjamin
> + /*
> + * Read the device report descriptor once and use as template
> + * for the driver-specific modifications.
> + */
> + ret = hdev->ll_driver->parse(hdev);
> if (ret)
> - hid_warn(hdev, "bad device descriptor (%d)\n", ret);
> + return ret;
> + if (!hdev->dev_rdesc)
> + return -ENODEV;
> +
> + /*
> + * Scan generic devices for group information
> + */
> + if (hid_ignore_special_drivers ||
> + !hid_match_id(hdev, hid_have_special_driver)) {
> + ret = hid_scan_report(hdev);
> + if (ret)
> + hid_warn(hdev,
> + "bad device descriptor (%d)\n", ret);
> + }
> }
>
> /* XXX hack, any other cleaner solution after the driver core
>
next prev parent reply other threads:[~2013-06-26 14:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-25 17:51 [PATCH] Added a check for NULL pointer in hid_add_device Michael Banken
2013-06-26 14:03 ` Benjamin Tissoires [this message]
2013-06-26 15:45 ` michael.banken
2013-06-28 10:52 ` David Herrmann
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=51CAF4C9.20407@redhat.com \
--to=benjamin.tissoires@redhat.com \
--cc=erazor_de@users.sourceforge.net \
--cc=jkosina@suse.cz \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@i4.informatik.uni-erlangen.de \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenz@badgers.com \
--cc=michael.banken@mathe.stud.uni-erlangen.de \
--cc=rydberg@euromail.se \
--cc=srinivas.pandruvada@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.