]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: dibx000_common: Constify struct i2c_algorithm
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 8 Sep 2024 08:21:00 +0000 (10:21 +0200)
committerHans Verkuil <hverkuil@xs4all.nl>
Fri, 21 Feb 2025 09:33:10 +0000 (10:33 +0100)
'struct i2c_algorithm' is not modified in this driver.

Constifying this structure moves some data to a read-only section, so
increase overall security, especially when the structure holds some
function pointers.

To do so, the prototype of i2c_adapter_init() has to be updated as well.

On a x86_64, with allmodconfig:
Before:
======
   text    data     bss     dec     hex filename
  17213     932      20   18165    46f5 drivers/media/dvb-frontends/dibx000_common.o

After:
=====
   text    data     bss     dec     hex filename
  17490     660      20   18170    46fa drivers/media/dvb-frontends/dibx000_common.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
drivers/media/dvb-frontends/dibx000_common.c

index 63a4c6a4afb584e7b8f8e68cba761ec2ff180258..bd5c5d7223aad56a29ec66dc61bc273c3809260f 100644 (file)
@@ -250,12 +250,12 @@ static int dibx000_i2c_master_xfer_gpio34(struct i2c_adapter *i2c_adap, struct i
        return num;
 }
 
-static struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
+static const struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
        .master_xfer = dibx000_i2c_master_xfer_gpio12,
        .functionality = dibx000_i2c_func,
 };
 
-static struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
+static const struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
        .master_xfer = dibx000_i2c_master_xfer_gpio34,
        .functionality = dibx000_i2c_func,
 };
@@ -324,7 +324,7 @@ static int dibx000_i2c_gated_gpio67_xfer(struct i2c_adapter *i2c_adap,
        return ret;
 }
 
-static struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
+static const struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
        .master_xfer = dibx000_i2c_gated_gpio67_xfer,
        .functionality = dibx000_i2c_func,
 };
@@ -369,7 +369,7 @@ static int dibx000_i2c_gated_tuner_xfer(struct i2c_adapter *i2c_adap,
        return ret;
 }
 
-static struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
+static const struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
        .master_xfer = dibx000_i2c_gated_tuner_xfer,
        .functionality = dibx000_i2c_func,
 };
@@ -422,7 +422,7 @@ void dibx000_reset_i2c_master(struct dibx000_i2c_master *mst)
 EXPORT_SYMBOL(dibx000_reset_i2c_master);
 
 static int i2c_adapter_init(struct i2c_adapter *i2c_adap,
-                               struct i2c_algorithm *algo, const char *name,
+                               const struct i2c_algorithm *algo, const char *name,
                                struct dibx000_i2c_master *mst)
 {
        strscpy(i2c_adap->name, name, sizeof(i2c_adap->name));