Skip to content

Commit f6d8baf

Browse files
author
Desnes Nunes
committed
USB: make to_usb_device_driver() use container_of_const()
JIRA: https://issues.redhat.com/browse/RHEL-78828 Conflicts: * Avoiding commit <d69d80484598> ("driver core: have match() callback in struct bus_type take a const *") commit d6fa15b Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Date: Wed, 13 Nov 2024 15:04:41 +0100 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 <johan@kernel.org> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: Grant Grundler <grundler@chromium.org> Cc: Yajun Deng <yajun.deng@linux.dev> Cc: Oliver Neukum <oneukum@suse.com> Cc: Douglas Anderson <dianders@chromium.org> Cc: linux-usb@vger.kernel.org Link: https://lore.kernel.org/r/2024111342-lagoon-reapprove-5e49@gregkh Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Desnes Nunes <desnesn@redhat.com>
1 parent c3758b9 commit f6d8baf

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