Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <sakari.ailus@linux.intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20221205121206.166576-3-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+2 -40
+2 -40
include/linux/usb.h
··· 259 259 struct work_struct reset_ws; /* for resets in atomic context */ 260 260 }; 261 261 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) 282 263 283 264 static inline void *usb_get_intfdata(struct usb_interface *intf) 284 265 { ··· 711 730 unsigned use_generic_driver:1; 712 731 }; 713 732 714 - static inline struct usb_device *__to_usb_device(struct device *d) 715 - { 716 - return container_of(d, struct usb_device, dev); 717 - } 718 - 719 - static inline const struct usb_device *__to_usb_device_const(const struct device *d) 720 - { 721 - return container_of(d, struct usb_device, dev); 722 - } 723 - 724 - /* 725 - * container_of() will happily take a const * and spit back a non-const * as it 726 - * is just doing pointer math. But we want to be a bit more careful in the USB 727 - * driver code, so manually force any const * of a device to also be a const * 728 - * to a usb_device. 729 - */ 730 - #define to_usb_device(dev) \ 731 - _Generic((dev), \ 732 - const struct device *: __to_usb_device_const, \ 733 - struct device *: __to_usb_device)(dev) 733 + #define to_usb_device(__dev) container_of_const(__dev, struct usb_device, dev) 734 734 735 735 static inline struct usb_device *__intf_to_usbdev(struct usb_interface *intf) 736 736 {