Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Dec 2020 20:45:11 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r368741 - in head/sys/dev/usb: . controller
Message-ID:  <202012172045.0BHKjB9m012678@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Thu Dec 17 20:45:10 2020
New Revision: 368741
URL: https://svnweb.freebsd.org/changeset/base/368741

Log:
  Use __containerof() instead of home-rolled versions.
  
  Reviewed by:	imp, hselasky
  Obtained from:	CheriBSD
  Sponsored by:	DARPA
  Differential Revision:	https://reviews.freebsd.org/D27582

Modified:
  head/sys/dev/usb/controller/ehci.c
  head/sys/dev/usb/controller/ohci.c
  head/sys/dev/usb/controller/uhci.c
  head/sys/dev/usb/controller/xhci.c
  head/sys/dev/usb/usb_transfer.h

Modified: head/sys/dev/usb/controller/ehci.c
==============================================================================
--- head/sys/dev/usb/controller/ehci.c	Thu Dec 17 20:31:45 2020	(r368740)
+++ head/sys/dev/usb/controller/ehci.c	Thu Dec 17 20:45:10 2020	(r368741)
@@ -90,8 +90,7 @@
 #include <dev/usb/controller/ehcireg.h>
 
 #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;

Modified: head/sys/dev/usb/controller/ohci.c
==============================================================================
--- head/sys/dev/usb/controller/ohci.c	Thu Dec 17 20:31:45 2020	(r368740)
+++ head/sys/dev/usb/controller/ohci.c	Thu Dec 17 20:45:10 2020	(r368741)
@@ -79,8 +79,7 @@
 #include <dev/usb/controller/ohcireg.h>
 
 #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;

Modified: head/sys/dev/usb/controller/uhci.c
==============================================================================
--- head/sys/dev/usb/controller/uhci.c	Thu Dec 17 20:31:45 2020	(r368740)
+++ head/sys/dev/usb/controller/uhci.c	Thu Dec 17 20:45:10 2020	(r368741)
@@ -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;

Modified: head/sys/dev/usb/controller/xhci.c
==============================================================================
--- head/sys/dev/usb/controller/xhci.c	Thu Dec 17 20:31:45 2020	(r368740)
+++ head/sys/dev/usb/controller/xhci.c	Thu Dec 17 20:45:10 2020	(r368741)
@@ -86,8 +86,7 @@
 #include <dev/usb/controller/xhcireg.h>
 
 #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");

Modified: head/sys/dev/usb/usb_transfer.h
==============================================================================
--- head/sys/dev/usb/usb_transfer.h	Thu Dec 17 20:31:45 2020	(r368740)
+++ head/sys/dev/usb/usb_transfer.h	Thu Dec 17 20:45:10 2020	(r368741)
@@ -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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202012172045.0BHKjB9m012678>