linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/6] USB: roles: make role_class a static const structure
@ 2023-06-20  9:44 Greg Kroah-Hartman
  2023-06-20  9:44 ` [PATCH 2/6] USB: gadget: udc: core: make udc_class " Greg Kroah-Hartman
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Greg Kroah-Hartman @ 2023-06-20  9:44 UTC (permalink / raw)
  To: linux-usb; +Cc: Ivan Orlov, Greg Kroah-Hartman

From: Ivan Orlov <ivan.orlov0322@gmail.com>

Now that the driver core allows for struct class to be in read-only
memory, move the role_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at load time.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/roles/class.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index 0395bd5dbd3e..ae41578bd014 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -14,7 +14,9 @@
 #include <linux/mutex.h>
 #include <linux/slab.h>
 
-static struct class *role_class;
+static const struct class role_class = {
+	.name = "usb_role",
+};
 
 struct usb_role_switch {
 	struct device dev;
@@ -95,7 +97,7 @@ static void *usb_role_switch_match(const struct fwnode_handle *fwnode, const cha
 	if (id && !fwnode_property_present(fwnode, id))
 		return NULL;
 
-	dev = class_find_device_by_fwnode(role_class, fwnode);
+	dev = class_find_device_by_fwnode(&role_class, fwnode);
 
 	return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
 }
@@ -111,7 +113,7 @@ usb_role_switch_is_parent(struct fwnode_handle *fwnode)
 		return NULL;
 	}
 
-	dev = class_find_device_by_fwnode(role_class, parent);
+	dev = class_find_device_by_fwnode(&role_class, parent);
 	fwnode_handle_put(parent);
 	return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
 }
@@ -191,7 +193,7 @@ usb_role_switch_find_by_fwnode(const struct fwnode_handle *fwnode)
 	if (!fwnode)
 		return NULL;
 
-	dev = class_find_device_by_fwnode(role_class, fwnode);
+	dev = class_find_device_by_fwnode(&role_class, fwnode);
 	if (dev)
 		WARN_ON(!try_module_get(dev->parent->driver->owner));
 
@@ -338,7 +340,7 @@ usb_role_switch_register(struct device *parent,
 
 	sw->dev.parent = parent;
 	sw->dev.fwnode = desc->fwnode;
-	sw->dev.class = role_class;
+	sw->dev.class = &role_class;
 	sw->dev.type = &usb_role_dev_type;
 	dev_set_drvdata(&sw->dev, desc->driver_data);
 	dev_set_name(&sw->dev, "%s-role-switch",
@@ -392,14 +394,13 @@ EXPORT_SYMBOL_GPL(usb_role_switch_get_drvdata);
 
 static int __init usb_roles_init(void)
 {
-	role_class = class_create("usb_role");
-	return PTR_ERR_OR_ZERO(role_class);
+	return class_register(&role_class);
 }
 subsys_initcall(usb_roles_init);
 
 static void __exit usb_roles_exit(void)
 {
-	class_destroy(role_class);
+	class_unregister(&role_class);
 }
 module_exit(usb_roles_exit);
 
-- 
2.41.0


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

* [PATCH 2/6] USB: gadget: udc: core: make udc_class a static const structure
  2023-06-20  9:44 [PATCH 1/6] USB: roles: make role_class a static const structure Greg Kroah-Hartman
@ 2023-06-20  9:44 ` Greg Kroah-Hartman
  2023-06-20  9:44 ` [PATCH 3/6] USB: mon: make mon_bin_class " Greg Kroah-Hartman
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Greg Kroah-Hartman @ 2023-06-20  9:44 UTC (permalink / raw)
  To: linux-usb; +Cc: Ivan Orlov, Greg Kroah-Hartman

From: Ivan Orlov <ivan.orlov0322@gmail.com>

Now that the driver core allows for struct class to be in read-only
memory, move the udc_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at load time.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/gadget/udc/core.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 52e6d2e84e35..b2bb6336902f 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -50,7 +50,7 @@ struct usb_udc {
 	bool				started;
 };
 
-static struct class *udc_class;
+static const struct class udc_class;
 static LIST_HEAD(udc_list);
 
 /* Protects udc_list, udc->driver, driver->is_bound, and related calls */
@@ -1312,7 +1312,7 @@ int usb_add_gadget(struct usb_gadget *gadget)
 
 	device_initialize(&udc->dev);
 	udc->dev.release = usb_udc_release;
-	udc->dev.class = udc_class;
+	udc->dev.class = &udc_class;
 	udc->dev.groups = usb_udc_attr_groups;
 	udc->dev.parent = gadget->dev.parent;
 	ret = dev_set_name(&udc->dev, "%s",
@@ -1774,6 +1774,11 @@ static int usb_udc_uevent(const struct device *dev, struct kobj_uevent_env *env)
 	return 0;
 }
 
+static const struct class udc_class = {
+	.name		= "udc",
+	.dev_uevent	= usb_udc_uevent,
+};
+
 static const struct bus_type gadget_bus_type = {
 	.name = "gadget",
 	.probe = gadget_bind_driver,
@@ -1785,18 +1790,13 @@ static int __init usb_udc_init(void)
 {
 	int rc;
 
-	udc_class = class_create("udc");
-	if (IS_ERR(udc_class)) {
-		pr_err("failed to create udc class --> %ld\n",
-				PTR_ERR(udc_class));
-		return PTR_ERR(udc_class);
-	}
-
-	udc_class->dev_uevent = usb_udc_uevent;
+	rc = class_register(&udc_class);
+	if (rc)
+		return rc;
 
 	rc = bus_register(&gadget_bus_type);
 	if (rc)
-		class_destroy(udc_class);
+		class_unregister(&udc_class);
 	return rc;
 }
 subsys_initcall(usb_udc_init);
@@ -1804,7 +1804,7 @@ subsys_initcall(usb_udc_init);
 static void __exit usb_udc_exit(void)
 {
 	bus_unregister(&gadget_bus_type);
-	class_destroy(udc_class);
+	class_unregister(&udc_class);
 }
 module_exit(usb_udc_exit);
 
-- 
2.41.0


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

* [PATCH 3/6] USB: mon: make mon_bin_class a static const structure
  2023-06-20  9:44 [PATCH 1/6] USB: roles: make role_class a static const structure Greg Kroah-Hartman
  2023-06-20  9:44 ` [PATCH 2/6] USB: gadget: udc: core: make udc_class " Greg Kroah-Hartman
@ 2023-06-20  9:44 ` Greg Kroah-Hartman
  2023-06-20  9:44 ` [PATCH 4/6] USB: gadget: f_printer: make usb_gadget_class " Greg Kroah-Hartman
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Greg Kroah-Hartman @ 2023-06-20  9:44 UTC (permalink / raw)
  To: linux-usb; +Cc: Ivan Orlov, Greg Kroah-Hartman

From: Ivan Orlov <ivan.orlov0322@gmail.com>

Now that the driver core allows for struct class to be in read-only
memory, move the mon_bin_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at load time.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/mon/mon_bin.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 952c56789258..9ca9305243fe 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -213,7 +213,10 @@ static unsigned char xfer_to_pipe[4] = {
 	PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT
 };
 
-static struct class *mon_bin_class;
+static const struct class mon_bin_class = {
+	.name = "usbmon",
+};
+
 static dev_t mon_bin_dev0;
 static struct cdev mon_bin_cdev;
 
@@ -1360,7 +1363,7 @@ int mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus)
 	if (minor >= MON_BIN_MAX_MINOR)
 		return 0;
 
-	dev = device_create(mon_bin_class, ubus ? ubus->controller : NULL,
+	dev = device_create(&mon_bin_class, ubus ? ubus->controller : NULL,
 			    MKDEV(MAJOR(mon_bin_dev0), minor), NULL,
 			    "usbmon%d", minor);
 	if (IS_ERR(dev))
@@ -1372,18 +1375,16 @@ int mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus)
 
 void mon_bin_del(struct mon_bus *mbus)
 {
-	device_destroy(mon_bin_class, mbus->classdev->devt);
+	device_destroy(&mon_bin_class, mbus->classdev->devt);
 }
 
 int __init mon_bin_init(void)
 {
 	int rc;
 
-	mon_bin_class = class_create("usbmon");
-	if (IS_ERR(mon_bin_class)) {
-		rc = PTR_ERR(mon_bin_class);
+	rc = class_register(&mon_bin_class);
+	if (rc)
 		goto err_class;
-	}
 
 	rc = alloc_chrdev_region(&mon_bin_dev0, 0, MON_BIN_MAX_MINOR, "usbmon");
 	if (rc < 0)
@@ -1401,7 +1402,7 @@ int __init mon_bin_init(void)
 err_add:
 	unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR);
 err_dev:
-	class_destroy(mon_bin_class);
+	class_unregister(&mon_bin_class);
 err_class:
 	return rc;
 }
@@ -1410,5 +1411,5 @@ void mon_bin_exit(void)
 {
 	cdev_del(&mon_bin_cdev);
 	unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR);
-	class_destroy(mon_bin_class);
+	class_unregister(&mon_bin_class);
 }
-- 
2.41.0


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

* [PATCH 4/6] USB: gadget: f_printer: make usb_gadget_class a static const structure
  2023-06-20  9:44 [PATCH 1/6] USB: roles: make role_class a static const structure Greg Kroah-Hartman
  2023-06-20  9:44 ` [PATCH 2/6] USB: gadget: udc: core: make udc_class " Greg Kroah-Hartman
  2023-06-20  9:44 ` [PATCH 3/6] USB: mon: make mon_bin_class " Greg Kroah-Hartman
@ 2023-06-20  9:44 ` Greg Kroah-Hartman
  2023-06-20  9:44 ` [PATCH 5/6] USB: gadget: f_hid: make hidg_class " Greg Kroah-Hartman
  2023-06-20  9:44 ` [PATCH 6/6] USB: file.c: make usb class " Greg Kroah-Hartman
  4 siblings, 0 replies; 11+ messages in thread
From: Greg Kroah-Hartman @ 2023-06-20  9:44 UTC (permalink / raw)
  To: linux-usb; +Cc: Ivan Orlov, Greg Kroah-Hartman

From: Ivan Orlov <ivan.orlov0322@gmail.com>

Now that the driver core allows for struct class to be in read-only
memory, move the usb_gadget_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at load time.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/gadget/function/f_printer.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c
index 28db3e336e7d..bf41a4fa7502 100644
--- a/drivers/usb/gadget/function/f_printer.c
+++ b/drivers/usb/gadget/function/f_printer.c
@@ -54,7 +54,10 @@
 #define DEFAULT_Q_LEN		10 /* same as legacy g_printer gadget */
 
 static int major, minors;
-static struct class *usb_gadget_class;
+static const struct class usb_gadget_class = {
+	.name = "usb_printer_gadget",
+};
+
 static DEFINE_IDA(printer_ida);
 static DEFINE_MUTEX(printer_ida_lock); /* protects access do printer_ida */
 
@@ -1120,7 +1123,7 @@ static int printer_func_bind(struct usb_configuration *c,
 
 	/* Setup the sysfs files for the printer gadget. */
 	devt = MKDEV(major, dev->minor);
-	pdev = device_create(usb_gadget_class, NULL, devt,
+	pdev = device_create(&usb_gadget_class, NULL, devt,
 				  NULL, "g_printer%d", dev->minor);
 	if (IS_ERR(pdev)) {
 		ERROR(dev, "Failed to create device: g_printer\n");
@@ -1143,7 +1146,7 @@ static int printer_func_bind(struct usb_configuration *c,
 	return 0;
 
 fail_cdev_add:
-	device_destroy(usb_gadget_class, devt);
+	device_destroy(&usb_gadget_class, devt);
 
 fail_rx_reqs:
 	while (!list_empty(&dev->rx_reqs)) {
@@ -1410,7 +1413,7 @@ static void printer_func_unbind(struct usb_configuration *c,
 
 	dev = func_to_printer(f);
 
-	device_destroy(usb_gadget_class, MKDEV(major, dev->minor));
+	device_destroy(&usb_gadget_class, MKDEV(major, dev->minor));
 
 	/* Remove Character Device */
 	cdev_del(&dev->printer_cdev);
@@ -1512,19 +1515,14 @@ static int gprinter_setup(int count)
 	int status;
 	dev_t devt;
 
-	usb_gadget_class = class_create("usb_printer_gadget");
-	if (IS_ERR(usb_gadget_class)) {
-		status = PTR_ERR(usb_gadget_class);
-		usb_gadget_class = NULL;
-		pr_err("unable to create usb_gadget class %d\n", status);
+	status = class_register(&usb_gadget_class);
+	if (status)
 		return status;
-	}
 
 	status = alloc_chrdev_region(&devt, 0, count, "USB printer gadget");
 	if (status) {
 		pr_err("alloc_chrdev_region %d\n", status);
-		class_destroy(usb_gadget_class);
-		usb_gadget_class = NULL;
+		class_unregister(&usb_gadget_class);
 		return status;
 	}
 
@@ -1540,6 +1538,5 @@ static void gprinter_cleanup(void)
 		unregister_chrdev_region(MKDEV(major, 0), minors);
 		major = minors = 0;
 	}
-	class_destroy(usb_gadget_class);
-	usb_gadget_class = NULL;
+	class_unregister(&usb_gadget_class);
 }
-- 
2.41.0


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

* [PATCH 5/6] USB: gadget: f_hid: make hidg_class a static const structure
  2023-06-20  9:44 [PATCH 1/6] USB: roles: make role_class a static const structure Greg Kroah-Hartman
                   ` (2 preceding siblings ...)
  2023-06-20  9:44 ` [PATCH 4/6] USB: gadget: f_printer: make usb_gadget_class " Greg Kroah-Hartman
@ 2023-06-20  9:44 ` Greg Kroah-Hartman
  2023-06-20  9:44 ` [PATCH 6/6] USB: file.c: make usb class " Greg Kroah-Hartman
  4 siblings, 0 replies; 11+ messages in thread
From: Greg Kroah-Hartman @ 2023-06-20  9:44 UTC (permalink / raw)
  To: linux-usb; +Cc: Ivan Orlov, Greg Kroah-Hartman

From: Ivan Orlov <ivan.orlov0322@gmail.com>

Now that the driver core allows for struct class to be in read-only
memory, move the hidg_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at load time.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/gadget/function/f_hid.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 9f6b10134121..ea85e2c701a1 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -23,7 +23,11 @@
 #define HIDG_MINORS	4
 
 static int major, minors;
-static struct class *hidg_class;
+
+static const struct class hidg_class = {
+	.name = "hidg",
+};
+
 static DEFINE_IDA(hidg_ida);
 static DEFINE_MUTEX(hidg_ida_lock); /* protects access to hidg_ida */
 
@@ -1272,7 +1276,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi)
 
 	device_initialize(&hidg->dev);
 	hidg->dev.release = hidg_release;
-	hidg->dev.class = hidg_class;
+	hidg->dev.class = &hidg_class;
 	hidg->dev.devt = MKDEV(major, opts->minor);
 	ret = dev_set_name(&hidg->dev, "hidg%d", opts->minor);
 	if (ret)
@@ -1325,17 +1329,13 @@ int ghid_setup(struct usb_gadget *g, int count)
 	int status;
 	dev_t dev;
 
-	hidg_class = class_create("hidg");
-	if (IS_ERR(hidg_class)) {
-		status = PTR_ERR(hidg_class);
-		hidg_class = NULL;
+	status = class_register(&hidg_class);
+	if (status)
 		return status;
-	}
 
 	status = alloc_chrdev_region(&dev, 0, count, "hidg");
 	if (status) {
-		class_destroy(hidg_class);
-		hidg_class = NULL;
+		class_unregister(&hidg_class);
 		return status;
 	}
 
@@ -1352,6 +1352,5 @@ void ghid_cleanup(void)
 		major = minors = 0;
 	}
 
-	class_destroy(hidg_class);
-	hidg_class = NULL;
+	class_unregister(&hidg_class);
 }
-- 
2.41.0


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

* [PATCH 6/6] USB: file.c: make usb class a static const structure
  2023-06-20  9:44 [PATCH 1/6] USB: roles: make role_class a static const structure Greg Kroah-Hartman
                   ` (3 preceding siblings ...)
  2023-06-20  9:44 ` [PATCH 5/6] USB: gadget: f_hid: make hidg_class " Greg Kroah-Hartman
@ 2023-06-20  9:44 ` Greg Kroah-Hartman
  2023-06-20 14:22   ` Greg Kroah-Hartman
  4 siblings, 1 reply; 11+ messages in thread
From: Greg Kroah-Hartman @ 2023-06-20  9:44 UTC (permalink / raw)
  To: linux-usb; +Cc: Ivan Orlov, Greg Kroah-Hartman

From: Ivan Orlov <ivan.orlov0322@gmail.com>

Now that the driver core allows for struct class to be in read-only
memory, remove the class field of the usb_class structure and
create the usbmisc_class static class structure declared at build time
which places it into read-only memory, instead of having it to be
dynamically allocated at load time.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/core/file.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index c4ed3310e069..0e16a9c048dd 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -59,7 +59,6 @@ static const struct file_operations usb_fops = {
 
 static struct usb_class {
 	struct kref kref;
-	struct class *class;
 } *usb_class;
 
 static char *usb_devnode(const struct device *dev, umode_t *mode)
@@ -72,6 +71,11 @@ static char *usb_devnode(const struct device *dev, umode_t *mode)
 	return drv->devnode(dev, mode);
 }
 
+static struct class usbmisc_class = {
+	.name		= "usbmisc",
+	.devnode	= usb_devnode,
+};
+
 static int init_usb_class(void)
 {
 	int result = 0;
@@ -88,15 +92,12 @@ static int init_usb_class(void)
 	}
 
 	kref_init(&usb_class->kref);
-	usb_class->class = class_create("usbmisc");
-	if (IS_ERR(usb_class->class)) {
-		result = PTR_ERR(usb_class->class);
-		printk(KERN_ERR "class_create failed for usb devices\n");
+	result = class_register(&usbmisc_class);
+	if (result) {
 		kfree(usb_class);
 		usb_class = NULL;
 		goto exit;
 	}
-	usb_class->class->devnode = usb_devnode;
 
 exit:
 	return result;
@@ -105,7 +106,7 @@ static int init_usb_class(void)
 static void release_usb_class(struct kref *kref)
 {
 	/* Ok, we cheat as we know we only have one usb_class */
-	class_destroy(usb_class->class);
+	class_unregister(&usbmisc_class);
 	kfree(usb_class);
 	usb_class = NULL;
 }
@@ -200,7 +201,7 @@ int usb_register_dev(struct usb_interface *intf,
 
 	/* create a usb class device for this usb interface */
 	snprintf(name, sizeof(name), class_driver->name, minor - minor_base);
-	intf->usb_dev = device_create(usb_class->class, &intf->dev,
+	intf->usb_dev = device_create(&usbmisc_class, &intf->dev,
 				      MKDEV(USB_MAJOR, minor), class_driver,
 				      "%s", kbasename(name));
 	if (IS_ERR(intf->usb_dev)) {
@@ -234,7 +235,7 @@ void usb_deregister_dev(struct usb_interface *intf,
 		return;
 
 	dev_dbg(&intf->dev, "removing %d minor\n", intf->minor);
-	device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor));
+	device_destroy(&usbmisc_class, MKDEV(USB_MAJOR, intf->minor));
 
 	down_write(&minor_rwsem);
 	usb_minors[intf->minor] = NULL;
-- 
2.41.0


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

* Re: [PATCH 6/6] USB: file.c: make usb class a static const structure
  2023-06-20  9:44 ` [PATCH 6/6] USB: file.c: make usb class " Greg Kroah-Hartman
@ 2023-06-20 14:22   ` Greg Kroah-Hartman
  2023-06-21 11:08     ` Ivan Orlov
  0 siblings, 1 reply; 11+ messages in thread
From: Greg Kroah-Hartman @ 2023-06-20 14:22 UTC (permalink / raw)
  To: linux-usb; +Cc: Ivan Orlov

On Tue, Jun 20, 2023 at 11:44:18AM +0200, Greg Kroah-Hartman wrote:
> From: Ivan Orlov <ivan.orlov0322@gmail.com>
> 
> Now that the driver core allows for struct class to be in read-only
> memory, remove the class field of the usb_class structure and
> create the usbmisc_class static class structure declared at build time
> which places it into read-only memory, instead of having it to be
> dynamically allocated at load time.
> 
> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  drivers/usb/core/file.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
> index c4ed3310e069..0e16a9c048dd 100644
> --- a/drivers/usb/core/file.c
> +++ b/drivers/usb/core/file.c
> @@ -59,7 +59,6 @@ static const struct file_operations usb_fops = {
>  
>  static struct usb_class {
>  	struct kref kref;
> -	struct class *class;
>  } *usb_class;

Is this structure needed anymore at all now that the thing the kref was
"protecting" is gone?  I think it can be dropped entirely, right?

thanks,

greg k-h

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

* Re: [PATCH 6/6] USB: file.c: make usb class a static const structure
  2023-06-20 14:22   ` Greg Kroah-Hartman
@ 2023-06-21 11:08     ` Ivan Orlov
  2023-06-21 12:48       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 11+ messages in thread
From: Ivan Orlov @ 2023-06-21 11:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-usb

On 20.06.2023 18:22, Greg Kroah-Hartman wrote:
> Is this structure needed anymore at all now that the thing the kref was
> "protecting" is gone?  I think it can be dropped entirely, right?
> 
> thanks,
> 
> greg k-h

As I understood after reading the code, this kref is used for checking 
how many devices uses our class and testing when we can unregister it.

As we register our class only when the first device is registered, I 
think the best solution is to move this kref structure out of the 
usb_class structure as we still need it for detecting when we could 
finally unregister our class. What do you think about it?


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

* Re: [PATCH 6/6] USB: file.c: make usb class a static const structure
  2023-06-21 11:08     ` Ivan Orlov
@ 2023-06-21 12:48       ` Greg Kroah-Hartman
  2023-06-21 13:06         ` Ivan Orlov
  0 siblings, 1 reply; 11+ messages in thread
From: Greg Kroah-Hartman @ 2023-06-21 12:48 UTC (permalink / raw)
  To: Ivan Orlov; +Cc: linux-usb

On Wed, Jun 21, 2023 at 03:08:07PM +0400, Ivan Orlov wrote:
> On 20.06.2023 18:22, Greg Kroah-Hartman wrote:
> > Is this structure needed anymore at all now that the thing the kref was
> > "protecting" is gone?  I think it can be dropped entirely, right?
> > 
> > thanks,
> > 
> > greg k-h
> 
> As I understood after reading the code, this kref is used for checking how
> many devices uses our class and testing when we can unregister it.
> 
> As we register our class only when the first device is registered, I think
> the best solution is to move this kref structure out of the usb_class
> structure as we still need it for detecting when we could finally unregister
> our class. What do you think about it?

I think we should make it simpler, allocate the class when we start up,
and free it when we shut down, which guarantees that all users of the
class are removed at that time as this is part of the usb core code.

No need to be fancy anymore with the dynamic creation/removal of the
class, it's just not worth it :)

thanks,

greg k-h

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

* Re: [PATCH 6/6] USB: file.c: make usb class a static const structure
  2023-06-21 12:48       ` Greg Kroah-Hartman
@ 2023-06-21 13:06         ` Ivan Orlov
  2023-06-21 13:29           ` Greg Kroah-Hartman
  0 siblings, 1 reply; 11+ messages in thread
From: Ivan Orlov @ 2023-06-21 13:06 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb

On 6/21/23 16:48, Greg Kroah-Hartman wrote:
> I think we should make it simpler, allocate the class when we start up,
> and free it when we shut down, which guarantees that all users of the
> class are removed at that time as this is part of the usb core code.
> 
> No need to be fancy anymore with the dynamic creation/removal of the
> class, it's just not worth it :)
> 
> thanks,
> 
> greg k-h

Alright, it sounds really reasonable, let's do it in this way :)

I'll add init_usb_class call to the 'usb_init' function and the 
corresponding releasing function call to the 'usb_exit' function in the 
'drivers/usb/core/usb.c' file. So we would register class at startup and 
unregister it when shutting down.


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

* Re: [PATCH 6/6] USB: file.c: make usb class a static const structure
  2023-06-21 13:06         ` Ivan Orlov
@ 2023-06-21 13:29           ` Greg Kroah-Hartman
  0 siblings, 0 replies; 11+ messages in thread
From: Greg Kroah-Hartman @ 2023-06-21 13:29 UTC (permalink / raw)
  To: Ivan Orlov; +Cc: linux-usb

On Wed, Jun 21, 2023 at 05:06:34PM +0400, Ivan Orlov wrote:
> On 6/21/23 16:48, Greg Kroah-Hartman wrote:
> > I think we should make it simpler, allocate the class when we start up,
> > and free it when we shut down, which guarantees that all users of the
> > class are removed at that time as this is part of the usb core code.
> > 
> > No need to be fancy anymore with the dynamic creation/removal of the
> > class, it's just not worth it :)
> > 
> > thanks,
> > 
> > greg k-h
> 
> Alright, it sounds really reasonable, let's do it in this way :)
> 
> I'll add init_usb_class call to the 'usb_init' function and the
> corresponding releasing function call to the 'usb_exit' function in the
> 'drivers/usb/core/usb.c' file. So we would register class at startup and
> unregister it when shutting down.
> 

Totally reasonable, thanks for doing this work.

greg k-h

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

end of thread, other threads:[~2023-06-21 13:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-20  9:44 [PATCH 1/6] USB: roles: make role_class a static const structure Greg Kroah-Hartman
2023-06-20  9:44 ` [PATCH 2/6] USB: gadget: udc: core: make udc_class " Greg Kroah-Hartman
2023-06-20  9:44 ` [PATCH 3/6] USB: mon: make mon_bin_class " Greg Kroah-Hartman
2023-06-20  9:44 ` [PATCH 4/6] USB: gadget: f_printer: make usb_gadget_class " Greg Kroah-Hartman
2023-06-20  9:44 ` [PATCH 5/6] USB: gadget: f_hid: make hidg_class " Greg Kroah-Hartman
2023-06-20  9:44 ` [PATCH 6/6] USB: file.c: make usb class " Greg Kroah-Hartman
2023-06-20 14:22   ` Greg Kroah-Hartman
2023-06-21 11:08     ` Ivan Orlov
2023-06-21 12:48       ` Greg Kroah-Hartman
2023-06-21 13:06         ` Ivan Orlov
2023-06-21 13:29           ` Greg Kroah-Hartman

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