Skip to content

Commit d6fa15b

Browse files
committed
USB: make to_usb_device_driver() use container_of_const()
Turns out that we have some const pointers being passed to to_usb_device_driver() but were not catching this. Change the macro to properly propagate the const-ness of the pointer so that we will notice when we try to write to memory that we shouldn't be writing to. This requires fixing up the usb_driver_applicable() function as well, because it can handle a const * to struct usb_driver. Cc: Johan Hovold <[email protected]> Cc: Alan Stern <[email protected]> Cc: Grant Grundler <[email protected]> Cc: Yajun Deng <[email protected]> Cc: Oliver Neukum <[email protected]> Cc: Douglas Anderson <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/2024111342-lagoon-reapprove-5e49@gregkh Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2f3aab7 commit d6fa15b

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

drivers/usb/core/driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ const struct usb_device_id *usb_device_match_id(struct usb_device *udev,
850850
EXPORT_SYMBOL_GPL(usb_device_match_id);
851851

852852
bool usb_driver_applicable(struct usb_device *udev,
853-
struct usb_device_driver *udrv)
853+
const struct usb_device_driver *udrv)
854854
{
855855
if (udrv->id_table && udrv->match)
856856
return usb_device_match_id(udev, udrv->id_table) != NULL &&
@@ -870,7 +870,7 @@ static int usb_device_match(struct device *dev, const struct device_driver *drv)
870870
/* devices and interfaces are handled separately */
871871
if (is_usb_device(dev)) {
872872
struct usb_device *udev;
873-
struct usb_device_driver *udrv;
873+
const struct usb_device_driver *udrv;
874874

875875
/* interface drivers never match devices */
876876
if (!is_usb_device_driver(drv))

drivers/usb/core/usb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ extern int usb_match_device(struct usb_device *dev,
7575
extern const struct usb_device_id *usb_device_match_id(struct usb_device *udev,
7676
const struct usb_device_id *id);
7777
extern bool usb_driver_applicable(struct usb_device *udev,
78-
struct usb_device_driver *udrv);
78+
const struct usb_device_driver *udrv);
7979
extern void usb_forced_unbind_intf(struct usb_interface *intf);
8080
extern void usb_unbind_and_rebind_marked_interfaces(struct usb_device *udev);
8181

include/linux/usb.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,7 @@ struct usb_device_driver {
12941294
unsigned int supports_autosuspend:1;
12951295
unsigned int generic_subclass:1;
12961296
};
1297-
#define to_usb_device_driver(d) container_of(d, struct usb_device_driver, \
1298-
driver)
1297+
#define to_usb_device_driver(d) container_of_const(d, struct usb_device_driver, driver)
12991298

13001299
/**
13011300
* struct usb_class_driver - identifies a USB driver that wants to use the USB major number

0 commit comments

Comments
 (0)