All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-usb@vger.kernel.org
Cc: Ivan Orlov <ivan.orlov0322@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 6/6] USB: file.c: make usb class a static const structure
Date: Tue, 20 Jun 2023 11:44:18 +0200	[thread overview]
Message-ID: <20230620094412.508580-12-gregkh@linuxfoundation.org> (raw)
In-Reply-To: <20230620094412.508580-7-gregkh@linuxfoundation.org>

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


  parent reply	other threads:[~2023-06-20  9:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Greg Kroah-Hartman [this message]
2023-06-20 14:22   ` [PATCH 6/6] USB: file.c: make usb class " 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

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=20230620094412.508580-12-gregkh@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ivan.orlov0322@gmail.com \
    --cc=linux-usb@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 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.