usb: core: constify the struct device_type usage
authorRicardo B. Marliere <ricardo@marliere.net>
Sun, 18 Feb 2024 19:18:12 +0000 (16:18 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Feb 2024 08:35:46 +0000 (09:35 +0100)
Since commit aed65af1cc2f ("drivers: make device_type const"), the driver
core can properly handle constant struct device_type. Move the
usb_device_type, usb_if_device_type, usb_ep_device_type and
usb_port_device_type variables to be constant structures as well, placing
it into read-only memory which can not be modified at runtime.

Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
Link: https://lore.kernel.org/r/20240218-device_cleanup-usb-v1-4-77423c4da262@marliere.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/endpoint.c
drivers/usb/core/message.c
drivers/usb/core/port.c
drivers/usb/core/usb.c
drivers/usb/core/usb.h

index a2530811cf7ded0656556d35abcc43b302409ce8..4b38b87a13438d382d3bd0d1ace2df069fbb0d00 100644 (file)
@@ -141,7 +141,7 @@ static void ep_device_release(struct device *dev)
        kfree(ep_dev);
 }
 
-struct device_type usb_ep_device_type = {
+const struct device_type usb_ep_device_type = {
        .name =         "usb_endpoint",
        .release = ep_device_release,
 };
index 077dfe48d01c1cb2ab807197450daae79d56c59a..67316d271596d6df8a1ec04d79f1c12473989c85 100644 (file)
@@ -1849,7 +1849,7 @@ static int usb_if_uevent(const struct device *dev, struct kobj_uevent_env *env)
        return 0;
 }
 
-struct device_type usb_if_device_type = {
+const struct device_type usb_if_device_type = {
        .name =         "usb_interface",
        .release =      usb_release_interface,
        .uevent =       usb_if_uevent,
index c628c1abc90711cb9b8e652a0d903a6359c968bc..84d36172b040280781386cb029917a1be7d6a7c1 100644 (file)
@@ -429,7 +429,7 @@ static const struct dev_pm_ops usb_port_pm_ops = {
 #endif
 };
 
-struct device_type usb_port_device_type = {
+const struct device_type usb_port_device_type = {
        .name =         "usb_port",
        .release =      usb_port_device_release,
        .pm =           &usb_port_pm_ops,
index dc8d9228a5e759775cc16b0a1bbacf514235b396..a0c432b14b20ba3fd8f1a9b1716988f0c578259c 100644 (file)
@@ -592,7 +592,7 @@ static char *usb_devnode(const struct device *dev,
                         usb_dev->bus->busnum, usb_dev->devnum);
 }
 
-struct device_type usb_device_type = {
+const struct device_type usb_device_type = {
        .name =         "usb_device",
        .release =      usb_release_dev,
        .uevent =       usb_dev_uevent,
index bfecb50773b6b61d04b9d696faaab7350c9644a6..b8324ea05b20fb037cff5ae53ec1ac6d6498f6e2 100644 (file)
@@ -144,10 +144,10 @@ static inline int usb_disable_usb2_hardware_lpm(struct usb_device *udev)
 extern const struct class usbmisc_class;
 extern const struct bus_type usb_bus_type;
 extern struct mutex usb_port_peer_mutex;
-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 device_type usb_port_device_type;
+extern const struct device_type usb_device_type;
+extern const struct device_type usb_if_device_type;
+extern const struct device_type usb_ep_device_type;
+extern const struct device_type usb_port_device_type;
 extern struct usb_device_driver usb_generic_driver;
 
 static inline int is_usb_device(const struct device *dev)