Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: dvb-usb-v2: Constify struct i2c_algorithm

'struct i2c_algorithm' are not modified in these drivers.

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

More over, dvb_usb_device_properties->i2c_algo seems to only be copied in
i2c_adapter->algo, which is already a "const struct i2c_algorithm".
This is done in dvb_usbv2_i2c_init()

On a x86_64, with allmodconfig, as an example:
Before:
======
text data bss dec hex filename
35366 5832 36 41234 a112 drivers/media/usb/dvb-usb-v2/af9015.o

After:
=====
text data bss dec hex filename
35430 5768 36 41234 a112 drivers/media/usb/dvb-usb-v2/af9015.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>

authored by

Christophe JAILLET and committed by
Hans Verkuil
d22d91fb fc91d334

+13 -13
+1 -1
drivers/media/usb/dvb-usb-v2/af9015.c
··· 260 260 return I2C_FUNC_I2C; 261 261 } 262 262 263 - static struct i2c_algorithm af9015_i2c_algo = { 263 + static const struct i2c_algorithm af9015_i2c_algo = { 264 264 .master_xfer = af9015_i2c_xfer, 265 265 .functionality = af9015_i2c_func, 266 266 };
+1 -1
drivers/media/usb/dvb-usb-v2/af9035.c
··· 483 483 return I2C_FUNC_I2C; 484 484 } 485 485 486 - static struct i2c_algorithm af9035_i2c_algo = { 486 + static const struct i2c_algorithm af9035_i2c_algo = { 487 487 .master_xfer = af9035_i2c_master_xfer, 488 488 .functionality = af9035_i2c_functionality, 489 489 };
+1 -1
drivers/media/usb/dvb-usb-v2/anysee.c
··· 235 235 return I2C_FUNC_I2C; 236 236 } 237 237 238 - static struct i2c_algorithm anysee_i2c_algo = { 238 + static const struct i2c_algorithm anysee_i2c_algo = { 239 239 .master_xfer = anysee_master_xfer, 240 240 .functionality = anysee_i2c_func, 241 241 };
+1 -1
drivers/media/usb/dvb-usb-v2/au6610.c
··· 115 115 return I2C_FUNC_I2C; 116 116 } 117 117 118 - static struct i2c_algorithm au6610_i2c_algo = { 118 + static const struct i2c_algorithm au6610_i2c_algo = { 119 119 .master_xfer = au6610_i2c_xfer, 120 120 .functionality = au6610_i2c_func, 121 121 };
+1 -1
drivers/media/usb/dvb-usb-v2/az6007.c
··· 838 838 return I2C_FUNC_I2C; 839 839 } 840 840 841 - static struct i2c_algorithm az6007_i2c_algo = { 841 + static const struct i2c_algorithm az6007_i2c_algo = { 842 842 .master_xfer = az6007_i2c_xfer, 843 843 .functionality = az6007_i2c_func, 844 844 };
+1 -1
drivers/media/usb/dvb-usb-v2/ce6230.c
··· 154 154 return I2C_FUNC_I2C; 155 155 } 156 156 157 - static struct i2c_algorithm ce6230_i2c_algorithm = { 157 + static const struct i2c_algorithm ce6230_i2c_algorithm = { 158 158 .master_xfer = ce6230_i2c_master_xfer, 159 159 .functionality = ce6230_i2c_functionality, 160 160 };
+1 -1
drivers/media/usb/dvb-usb-v2/dvb_usb.h
··· 243 243 int (*download_firmware) (struct dvb_usb_device *, 244 244 const struct firmware *); 245 245 246 - struct i2c_algorithm *i2c_algo; 246 + const struct i2c_algorithm *i2c_algo; 247 247 248 248 unsigned int num_adapters; 249 249 int (*get_adapter_count) (struct dvb_usb_device *);
+1 -1
drivers/media/usb/dvb-usb-v2/dvbsky.c
··· 169 169 return I2C_FUNC_I2C; 170 170 } 171 171 172 - static struct i2c_algorithm dvbsky_i2c_algo = { 172 + static const struct i2c_algorithm dvbsky_i2c_algo = { 173 173 .master_xfer = dvbsky_i2c_xfer, 174 174 .functionality = dvbsky_i2c_func, 175 175 };
+1 -1
drivers/media/usb/dvb-usb-v2/ec168.c
··· 176 176 return I2C_FUNC_I2C; 177 177 } 178 178 179 - static struct i2c_algorithm ec168_i2c_algo = { 179 + static const struct i2c_algorithm ec168_i2c_algo = { 180 180 .master_xfer = ec168_i2c_xfer, 181 181 .functionality = ec168_i2c_func, 182 182 };
+1 -1
drivers/media/usb/dvb-usb-v2/gl861.c
··· 162 162 return I2C_FUNC_I2C; 163 163 } 164 164 165 - static struct i2c_algorithm gl861_i2c_algo = { 165 + static const struct i2c_algorithm gl861_i2c_algo = { 166 166 .master_xfer = gl861_i2c_master_xfer, 167 167 .functionality = gl861_i2c_functionality, 168 168 };
+1 -1
drivers/media/usb/dvb-usb-v2/lmedm04.c
··· 559 559 return I2C_FUNC_I2C; 560 560 } 561 561 562 - static struct i2c_algorithm lme2510_i2c_algo = { 562 + static const struct i2c_algorithm lme2510_i2c_algo = { 563 563 .master_xfer = lme2510_i2c_xfer, 564 564 .functionality = lme2510_i2c_func, 565 565 };
+1 -1
drivers/media/usb/dvb-usb-v2/mxl111sf.c
··· 911 911 return I2C_FUNC_I2C; 912 912 } 913 913 914 - static struct i2c_algorithm mxl111sf_i2c_algo = { 914 + static const struct i2c_algorithm mxl111sf_i2c_algo = { 915 915 .master_xfer = mxl111sf_i2c_xfer, 916 916 .functionality = mxl111sf_i2c_func, 917 917 #ifdef NEED_ALGO_CONTROL
+1 -1
drivers/media/usb/dvb-usb-v2/rtl28xxu.c
··· 290 290 return I2C_FUNC_I2C; 291 291 } 292 292 293 - static struct i2c_algorithm rtl28xxu_i2c_algo = { 293 + static const struct i2c_algorithm rtl28xxu_i2c_algo = { 294 294 .master_xfer = rtl28xxu_i2c_xfer, 295 295 .functionality = rtl28xxu_i2c_func, 296 296 };