From patchwork Tue Jun 20 09:44:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 694717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78AE2EB64DB for ; Tue, 20 Jun 2023 09:44:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232411AbjFTJok (ORCPT ); Tue, 20 Jun 2023 05:44:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232401AbjFTJod (ORCPT ); Tue, 20 Jun 2023 05:44:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FB79F1 for ; Tue, 20 Jun 2023 02:44:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 120CD60E9D for ; Tue, 20 Jun 2023 09:44:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08CEBC433C8; Tue, 20 Jun 2023 09:44:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687254271; bh=ORDrTxe/QL9CwXo0rl8o78wjPYr164OQasmrja0hGqw=; h=From:To:Cc:Subject:Date:From; b=t/fyj2k7xcGqILxfuuLQ00s4HbSpkZHU8XU78K6WSu7vipQdBmcpo+BoeUAAVjY18 DCJuGVJzI1VBQDW8cEUWV90i/8Gr0WnEzTs5prEWLw+bhbFl9VK2Dcm4iwuq6vYtpd rNWzoGMi1gfxRoWAANIoA0qGgviu7gipbpYPFqyM= From: Greg Kroah-Hartman To: linux-usb@vger.kernel.org Cc: Ivan Orlov , Greg Kroah-Hartman Subject: [PATCH 1/6] USB: roles: make role_class a static const structure Date: Tue, 20 Jun 2023 11:44:13 +0200 Message-ID: <20230620094412.508580-7-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2688; i=gregkh@linuxfoundation.org; h=from:subject; bh=w+0XbWy3w89qDNuFAd+9cVMaRXZ3bM6VgTJ4hWkOG4Q=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTS94+8C7fNs0rYq+7YP+VjcZCTxU/X/Hen2h3b+uVm L3C2vKsHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRbTIMc/gfbZvzs/PYHRbf gEX8Hk3FXpf9BBjmyp67arNp7ya9Ng+Poo3njuzbn33kLwA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Ivan Orlov 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 Signed-off-by: Ivan Orlov Signed-off-by: Greg Kroah-Hartman --- 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 #include -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); From patchwork Tue Jun 20 09:44:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 694888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63181EB64D7 for ; Tue, 20 Jun 2023 09:44:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232395AbjFTJoj (ORCPT ); Tue, 20 Jun 2023 05:44:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232400AbjFTJod (ORCPT ); Tue, 20 Jun 2023 05:44:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0674C128 for ; Tue, 20 Jun 2023 02:44:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8ED62610AB for ; Tue, 20 Jun 2023 09:44:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89B2BC433C0; Tue, 20 Jun 2023 09:44:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687254268; bh=WrHiGQ4G0nlo3itO0qX44y0ndggKzbSUkqbQicIe6KE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z/KOcg2Ygyj5M5a+oWSWA0IvCX4THmYp72qvuRIwzW1p+qi8C7pfZfa5P+ZjbUlLs I0Kv2Lf0P7TCYLnP0m0xxmEU9ToX8t4Qnk3H8AVyTFp83rJI9mRN1fmVoj0HUwKOmB eDFqy0349s0QvGfENaDO3Nf9wF9xAXgV40BTwWss= From: Greg Kroah-Hartman To: linux-usb@vger.kernel.org Cc: Ivan Orlov , Greg Kroah-Hartman Subject: [PATCH 2/6] USB: gadget: udc: core: make udc_class a static const structure Date: Tue, 20 Jun 2023 11:44:14 +0200 Message-ID: <20230620094412.508580-8-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620094412.508580-7-gregkh@linuxfoundation.org> References: <20230620094412.508580-7-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2414; i=gregkh@linuxfoundation.org; h=from:subject; bh=hlwpUa20fqzH5fJa2phVL0sHorL3wR0Q/5byiVVdq+U=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTS94/SD+e1ag058Fd/SLZNQeaFdUjO+Y9vOGzdm9zZ O3ylf3zOmJZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAiBeYM88ykDs7SWsz6zaVS 2O2+t+BTVZ9LaxgW3DDg2tHEGMzrbb/DOiCqP587OpkFAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Ivan Orlov 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 Signed-off-by: Ivan Orlov Signed-off-by: Greg Kroah-Hartman --- 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); From patchwork Tue Jun 20 09:44:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 694887 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE2BAEB64D8 for ; Tue, 20 Jun 2023 09:44:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232402AbjFTJol (ORCPT ); Tue, 20 Jun 2023 05:44:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231149AbjFTJoh (ORCPT ); Tue, 20 Jun 2023 05:44:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1ECD130 for ; Tue, 20 Jun 2023 02:44:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 416AF610AB for ; Tue, 20 Jun 2023 09:44:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A1D0C433C0; Tue, 20 Jun 2023 09:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687254275; bh=jRoxHpEH6o3hriylQl2EejlWbKyFU4k4XcAWEeQP31c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XS98Sg7wZbPaFyd5rOQO2wITqjOgGEfhAuQPlg2y3jA3OGzU2yai1ILsxZLVHLiDd VFHkNsJKDqW3zq0TwWRZpfRXF5evjsma9P1s+M+XT+qQOyyb90QAq3Bbxp3nQ0MFI0 rrJaUwiXoG4F1Xl02YgxVii8hb1shlP3qIYvo4VU= From: Greg Kroah-Hartman To: linux-usb@vger.kernel.org Cc: Ivan Orlov , Greg Kroah-Hartman Subject: [PATCH 3/6] USB: mon: make mon_bin_class a static const structure Date: Tue, 20 Jun 2023 11:44:15 +0200 Message-ID: <20230620094412.508580-9-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620094412.508580-7-gregkh@linuxfoundation.org> References: <20230620094412.508580-7-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2451; i=gregkh@linuxfoundation.org; h=from:subject; bh=Sg3k3k+cW+qn7rgFBlXisILddDj1GQWBllomMvxjyJI=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTS97reupWi4mVbWk5zqfeevyMTvMqSa3HpVdPTHzY/ qBnmkJJRywLgyATg6yYIsuXbTxH91ccUvQytD0NM4eVCWQIAxenAEzk1FyG+W4Jn1kuMz6Pzdv5 M3v5cpvKDpNn6QwLLhz6eJ7P3FcvRGff6uYWa6dI05wvAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Ivan Orlov 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 Signed-off-by: Ivan Orlov Signed-off-by: Greg Kroah-Hartman --- 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); } From patchwork Tue Jun 20 09:44:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 694716 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DACDEB64D7 for ; Tue, 20 Jun 2023 09:45:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230422AbjFTJpN (ORCPT ); Tue, 20 Jun 2023 05:45:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232418AbjFTJol (ORCPT ); Tue, 20 Jun 2023 05:44:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73BC51AC for ; Tue, 20 Jun 2023 02:44:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EB9C361199 for ; Tue, 20 Jun 2023 09:44:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03444C433C9; Tue, 20 Jun 2023 09:44:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687254279; bh=wGFyBsJ+k/1d5IwCojYRRNN0WrHJLopY5t08nnBhxpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AOIX1FhfYCqYMYCtXs/JAcR9oB3yKEIXQ6q5RTX0sF8zSVw2oyNNFtsGKnI3SUya4 9PgB7f+NN8VoZn0AKkjSG3gL1NAWnwnrYQq+q5aSwGtmfh8bru6gmtzaF9jnxDkDVT 3atM4YXH12m2+LwTwa28vPovVDvxnOrCiuKWbUYA= From: Greg Kroah-Hartman To: linux-usb@vger.kernel.org Cc: Ivan Orlov , Greg Kroah-Hartman Subject: [PATCH 4/6] USB: gadget: f_printer: make usb_gadget_class a static const structure Date: Tue, 20 Jun 2023 11:44:16 +0200 Message-ID: <20230620094412.508580-10-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620094412.508580-7-gregkh@linuxfoundation.org> References: <20230620094412.508580-7-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3070; i=gregkh@linuxfoundation.org; h=from:subject; bh=BCduruOLEGMu4mO3rQQDhiPJWai3nuz61jR3tcpLUAI=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTSz4EvZ3w5rHARnETgVQhmdqwPerhB3fut75b3/Llc sbFPzZpHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjARq9kMCxaeNLDh/sz2uPr4 vfNzi94ss9i14QDDggk/d5y77H/qpFbbW/0lATuunLkeXggA X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Ivan Orlov 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 Signed-off-by: Ivan Orlov Signed-off-by: Greg Kroah-Hartman --- 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); } From patchwork Tue Jun 20 09:44:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 694886 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D7FCEB64D8 for ; Tue, 20 Jun 2023 09:45:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232033AbjFTJpO (ORCPT ); Tue, 20 Jun 2023 05:45:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232442AbjFTJoq (ORCPT ); Tue, 20 Jun 2023 05:44:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FDD51B4 for ; Tue, 20 Jun 2023 02:44:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9BE656108B for ; Tue, 20 Jun 2023 09:44:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D360C433C0; Tue, 20 Jun 2023 09:44:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687254283; bh=bSDPLXuq92Cy/rayrdnqwJo1rXplrk1L9zzyVN0Ym2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qT1HCqjZch/xq4tDAX2FjR8kXe6rkKMNX/Zh4VhbljZ7/k+n5snSQyRJcgtORrj+Q +cCTYG2OgYSkX9JeyrlPwHwXK1oF46B2CD5zH3GJIJcWMZXU8mz76uLMWeTePxDYq6 MCgYH2nLY+97NXQS2S3ZCkF4a5rj/b6oITNFWOxA= From: Greg Kroah-Hartman To: linux-usb@vger.kernel.org Cc: Ivan Orlov , Greg Kroah-Hartman Subject: [PATCH 5/6] USB: gadget: f_hid: make hidg_class a static const structure Date: Tue, 20 Jun 2023 11:44:17 +0200 Message-ID: <20230620094412.508580-11-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620094412.508580-7-gregkh@linuxfoundation.org> References: <20230620094412.508580-7-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2082; i=gregkh@linuxfoundation.org; h=from:subject; bh=5tKJZq9tYYar6vmT8FNxCJtg0X+isdG6KEzWo/U4Abo=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTSz4UXdU4u8no5amtGQoGrZMORTKapP1lb5x7odLad +IO0UN9HbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRPc8Y5tm16ZXmvw98duiF h/Ch3o2WoXnaTgzzk1ZHMr6aZ5ad9y+zTOolr9fjmvJqAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Ivan Orlov 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 Signed-off-by: Ivan Orlov Signed-off-by: Greg Kroah-Hartman --- 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); } From patchwork Tue Jun 20 09:44:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 694715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CD65EB64DC for ; Tue, 20 Jun 2023 09:45:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232401AbjFTJpP (ORCPT ); Tue, 20 Jun 2023 05:45:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232476AbjFTJov (ORCPT ); Tue, 20 Jun 2023 05:44:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2EAE185 for ; Tue, 20 Jun 2023 02:44:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 51DF66108B for ; Tue, 20 Jun 2023 09:44:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E8ECC43395; Tue, 20 Jun 2023 09:44:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687254286; bh=MIaYJpfW8Nm0eXsiV4+DhH7dVBgMDQmKZrQZ1KcdzP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wkcZLekGnjDGVJkrxopxl+uDs9FMHWrP8BR+6iEfBasXTXD6SeTi1C85YZYg5/Mc2 a9RfPOpr/+lB3bnlAjqbD6ID7lx+ocij/fLIlULG9LROIpvFwhkWljj3uIIUmsqfU5 Ol14jXrsP2jyzMDvHeqRt8HsSOkXAFTNau5mbWa4= From: Greg Kroah-Hartman To: linux-usb@vger.kernel.org Cc: Ivan Orlov , Greg Kroah-Hartman Subject: [PATCH 6/6] USB: file.c: make usb class a static const structure Date: Tue, 20 Jun 2023 11:44:18 +0200 Message-ID: <20230620094412.508580-12-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620094412.508580-7-gregkh@linuxfoundation.org> References: <20230620094412.508580-7-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2852; i=gregkh@linuxfoundation.org; h=from:subject; bh=HYOn9kY0qERDPI3rrYa0VYrvwbfMFtmWMRiKx7UCy0s=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTSz6U+dtYv9rasfZ4e/vKO9sCmyZOnPVRRHnWZzkRz V2BPHKqHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjARkU6G+eWGdywbX+xWevrW OfxOssgnczaWowzzgwq7Psodyz69bLbCXYXP94PMM6USAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Ivan Orlov 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 Signed-off-by: Ivan Orlov Signed-off-by: Greg Kroah-Hartman --- 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;