Skip to contentSkip to conversation

iio: Mark iio_device_type as const

PATCH Applied Lars-Peter Clausen 2 participants 2 messages Oct 31, 2021 – Nov 3, 2021 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: Mark iio_device_type as const

The iio_device_type struct is never modified, mark it as const. This allows it to be placed in a read-only memory section, which will protect against accidental or deliberate modification.

---
 drivers/iio/iio_core.h          | 2 +-
 drivers/iio/industrialio-core.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/iio/iio_core.h +1 -1
index 61e318431de9..501e286702ef 100644
@@ -16,7 +16,7 @@ struct iio_buffer;
 struct iio_chan_spec;
 struct iio_dev;
 
-extern struct device_type iio_device_type;
+extern const struct device_type iio_device_type;
 
 struct iio_dev_buffer_pair {
 	struct iio_dev		*indio_dev;
drivers/iio/industrialio-core.c +1 -1
index 463a63d5bf56..737518efa38f 100644
@@ -1619,7 +1619,7 @@ static void iio_dev_release(struct device *device)
 	kfree(iio_dev_opaque);
 }
 
-struct device_type iio_device_type = {
+const struct device_type iio_device_type = {
 	.name = "iio_device",
 	.release = iio_dev_release,
 };
Signature · 1 line
2.20.1
maintainer Applied
#1 lore raw
Quoted 5 lines · On Sun, 31 Oct 2021 09:04:21 +0100 Lars-Peter Clausen <[email protected]> wrote:

The iio_device_type struct is never modified, mark it as const. This allows it to be placed in a read-only memory section, which will protect against accidental or deliberate modification.

Applied to the togreg branch of iio.git which will be only visible as testing for 0-day to poke at it until after the merge window.

Thanks,

Jonathan

Quoted 31 lines
---
 drivers/iio/iio_core.h          | 2 +-
 drivers/iio/industrialio-core.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/iio/iio_core.h +1 -1
index 61e318431de9..501e286702ef 100644
@@ -16,7 +16,7 @@ struct iio_buffer;
 struct iio_chan_spec;
 struct iio_dev;
 
-extern struct device_type iio_device_type;
+extern const struct device_type iio_device_type;
 
 struct iio_dev_buffer_pair {
 	struct iio_dev		*indio_dev;
drivers/iio/industrialio-core.c +1 -1
index 463a63d5bf56..737518efa38f 100644
@@ -1619,7 +1619,7 @@ static void iio_dev_release(struct device *device)
 	kfree(iio_dev_opaque);
 }
 
-struct device_type iio_device_type = {
+const struct device_type iio_device_type = {
 	.name = "iio_device",
 	.release = iio_dev_release,
 };