mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Cc: Greg KH <gregkh@suse.de>, Kay Sievers <kay.sievers@vrfy.org>,
	Jan Blunck <jblunck@suse.de>
Subject: [patch 03/13] Driver Core: usb: add nodename support for usb drivers.
Date: Sat, 09 May 2009 07:26:04 -0700	[thread overview]
Message-ID: <20090509143632.207105067@blue.kroah.org> (raw)
In-Reply-To: <20090509143742.GA27663@kroah.com>

[-- Attachment #1: driver-core-usb-add-nodename-support-for-usb-drivers.patch --]
[-- Type: text/plain, Size: 5791 bytes --]

From: Kay Sievers <kay.sievers@vrfy.org>

This adds support for USB drivers to report their requested nodename to
userspace.  It also updates a number of USB drivers to provide the
needed subdirectory and device name to be used for them.

Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Jan Blunck <jblunck@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/hid/usbhid/hiddev.c     |    7 ++++++-
 drivers/media/video/dabusb.c    |    6 ++++++
 drivers/usb/class/usblp.c       |    6 ++++++
 drivers/usb/core/file.c         |   13 ++++++++++++-
 drivers/usb/core/usb.c          |   11 +++++++++++
 drivers/usb/misc/iowarrior.c    |    6 ++++++
 drivers/usb/misc/legousbtower.c |    6 ++++++
 include/linux/usb.h             |    3 +++
 8 files changed, 56 insertions(+), 2 deletions(-)

--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -850,8 +850,14 @@ static const struct file_operations hidd
 #endif
 };
 
+static char *hiddev_nodename(struct device *dev)
+{
+	return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
+}
+
 static struct usb_class_driver hiddev_class = {
 	.name =		"hiddev%d",
+	.nodename =	hiddev_nodename,
 	.fops =		&hiddev_fops,
 	.minor_base =	HIDDEV_MINOR_BASE,
 };
@@ -955,7 +961,6 @@ static int hiddev_usbd_probe(struct usb_
 	return -ENODEV;
 }
 
-
 static /* const */ struct usb_driver hiddev_driver = {
 	.name =		"hiddev",
 	.probe =	hiddev_usbd_probe,
--- a/drivers/media/video/dabusb.c
+++ b/drivers/media/video/dabusb.c
@@ -747,8 +747,14 @@ static const struct file_operations dabu
 	.release =	dabusb_release,
 };
 
+static char *dabusb_nodename(struct device *dev)
+{
+	return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
+}
+
 static struct usb_class_driver dabusb_class = {
 	.name =		"dabusb%d",
+	.nodename =	dabusb_nodename,
 	.fops =		&dabusb_fops,
 	.minor_base =	DABUSB_MINOR,
 };
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -1057,8 +1057,14 @@ static const struct file_operations usbl
 	.release =	usblp_release,
 };
 
+static char *usblp_nodename(struct device *dev)
+{
+	return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
+}
+
 static struct usb_class_driver usblp_class = {
 	.name =		"lp%d",
+	.nodename =	usblp_nodename,
 	.fops =		&usblp_fops,
 	.minor_base =	USBLP_MINOR_BASE,
 };
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -67,6 +67,16 @@ static struct usb_class {
 	struct class *class;
 } *usb_class;
 
+static char *usb_nodename(struct device *dev)
+{
+	struct usb_class_driver *drv;
+
+	drv = dev_get_drvdata(dev);
+	if (!drv || !drv->nodename)
+		return NULL;
+	return drv->nodename(dev);
+}
+
 static int init_usb_class(void)
 {
 	int result = 0;
@@ -90,6 +100,7 @@ static int init_usb_class(void)
 		kfree(usb_class);
 		usb_class = NULL;
 	}
+	usb_class->class->nodename = usb_nodename;
 
 exit:
 	return result;
@@ -198,7 +209,7 @@ int usb_register_dev(struct usb_interfac
 	else
 		temp = name;
 	intf->usb_dev = device_create(usb_class->class, &intf->dev,
-				      MKDEV(USB_MAJOR, minor), NULL,
+				      MKDEV(USB_MAJOR, minor), class_driver,
 				      "%s", temp);
 	if (IS_ERR(intf->usb_dev)) {
 		down_write(&minor_rwsem);
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -305,10 +305,21 @@ static struct dev_pm_ops usb_device_pm_o
 
 #endif	/* CONFIG_PM */
 
+
+static char *usb_nodename(struct device *dev)
+{
+	struct usb_device *usb_dev;
+
+	usb_dev = to_usb_device(dev);
+	return kasprintf(GFP_KERNEL, "bus/usb/%03d/%03d",
+			 usb_dev->bus->busnum, usb_dev->devnum);
+}
+
 struct device_type usb_device_type = {
 	.name =		"usb_device",
 	.release =	usb_release_dev,
 	.uevent =	usb_dev_uevent,
+	.nodename = 	usb_nodename,
 	.pm =		&usb_device_pm_ops,
 };
 
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -726,12 +726,18 @@ static const struct file_operations iowa
 	.poll = iowarrior_poll,
 };
 
+static char *iowarrior_nodename(struct device *dev)
+{
+	return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
+}
+
 /*
  * usb class driver info in order to get a minor number from the usb core,
  * and to have the device registered with devfs and the driver core
  */
 static struct usb_class_driver iowarrior_class = {
 	.name = "iowarrior%d",
+	.nodename = iowarrior_nodename,
 	.fops = &iowarrior_fops,
 	.minor_base = IOWARRIOR_MINOR_BASE,
 };
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -266,12 +266,18 @@ static const struct file_operations towe
 	.llseek =	tower_llseek,
 };
 
+static char *legousbtower_nodename(struct device *dev)
+{
+	return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
+}
+
 /*
  * usb class driver info in order to get a minor number from the usb core,
  * and to have the device registered with the driver core
  */
 static struct usb_class_driver tower_class = {
 	.name =		"legousbtower%d",
+	.nodename = 	legousbtower_nodename,
 	.fops =		&tower_fops,
 	.minor_base =	LEGO_USB_TOWER_MINOR_BASE,
 };
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -869,6 +869,8 @@ struct usb_driver {
  * struct usb_device_driver - identifies USB device driver to usbcore
  * @name: The driver name should be unique among USB drivers,
  *	and should normally be the same as the module name.
+ * @nodename: Callback to provide a naming hint for a possible
+ *	device node to create.
  * @probe: Called to see if the driver is willing to manage a particular
  *	device.  If it is, probe returns zero and uses dev_set_drvdata()
  *	to associate driver-specific data with the device.  If unwilling
@@ -912,6 +914,7 @@ extern struct bus_type usb_bus_type;
  */
 struct usb_class_driver {
 	char *name;
+	char *(*nodename)(struct device *dev);
 	const struct file_operations *fops;
 	int minor_base;
 };



  parent reply	other threads:[~2009-05-09 14:43 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20090509142601.874865281@blue.kroah.org>
2009-05-09 14:37 ` [patch 00/13] devtmpfs patches Greg KH
2009-05-09 14:26   ` [patch 01/13] Driver Core: add nodename callbacks Greg KH
2009-05-10 12:52     ` Stephen Rothwell
2009-05-10 13:19       ` Kay Sievers
2009-05-11 20:51         ` Greg KH
2009-05-09 14:26   ` [patch 02/13] Driver Core: misc: add nodename support for misc devices Greg KH
2009-05-15 19:58     ` Pavel Machek
2009-05-18 14:34       ` Greg KH
2009-05-18 19:59         ` Pavel Machek
2009-05-18 20:28       ` Alan Cox
2009-05-09 14:26   ` Greg KH [this message]
2009-05-09 14:26   ` [patch 04/13] Driver Core: block: add nodename support for block drivers Greg KH
2009-05-09 14:26   ` [patch 05/13] Driver Core: x86: add nodename for cpuid and msr drivers Greg KH
2009-05-09 14:26   ` [patch 06/13] Driver Core: dvb: add nodename for dvb drivers Greg KH
2009-05-09 14:26   ` [patch 07/13] Driver Core: input: add nodename for input drivers Greg KH
2009-05-09 14:26   ` [patch 08/13] Driver Core: sound: add nodename for sound drivers Greg KH
2009-05-09 14:26   ` [patch 09/13] Driver Core: raw: add nodename for raw devices Greg KH
2009-05-09 14:26   ` [patch 10/13] Driver Core: drm: add nodename for drm devices Greg KH
2009-05-09 14:26   ` [patch 11/13] Driver Core: aoe: add nodename for aoe devices Greg KH
2009-05-09 14:26   ` [patch 12/13] Driver Core: bsg: add nodename for bsg driver Greg KH
2009-05-09 14:26   ` [patch 13/13] Driver Core: devtmpfs - driver core maintained /dev tmpfs Greg KH
2009-05-09 15:10   ` [patch 00/13] devtmpfs patches Fabio Comolli
2009-05-09 15:08     ` Greg KH
2009-05-09 15:22       ` Arjan van de Ven
2009-05-09 16:19         ` Greg KH
2009-05-09 19:09           ` Arjan van de Ven
2009-05-10  4:34           ` Arjan van de Ven
2009-05-10  7:48             ` Eric W. Biederman
2009-05-10 14:56               ` Eric W. Biederman
2009-05-10  5:34           ` Andrew Morton
2009-05-10 15:20             ` Greg KH
2009-05-10 15:59               ` Arjan van de Ven
2009-05-10 18:31               ` Peter Zijlstra
2009-05-10 21:19                 ` Alan Cox
2009-05-10 23:47                   ` Kay Sievers
2009-05-11  0:00                     ` Arjan van de Ven
     [not found]                       ` <ac3eb2510905101822t7fde14b3nf2c689621f69c925@mail.gmail.com>
2009-05-11  2:36                         ` Eric W. Biederman
2009-05-11 10:46                           ` Kay Sievers
2009-05-11 10:55                             ` Alan Cox
2009-05-11 11:34                               ` Kay Sievers
2009-05-11 13:05                                 ` [patch 00/13] devtmpfs Arjan van de Ven
2009-05-11 13:28                                   ` Kay Sievers
2009-05-11 13:49                                     ` Arjan van de Ven
2009-05-11 14:59                                       ` Kay Sievers
2009-05-11 13:10                                 ` [patch 00/13] devtmpfs patches Alan Cox
2009-05-11 14:14                                   ` Kay Sievers
2009-05-11 14:30                                     ` Arjan van de Ven
2009-05-11 14:42                                       ` Kay Sievers
2009-05-11 15:53                                     ` Alan Cox
2009-05-11 16:28                                       ` Kay Sievers
2009-05-11 16:41                                         ` Arjan van de Ven
2009-05-11 17:32                                           ` Kay Sievers
2009-05-11 17:55                                             ` Alan Cox
2009-05-11 18:04                                               ` Kay Sievers
2009-05-11 18:40                                                 ` Alan Cox
2009-05-11 16:56                                         ` Alan Cox
2009-05-11 18:13                             ` Eric W. Biederman
2009-05-11  3:55                         ` Arjan van de Ven
2009-05-11 11:49                         ` Fabio Comolli
2009-05-11 17:47                           ` Greg KH
2009-05-11 16:40                         ` Eric W. Biederman
2009-05-11 17:16                           ` Kay Sievers
2009-05-11 21:13                             ` Eric W. Biederman
2009-05-11  1:00                     ` Andrew Morton
2009-05-11  3:58                       ` Arjan van de Ven
2009-05-11 17:45                       ` Greg KH
2009-05-09 16:46         ` Kay Sievers
2009-05-09 17:11           ` Alan Cox
2009-05-09 18:09             ` Kay Sievers
2009-05-11 17:40   ` David P. Quigley
2009-05-11 17:56     ` Greg KH
2009-05-11 20:41       ` David P. Quigley
2009-05-11 21:05         ` Kay Sievers
2009-05-11 21:19           ` Alan Cox
2009-05-11 21:27             ` Kay Sievers
2009-05-12 12:45           ` Stephen Smalley
2009-05-12 15:10             ` Kay Sievers
2009-05-12 15:35               ` Stephen Smalley
2009-05-12 15:54                 ` Kay Sievers
2009-05-12 22:55                   ` Kay Sievers
2009-05-12 23:22                     ` David P. Quigley
2009-05-12 23:34                       ` Kay Sievers
2009-05-12 23:50                         ` Greg KH
2009-05-13 12:22                     ` Stephen Smalley
2009-05-13 12:58                       ` Kay Sievers
2009-05-13 12:57                         ` Stephen Smalley
2009-05-13 13:09                           ` Kay Sievers
2009-05-13 12:59                       ` Alan Cox
2009-05-13 13:20                   ` David Howells
2009-05-13 13:34                     ` Kay Sievers
2009-05-13 14:20                       ` Kay Sievers
2009-05-13 14:35                         ` Stephen Smalley
2009-05-13 16:45                           ` Kay Sievers
2009-05-13 22:43                             ` Eric W. Biederman
2009-05-13 23:10                               ` Greg KH

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=20090509143632.207105067@blue.kroah.org \
    --to=greg@kroah.com \
    --cc=gregkh@suse.de \
    --cc=jblunck@suse.de \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®