From e94ed10475e599705365202335caa283dc8766cb Mon Sep 17 00:00:00 2001 From: jhb Date: Thu, 17 Dec 2020 20:45:10 +0000 Subject: [PATCH] Use __containerof() instead of home-rolled versions. Reviewed by: imp, hselasky Obtained from: CheriBSD Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D27582 --- sys/dev/usb/controller/ehci.c | 3 +-- sys/dev/usb/controller/ohci.c | 3 +-- sys/dev/usb/controller/uhci.c | 3 +-- sys/dev/usb/controller/xhci.c | 3 +-- sys/dev/usb/usb_transfer.h | 4 +--- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/sys/dev/usb/controller/ehci.c b/sys/dev/usb/controller/ehci.c index 9e56cc51a8f..0b7f41b3923 100644 --- a/sys/dev/usb/controller/ehci.c +++ b/sys/dev/usb/controller/ehci.c @@ -90,8 +90,7 @@ #include #define EHCI_BUS2SC(bus) \ - ((ehci_softc_t *)(((uint8_t *)(bus)) - \ - ((uint8_t *)&(((ehci_softc_t *)0)->sc_bus)))) + __containerof(bus, ehci_softc_t, sc_bus) #ifdef USB_DEBUG static int ehcidebug = 0; diff --git a/sys/dev/usb/controller/ohci.c b/sys/dev/usb/controller/ohci.c index ac3e46fb7fd..39f3bd54f50 100644 --- a/sys/dev/usb/controller/ohci.c +++ b/sys/dev/usb/controller/ohci.c @@ -79,8 +79,7 @@ #include #define OHCI_BUS2SC(bus) \ - ((ohci_softc_t *)(((uint8_t *)(bus)) - \ - ((uint8_t *)&(((ohci_softc_t *)0)->sc_bus)))) + __containerof(bus, ohci_softc_t, sc_bus) #ifdef USB_DEBUG static int ohcidebug = 0; diff --git a/sys/dev/usb/controller/uhci.c b/sys/dev/usb/controller/uhci.c index 32a420abbfe..59453359deb 100644 --- a/sys/dev/usb/controller/uhci.c +++ b/sys/dev/usb/controller/uhci.c @@ -83,8 +83,7 @@ #define alt_next next #define UHCI_BUS2SC(bus) \ - ((uhci_softc_t *)(((uint8_t *)(bus)) - \ - ((uint8_t *)&(((uhci_softc_t *)0)->sc_bus)))) + __containerof(bus, uhci_softc_t, sc_bus) #ifdef USB_DEBUG static int uhcidebug = 0; diff --git a/sys/dev/usb/controller/xhci.c b/sys/dev/usb/controller/xhci.c index efab2413cea..1f8877546c2 100644 --- a/sys/dev/usb/controller/xhci.c +++ b/sys/dev/usb/controller/xhci.c @@ -86,8 +86,7 @@ #include #define XHCI_BUS2SC(bus) \ - ((struct xhci_softc *)(((uint8_t *)(bus)) - \ - ((uint8_t *)&(((struct xhci_softc *)0)->sc_bus)))) + __containerof(bus, struct xhci_softc, sc_bus) static SYSCTL_NODE(_hw_usb, OID_AUTO, xhci, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "USB XHCI"); diff --git a/sys/dev/usb/usb_transfer.h b/sys/dev/usb/usb_transfer.h index da632a73826..c6b97e1ab3c 100644 --- a/sys/dev/usb/usb_transfer.h +++ b/sys/dev/usb/usb_transfer.h @@ -153,9 +153,7 @@ struct usb_done_msg { }; #define USB_DMATAG_TO_XROOT(dpt) \ - ((struct usb_xfer_root *)( \ - ((uint8_t *)(dpt)) - \ - ((uint8_t *)&((struct usb_xfer_root *)0)->dma_parent_tag))) + __containerof(dpt, struct usb_xfer_root, dma_parent_tag) /* * The following structure is used to keep information about memory -- 2.45.0