Skip to content

Commit c3da679

Browse files
committed
usb.h: take advantage of container_of_const()
Instead of rolling our own const-checking logic in to_usb_interface() and to_usb_device() use the newly added container_of_const() instead, making the logic much simpler overall. Reviewed-by: Sakari Ailus <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6149f83 commit c3da679

File tree

1 file changed

+2
-40
lines changed

1 file changed

+2
-40
lines changed

include/linux/usb.h

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -259,26 +259,7 @@ struct usb_interface {
259259
struct work_struct reset_ws; /* for resets in atomic context */
260260
};
261261

262-
static inline struct usb_interface *__to_usb_interface(struct device *d)
263-
{
264-
return container_of(d, struct usb_interface, dev);
265-
}
266-
267-
static inline const struct usb_interface *__to_usb_interface_const(const struct device *d)
268-
{
269-
return container_of(d, struct usb_interface, dev);
270-
}
271-
272-
/*
273-
* container_of() will happily take a const * and spit back a non-const * as it
274-
* is just doing pointer math. But we want to be a bit more careful in the USB
275-
* driver code, so manually force any const * of a device to also be a const *
276-
* to a usb_device.
277-
*/
278-
#define to_usb_interface(dev) \
279-
_Generic((dev), \
280-
const struct device *: __to_usb_interface_const, \
281-
struct device *: __to_usb_interface)(dev)
262+
#define to_usb_interface(__dev) container_of_const(__dev, struct usb_interface, dev)
282263

283264
static inline void *usb_get_intfdata(struct usb_interface *intf)
284265
{
@@ -730,26 +711,7 @@ struct usb_device {
730711
unsigned use_generic_driver:1;
731712
};
732713

733-
static inline struct usb_device *__to_usb_device(struct device *d)
734-
{
735-
return container_of(d, struct usb_device, dev);
736-
}
737-
738-
static inline const struct usb_device *__to_usb_device_const(const struct device *d)
739-
{
740-
return container_of(d, struct usb_device, dev);
741-
}
742-
743-
/*
744-
* container_of() will happily take a const * and spit back a non-const * as it
745-
* is just doing pointer math. But we want to be a bit more careful in the USB
746-
* driver code, so manually force any const * of a device to also be a const *
747-
* to a usb_device.
748-
*/
749-
#define to_usb_device(dev) \
750-
_Generic((dev), \
751-
const struct device *: __to_usb_device_const, \
752-
struct device *: __to_usb_device)(dev)
714+
#define to_usb_device(__dev) container_of_const(__dev, struct usb_device, dev)
753715

754716
static inline struct usb_device *__intf_to_usbdev(struct usb_interface *intf)
755717
{

0 commit comments

Comments
 (0)