Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Apr 2021 18:17:31 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 5c00c8224576 - stable/13 - Rename struct device to struct _device
Message-ID:  <202104191817.13JIHVcJ020464@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=5c00c82245764546b30c7152417cd6470fb16ac5

commit 5c00c82245764546b30c7152417cd6470fb16ac5
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2021-04-12 13:32:30 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2021-04-19 18:17:08 +0000

    Rename struct device to struct _device
    
    types.h defines device_t as a typedef of struct device *.  struct device
    is defined in subr_bus.c and almost all of the kernel uses device_t.
    The LinuxKPI also defines a struct device, so type confusion can occur.
    
    This causes bugs and ambiguity for debugging tools.  Rename the FreeBSD
    struct device to struct _device.
    
    Reviewed by:    gbe (man pages)
    Reviewed by:    rpokala, imp, jhb
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D29676
    
    (cherry picked from commit dfff37765ce4ea4fd7db4d293b459dc84008f411)
---
 share/man/man9/device.9       |  2 +-
 share/man/man9/rman.9         |  6 +++---
 sys/kern/subr_bus.c           | 15 +++++++++------
 sys/powerpc/include/bus_dma.h |  4 +---
 sys/sys/pcpu.h                |  2 +-
 sys/sys/systm.h               |  4 +---
 sys/sys/types.h               |  2 +-
 7 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/share/man/man9/device.9 b/share/man/man9/device.9
index 40bd3f16d3ee..d5e30f0abefa 100644
--- a/share/man/man9/device.9
+++ b/share/man/man9/device.9
@@ -35,7 +35,7 @@
 .Nm device
 .Nd an abstract representation of a device
 .Sh SYNOPSIS
-.Vt typedef struct device *device_t ;
+.Vt typedef struct _device *device_t ;
 .Sh DESCRIPTION
 The device object represents a piece of hardware attached to the
 system such as an expansion card, the bus which that card is plugged
diff --git a/share/man/man9/rman.9 b/share/man/man9/rman.9
index 3e03c05f9088..3faea2a014fc 100644
--- a/share/man/man9/rman.9
+++ b/share/man/man9/rman.9
@@ -88,12 +88,12 @@
 .Ft "struct resource *"
 .Fo rman_reserve_resource
 .Fa "struct rman *rm" "rman_res_t start" "rman_res_t end" "rman_res_t count"
-.Fa "u_int flags" "struct device *dev"
+.Fa "u_int flags" "device_t dev"
 .Fc
 .Ft "struct resource *"
 .Fo rman_reserve_resource_bound
 .Fa "struct rman *rm" "rman_res_t start" "rman_res_t end" "rman_res_t count"
-.Fa "rman_res_t bound" "u_int flags" "struct device *dev"
+.Fa "rman_res_t bound" "u_int flags" "device_t dev"
 .Fc
 .Ft uint32_t
 .Fn rman_make_alignment_flags "uint32_t size"
@@ -101,7 +101,7 @@
 .Fn rman_get_start "struct resource *r"
 .Ft rman_res_t
 .Fn rman_get_end "struct resource *r"
-.Ft "struct device *"
+.Ft "device_t"
 .Fn rman_get_device "struct resource *r"
 .Ft rman_res_t
 .Fn rman_get_size "struct resource *r"
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
index ecd6c9685e36..6d5607337ef6 100644
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -95,7 +95,7 @@ struct driverlink {
  */
 typedef TAILQ_HEAD(devclass_list, devclass) devclass_list_t;
 typedef TAILQ_HEAD(driver_list, driverlink) driver_list_t;
-typedef TAILQ_HEAD(device_list, device) device_list_t;
+typedef TAILQ_HEAD(device_list, _device) device_list_t;
 
 struct devclass {
 	TAILQ_ENTRY(devclass) link;
@@ -112,9 +112,12 @@ struct devclass {
 };
 
 /**
- * @brief Implementation of device.
+ * @brief Implementation of _device.
+ *
+ * The structure is named "_device" instead of "device" to avoid type confusion
+ * caused by other subsystems defining a (struct device).
  */
-struct device {
+struct _device {
 	/*
 	 * A device is a kernel object. The first field must be the
 	 * current ops table for the object.
@@ -124,8 +127,8 @@ struct device {
 	/*
 	 * Device hierarchy.
 	 */
-	TAILQ_ENTRY(device)	link;	/**< list of devices in parent */
-	TAILQ_ENTRY(device)	devlink; /**< global device list membership */
+	TAILQ_ENTRY(_device)	link;	/**< list of devices in parent */
+	TAILQ_ENTRY(_device)	devlink; /**< global device list membership */
 	device_t	parent;		/**< parent of this device  */
 	device_list_t	children;	/**< list of child devices */
 
@@ -853,7 +856,7 @@ devctl_safe_quote_sb(struct sbuf *sb, const char *src)
 
 /* End of /dev/devctl code */
 
-static TAILQ_HEAD(,device)	bus_data_devices;
+static struct device_list bus_data_devices;
 static int bus_data_generation = 1;
 
 static kobj_method_t null_methods[] = {
diff --git a/sys/powerpc/include/bus_dma.h b/sys/powerpc/include/bus_dma.h
index ba4ebdab4c42..947a25819a7e 100644
--- a/sys/powerpc/include/bus_dma.h
+++ b/sys/powerpc/include/bus_dma.h
@@ -33,8 +33,6 @@
 #include <sys/bus_dma.h>
 #include <sys/bus_dma_internal.h>
 
-struct device;
-
-int bus_dma_tag_set_iommu(bus_dma_tag_t, struct device *iommu, void *cookie);
+int bus_dma_tag_set_iommu(bus_dma_tag_t, device_t iommu, void *cookie);
 
 #endif /* _POWERPC_BUS_DMA_H_ */
diff --git a/sys/sys/pcpu.h b/sys/sys/pcpu.h
index 43827b1af4fa..cfc8a215707c 100644
--- a/sys/sys/pcpu.h
+++ b/sys/sys/pcpu.h
@@ -187,7 +187,7 @@ struct pcpu {
 	STAILQ_ENTRY(pcpu) pc_allcpu;
 	struct lock_list_entry *pc_spinlocks;
 	long		pc_cp_time[CPUSTATES];	/* statclock ticks */
-	struct device	*pc_device;
+	struct _device	*pc_device;		/* CPU device handle */
 	void		*pc_netisr;		/* netisr SWI cookie */
 	int		pc_unused1;		/* unused field */
 	int		pc_domain;		/* Memory domain. */
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index 369b8bdedb51..d13379b0a12f 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -614,9 +614,8 @@ void counted_warning(unsigned *counter, const char *msg);
 /*
  * APIs to manage deprecation and obsolescence.
  */
-struct device;
 void _gone_in(int major, const char *msg);
-void _gone_in_dev(struct device *dev, int major, const char *msg);
+void _gone_in_dev(device_t dev, int major, const char *msg);
 #ifdef NO_OBSOLETE_CODE
 #define __gone_ok(m, msg)					 \
 	_Static_assert(m < P_OSREL_MAJOR(__FreeBSD_version)),	 \
@@ -629,5 +628,4 @@ void _gone_in_dev(struct device *dev, int major, const char *msg);
 #endif /* _KERNEL */
 
 __NULLABILITY_PRAGMA_POP
-
 #endif /* !_SYS_SYSTM_H_ */
diff --git a/sys/sys/types.h b/sys/sys/types.h
index c026fa023bd0..58abcf00cebb 100644
--- a/sys/sys/types.h
+++ b/sys/sys/types.h
@@ -272,7 +272,7 @@ typedef __rman_res_t    rman_res_t;
 
 #ifdef _KERNEL
 typedef	int		boolean_t;
-typedef	struct device	*device_t;
+typedef	struct _device	*device_t;
 typedef	__intfptr_t	intfptr_t;
 
 /*



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