i2c: virtio: Constify struct i2c_algorithm and struct virtio_device_id

'struct i2c_algorithm' and 'struct virtio_device_id' are 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, which is the case for struct i2c_algorithm.

On a x86_64, with allmodconfig:
Before:
======
   text	   data	    bss	    dec	    hex	filename
   6663	    568	     16	   7247	   1c4f	drivers/i2c/busses/i2c-virtio.o

After:
=====
   text	   data	    bss	    dec	    hex	filename
   6735	    472	     16	   7223	   1c37	drivers/i2c/busses/i2c-virtio.o

--
Compile tested only

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
This commit is contained in:
Christophe JAILLET 2024-09-08 08:52:07 +02:00 committed by Andi Shyti
parent 1bae758922
commit 35b6c073cc

View File

@ -182,7 +182,7 @@ static u32 virtio_i2c_func(struct i2c_adapter *adap)
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
}
static struct i2c_algorithm virtio_algorithm = {
static const struct i2c_algorithm virtio_algorithm = {
.xfer = virtio_i2c_xfer,
.functionality = virtio_i2c_func,
};
@ -237,7 +237,7 @@ static void virtio_i2c_remove(struct virtio_device *vdev)
virtio_i2c_del_vqs(vdev);
}
static struct virtio_device_id id_table[] = {
static const struct virtio_device_id id_table[] = {
{ VIRTIO_ID_I2C_ADAPTER, VIRTIO_DEV_ANY_ID },
{}
};