linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: uhid: allocate static minor
@ 2013-09-09 16:33 David Herrmann
  2013-09-09 16:51 ` Tom Gundersen
  0 siblings, 1 reply; 3+ messages in thread
From: David Herrmann @ 2013-09-09 16:33 UTC (permalink / raw)
  To: linux-input
  Cc: Tom Gundersen, Kay Sievers, Marcel Holtmann, linux-kernel,
	David Herrmann

udev has this nice feature of creating "dead" /dev/<node> device-nodes if
it finds a devnode:<node> modalias. Once the node is accessed, the kernel
automatically loads the module that provides the node. However, this
requires udev to know the major:minor code to use for the node. This
feature was introduced by:

  commit 578454ff7eab61d13a26b568f99a89a2c9edc881
  Author: Kay Sievers <kay.sievers@vrfy.org>
  Date:   Thu May 20 18:07:20 2010 +0200

      driver core: add devname module aliases to allow module on-demand auto-loading

However, uhid uses dynamic minor numbers so this doesn't actually work. We
need to load uhid to know which minor it's going to use.

Hence, allocate a static minor (just like uinput does) and we're good
to go.

Reported-by: Tom Gundersen <teg@jklm.no>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
---
 drivers/hid/uhid.c         | 3 ++-
 include/linux/miscdevice.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
index 5bf2fb7..93b00d7 100644
--- a/drivers/hid/uhid.c
+++ b/drivers/hid/uhid.c
@@ -615,7 +615,7 @@ static const struct file_operations uhid_fops = {
 
 static struct miscdevice uhid_misc = {
 	.fops		= &uhid_fops,
-	.minor		= MISC_DYNAMIC_MINOR,
+	.minor		= UHID_MINOR,
 	.name		= UHID_NAME,
 };
 
@@ -634,4 +634,5 @@ module_exit(uhid_exit);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>");
 MODULE_DESCRIPTION("User-space I/O driver support for HID subsystem");
+MODULE_ALIAS_MISCDEV(UHID_MINOR);
 MODULE_ALIAS("devname:" UHID_NAME);
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index 09c2300..cb35835 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -45,6 +45,7 @@
 #define MAPPER_CTRL_MINOR	236
 #define LOOP_CTRL_MINOR		237
 #define VHOST_NET_MINOR		238
+#define UHID_MINOR		239
 #define MISC_DYNAMIC_MINOR	255
 
 struct device;
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] HID: uhid: allocate static minor
  2013-09-09 16:33 [PATCH] HID: uhid: allocate static minor David Herrmann
@ 2013-09-09 16:51 ` Tom Gundersen
  2013-09-24 16:28   ` David Herrmann
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Gundersen @ 2013-09-09 16:51 UTC (permalink / raw)
  To: David Herrmann
  Cc: linux-input@vger.kernel.org, Kay Sievers, Marcel Holtmann, LKML

On Mon, Sep 9, 2013 at 6:33 PM, David Herrmann <dh.herrmann@gmail.com> wrote:
> udev has this nice feature of creating "dead" /dev/<node> device-nodes if
> it finds a devnode:<node> modalias. Once the node is accessed, the kernel
> automatically loads the module that provides the node. However, this
> requires udev to know the major:minor code to use for the node. This
> feature was introduced by:
>
>   commit 578454ff7eab61d13a26b568f99a89a2c9edc881
>   Author: Kay Sievers <kay.sievers@vrfy.org>
>   Date:   Thu May 20 18:07:20 2010 +0200
>
>       driver core: add devname module aliases to allow module on-demand auto-loading
>
> However, uhid uses dynamic minor numbers so this doesn't actually work. We
> need to load uhid to know which minor it's going to use.
>
> Hence, allocate a static minor (just like uinput does) and we're good
> to go.
>
> Reported-by: Tom Gundersen <teg@jklm.no>

Thanks, this works (I only tested the creation of the device node, not
the actual module loading).

> Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
> ---
>  drivers/hid/uhid.c         | 3 ++-
>  include/linux/miscdevice.h | 1 +
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
> index 5bf2fb7..93b00d7 100644
> --- a/drivers/hid/uhid.c
> +++ b/drivers/hid/uhid.c
> @@ -615,7 +615,7 @@ static const struct file_operations uhid_fops = {
>
>  static struct miscdevice uhid_misc = {
>         .fops           = &uhid_fops,
> -       .minor          = MISC_DYNAMIC_MINOR,
> +       .minor          = UHID_MINOR,
>         .name           = UHID_NAME,
>  };
>
> @@ -634,4 +634,5 @@ module_exit(uhid_exit);
>  MODULE_LICENSE("GPL");
>  MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>");
>  MODULE_DESCRIPTION("User-space I/O driver support for HID subsystem");
> +MODULE_ALIAS_MISCDEV(UHID_MINOR);
>  MODULE_ALIAS("devname:" UHID_NAME);
> diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
> index 09c2300..cb35835 100644
> --- a/include/linux/miscdevice.h
> +++ b/include/linux/miscdevice.h
> @@ -45,6 +45,7 @@
>  #define MAPPER_CTRL_MINOR      236
>  #define LOOP_CTRL_MINOR                237
>  #define VHOST_NET_MINOR                238
> +#define UHID_MINOR             239
>  #define MISC_DYNAMIC_MINOR     255
>
>  struct device;
> --
> 1.8.4
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] HID: uhid: allocate static minor
  2013-09-09 16:51 ` Tom Gundersen
@ 2013-09-24 16:28   ` David Herrmann
  0 siblings, 0 replies; 3+ messages in thread
From: David Herrmann @ 2013-09-24 16:28 UTC (permalink / raw)
  To: Tom Gundersen
  Cc: linux-input@vger.kernel.org, Kay Sievers, Marcel Holtmann, LKML,
	Jiri Kosina

Hey Jiri

I forgot to put you on CC on the initial patch. Any comments on this?

Cheers
David

On Mon, Sep 9, 2013 at 6:51 PM, Tom Gundersen <teg@jklm.no> wrote:
> On Mon, Sep 9, 2013 at 6:33 PM, David Herrmann <dh.herrmann@gmail.com> wrote:
>> udev has this nice feature of creating "dead" /dev/<node> device-nodes if
>> it finds a devnode:<node> modalias. Once the node is accessed, the kernel
>> automatically loads the module that provides the node. However, this
>> requires udev to know the major:minor code to use for the node. This
>> feature was introduced by:
>>
>>   commit 578454ff7eab61d13a26b568f99a89a2c9edc881
>>   Author: Kay Sievers <kay.sievers@vrfy.org>
>>   Date:   Thu May 20 18:07:20 2010 +0200
>>
>>       driver core: add devname module aliases to allow module on-demand auto-loading
>>
>> However, uhid uses dynamic minor numbers so this doesn't actually work. We
>> need to load uhid to know which minor it's going to use.
>>
>> Hence, allocate a static minor (just like uinput does) and we're good
>> to go.
>>
>> Reported-by: Tom Gundersen <teg@jklm.no>
>
> Thanks, this works (I only tested the creation of the device node, not
> the actual module loading).
>
>> Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
>> ---
>>  drivers/hid/uhid.c         | 3 ++-
>>  include/linux/miscdevice.h | 1 +
>>  2 files changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
>> index 5bf2fb7..93b00d7 100644
>> --- a/drivers/hid/uhid.c
>> +++ b/drivers/hid/uhid.c
>> @@ -615,7 +615,7 @@ static const struct file_operations uhid_fops = {
>>
>>  static struct miscdevice uhid_misc = {
>>         .fops           = &uhid_fops,
>> -       .minor          = MISC_DYNAMIC_MINOR,
>> +       .minor          = UHID_MINOR,
>>         .name           = UHID_NAME,
>>  };
>>
>> @@ -634,4 +634,5 @@ module_exit(uhid_exit);
>>  MODULE_LICENSE("GPL");
>>  MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>");
>>  MODULE_DESCRIPTION("User-space I/O driver support for HID subsystem");
>> +MODULE_ALIAS_MISCDEV(UHID_MINOR);
>>  MODULE_ALIAS("devname:" UHID_NAME);
>> diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
>> index 09c2300..cb35835 100644
>> --- a/include/linux/miscdevice.h
>> +++ b/include/linux/miscdevice.h
>> @@ -45,6 +45,7 @@
>>  #define MAPPER_CTRL_MINOR      236
>>  #define LOOP_CTRL_MINOR                237
>>  #define VHOST_NET_MINOR                238
>> +#define UHID_MINOR             239
>>  #define MISC_DYNAMIC_MINOR     255
>>
>>  struct device;
>> --
>> 1.8.4
>>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-09-24 16:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-09 16:33 [PATCH] HID: uhid: allocate static minor David Herrmann
2013-09-09 16:51 ` Tom Gundersen
2013-09-24 16:28   ` David Herrmann

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).