2024-02-19 12:38:16

by Ricardo B. Marliere

[permalink] [raw]
Subject: [PATCH] i2c: constify the struct device_type usage

Since commit aed65af1cc2f ("drivers: make device_type const"), the driver
core can properly handle constant struct device_type. Move the
i2c_adapter_type and i2c_client_type variables to be constant structures as
well, placing it into read-only memory which can not be modified at
runtime.

Cc: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Ricardo B. Marliere <[email protected]>
---
drivers/i2c/i2c-core-base.c | 4 ++--
include/linux/i2c.h | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 3bd48d4b6318..ff5c486a1dbb 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -701,7 +701,7 @@ const struct bus_type i2c_bus_type = {
};
EXPORT_SYMBOL_GPL(i2c_bus_type);

-struct device_type i2c_client_type = {
+const struct device_type i2c_client_type = {
.groups = i2c_dev_groups,
.uevent = i2c_device_uevent,
.release = i2c_client_dev_release,
@@ -1343,7 +1343,7 @@ static struct attribute *i2c_adapter_attrs[] = {
};
ATTRIBUTE_GROUPS(i2c_adapter);

-struct device_type i2c_adapter_type = {
+const struct device_type i2c_adapter_type = {
.groups = i2c_adapter_groups,
.release = i2c_adapter_dev_release,
};
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 652ecb7abeda..ff93ff8b257c 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -24,8 +24,8 @@
#include <uapi/linux/i2c.h>

extern const struct bus_type i2c_bus_type;
-extern struct device_type i2c_adapter_type;
-extern struct device_type i2c_client_type;
+extern const struct device_type i2c_adapter_type;
+extern const struct device_type i2c_client_type;

/* --- General options ------------------------------------------------ */


---
base-commit: 67ec505fae32419354f4172c06c853def2541300
change-id: 20240219-device_cleanup-i2c-5a53da345188

Best regards,
--
Ricardo B. Marliere <[email protected]>



2024-03-04 13:29:49

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH] i2c: constify the struct device_type usage

On Mon, Feb 19, 2024 at 09:38:47AM -0300, Ricardo B. Marliere wrote:
> Since commit aed65af1cc2f ("drivers: make device_type const"), the driver
> core can properly handle constant struct device_type. Move the
> i2c_adapter_type and i2c_client_type variables to be constant structures as
> well, placing it into read-only memory which can not be modified at
> runtime.
>
> Cc: Greg Kroah-Hartman <[email protected]>
> Signed-off-by: Ricardo B. Marliere <[email protected]>

Applied to for-next, thanks!


Attachments:
(No filename) (529.00 B)
signature.asc (849.00 B)
Download all attachments