Re: [PATCH 0/3] Remove usb_host class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2009-05-03 at 22:34 +0200, Kay Sievers wrote:
> What do you think about the name to choose? It's:
>   4-0:1.0-ep81
> now.
> 
> But it could be:
>   4-0:1.0-ep_81
> to match closer to the old name, or anything else, or David liked to
> add direction to the name, if I remember that correctly?

Updated patch, including the device_type. It still creates
"4-0:1.0-ep81" names, please change this to whatever you guys decide is
the best.

Thanks,
Kay


From: Kay Sievers <kay.sievers@xxxxxxxx>
Subject: usb: move endpoint devices from separate class to usb bus

USB endpoints will be part of the "usb" bus now, instead of living in their
own "usb_endpoint" class.

This also disables the device nodes request for endpoint devices, which
are not implemented today. If usbfs2 gets implemented, they can be
enabled again, along with a proper device naming scheme was defined.

Signed-off-by: Kay Sievers <kay.sievers@xxxxxxxx>
---
 drivers/usb/core/driver.c   |    2 
 drivers/usb/core/endpoint.c |  103 +++++++++++---------------------------------
 drivers/usb/core/usb.c      |    4 +
 drivers/usb/core/usb.h      |   14 +++++
 4 files changed, 47 insertions(+), 76 deletions(-)

--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -598,7 +598,7 @@ static int usb_device_match(struct devic
 		/* TODO: Add real matching code */
 		return 1;
 
-	} else {
+	} else if (is_usb_interface(dev)) {
 		struct usb_interface *intf;
 		struct usb_driver *usb_drv;
 		const struct usb_device_id *id;
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -15,9 +15,11 @@
 #include <linux/usb.h>
 #include "usb.h"
 
+#if 0
 #define MAX_ENDPOINT_MINORS (64*128*32)
 static int usb_endpoint_major;
 static DEFINE_IDR(endpoint_idr);
+#endif
 
 struct ep_device {
 	struct usb_endpoint_descriptor *desc;
@@ -28,6 +30,10 @@ struct ep_device {
 #define to_ep_device(_dev) \
 	container_of(_dev, struct ep_device, dev)
 
+struct device_type usb_ep_device_type = {
+	.name =		"usb_endpoint",
+};
+
 struct ep_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct usb_device *,
@@ -160,10 +166,11 @@ static struct attribute_group *ep_dev_gr
 	NULL
 };
 
-static int usb_endpoint_major_init(void)
+int __init usb_endpoint_major_init(void)
 {
+	int error = 0;
+#if 0
 	dev_t dev;
-	int error;
 
 	error = alloc_chrdev_region(&dev, 0, MAX_ENDPOINT_MINORS,
 				    "usb_endpoint");
@@ -173,25 +180,30 @@ static int usb_endpoint_major_init(void)
 		return error;
 	}
 	usb_endpoint_major = MAJOR(dev);
-
+#endif
 	return error;
 }
 
-static void usb_endpoint_major_cleanup(void)
+void usb_endpoint_major_cleanup(void)
 {
+#if 0
 	unregister_chrdev_region(MKDEV(usb_endpoint_major, 0),
 				 MAX_ENDPOINT_MINORS);
+#endif
 }
 
 static int endpoint_get_minor(struct ep_device *ep_dev)
 {
+	int retval = 0;
+#if 0
 	static DEFINE_MUTEX(minor_lock);
-	int retval = -ENOMEM;
 	int id;
 
 	mutex_lock(&minor_lock);
-	if (idr_pre_get(&endpoint_idr, GFP_KERNEL) == 0)
+	if (idr_pre_get(&endpoint_idr, GFP_KERNEL) == 0) {
+		err = -ENOMEM;
 		goto exit;
+	}
 
 	retval = idr_get_new(&endpoint_idr, ep_dev, &id);
 	if (retval < 0) {
@@ -202,69 +214,15 @@ static int endpoint_get_minor(struct ep_
 	ep_dev->minor = id & MAX_ID_MASK;
 exit:
 	mutex_unlock(&minor_lock);
+#endif
 	return retval;
 }
 
 static void endpoint_free_minor(struct ep_device *ep_dev)
 {
+#if 0
 	idr_remove(&endpoint_idr, ep_dev->minor);
-}
-
-static struct endpoint_class {
-	struct kref kref;
-	struct class *class;
-} *ep_class;
-
-static int init_endpoint_class(void)
-{
-	int result = 0;
-
-	if (ep_class != NULL) {
-		kref_get(&ep_class->kref);
-		goto exit;
-	}
-
-	ep_class = kmalloc(sizeof(*ep_class), GFP_KERNEL);
-	if (!ep_class) {
-		result = -ENOMEM;
-		goto exit;
-	}
-
-	kref_init(&ep_class->kref);
-	ep_class->class = class_create(THIS_MODULE, "usb_endpoint");
-	if (IS_ERR(ep_class->class)) {
-		result = PTR_ERR(ep_class->class);
-		goto class_create_error;
-	}
-
-	result = usb_endpoint_major_init();
-	if (result)
-		goto endpoint_major_error;
-
-	goto exit;
-
-endpoint_major_error:
-	class_destroy(ep_class->class);
-class_create_error:
-	kfree(ep_class);
-	ep_class = NULL;
-exit:
-	return result;
-}
-
-static void release_endpoint_class(struct kref *kref)
-{
-	/* Ok, we cheat as we know we only have one ep_class */
-	class_destroy(ep_class->class);
-	kfree(ep_class);
-	ep_class = NULL;
-	usb_endpoint_major_cleanup();
-}
-
-static void destroy_endpoint_class(void)
-{
-	if (ep_class)
-		kref_put(&ep_class->kref, release_endpoint_class);
+#endif
 }
 
 static void ep_device_release(struct device *dev)
@@ -283,14 +241,10 @@ int usb_create_ep_devs(struct device *pa
 	struct ep_device *ep_dev;
 	int retval;
 
-	retval = init_endpoint_class();
-	if (retval)
-		goto exit;
-
 	ep_dev = kzalloc(sizeof(*ep_dev), GFP_KERNEL);
 	if (!ep_dev) {
 		retval = -ENOMEM;
-		goto error_alloc;
+		goto exit;
 	}
 
 	retval = endpoint_get_minor(ep_dev);
@@ -303,12 +257,15 @@ int usb_create_ep_devs(struct device *pa
 	ep_dev->desc = &endpoint->desc;
 	ep_dev->udev = udev;
 	ep_dev->dev.groups = ep_dev_groups;
+#if 0
 	ep_dev->dev.devt = MKDEV(usb_endpoint_major, ep_dev->minor);
-	ep_dev->dev.class = ep_class->class;
+#endif
+	ep_dev->dev.bus = &usb_bus_type;
+	ep_dev->dev.type = &usb_ep_device_type;
 	ep_dev->dev.parent = parent;
 	ep_dev->dev.release = ep_device_release;
-	dev_set_name(&ep_dev->dev, "usbdev%d.%d_ep%02x",
-		 udev->bus->busnum, udev->devnum,
+	dev_set_name(&ep_dev->dev, "%s-ep%02x",
+		 dev_name(parent),
 		 endpoint->desc.bEndpointAddress);
 
 	retval = device_register(&ep_dev->dev);
@@ -325,7 +282,6 @@ int usb_create_ep_devs(struct device *pa
 
 error_link:
 	device_unregister(&ep_dev->dev);
-	destroy_endpoint_class();
 	return retval;
 
 error_chrdev:
@@ -333,8 +289,6 @@ error_chrdev:
 
 error_register:
 	kfree(ep_dev);
-error_alloc:
-	destroy_endpoint_class();
 exit:
 	return retval;
 }
@@ -350,6 +304,5 @@ void usb_remove_ep_devs(struct usb_host_
 		sysfs_remove_link(&ep_dev->dev.parent->kobj, name);
 		device_unregister(&ep_dev->dev);
 		endpoint->ep_dev = NULL;
-		destroy_endpoint_class();
 	}
 }
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -1039,10 +1039,14 @@ static int __init usb_init(void)
 	retval = usb_hub_init();
 	if (retval)
 		goto hub_init_failed;
+	retval = usb_endpoint_major_init();
+	if (retval)
+		goto enpoint_major_init_failed;
 	retval = usb_register_device_driver(&usb_generic_driver, THIS_MODULE);
 	if (!retval)
 		goto out;
 
+enpoint_major_init_failed:
 	usb_hub_cleanup();
 hub_init_failed:
 	usbfs_cleanup();
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -106,6 +106,7 @@ extern struct workqueue_struct *ksuspend
 extern struct bus_type usb_bus_type;
 extern struct device_type usb_device_type;
 extern struct device_type usb_if_device_type;
+extern struct device_type usb_ep_device_type;
 extern struct usb_device_driver usb_generic_driver;
 
 static inline int is_usb_device(const struct device *dev)
@@ -113,6 +114,16 @@ static inline int is_usb_device(const st
 	return dev->type == &usb_device_type;
 }
 
+static inline int is_usb_interface(const struct device *dev)
+{
+	return dev->type == &usb_if_device_type;
+}
+
+static inline int is_usb_endpoint(const struct device *dev)
+{
+	return dev->type == &usb_ep_device_type;
+}
+
 /* Do the same for device drivers and interface drivers. */
 
 static inline int is_usb_device_driver(struct device_driver *drv)
@@ -156,6 +167,9 @@ extern void usbfs_conn_disc_event(void);
 extern int usb_devio_init(void);
 extern void usb_devio_cleanup(void);
 
+extern int usb_endpoint_major_init(void);
+extern void usb_endpoint_major_cleanup(void);
+
 /* internal notify stuff */
 extern void usb_notify_add_device(struct usb_device *udev);
 extern void usb_notify_remove_device(struct usb_device *udev);


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux