Skip to content

Commit 35b6c07

Browse files
tititiou36Andi Shyti
authored andcommitted
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 <[email protected]> Signed-off-by: Andi Shyti <[email protected]>
1 parent 1bae758 commit 35b6c07

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/i2c/busses/i2c-virtio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static u32 virtio_i2c_func(struct i2c_adapter *adap)
182182
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
183183
}
184184

185-
static struct i2c_algorithm virtio_algorithm = {
185+
static const struct i2c_algorithm virtio_algorithm = {
186186
.xfer = virtio_i2c_xfer,
187187
.functionality = virtio_i2c_func,
188188
};
@@ -237,7 +237,7 @@ static void virtio_i2c_remove(struct virtio_device *vdev)
237237
virtio_i2c_del_vqs(vdev);
238238
}
239239

240-
static struct virtio_device_id id_table[] = {
240+
static const struct virtio_device_id id_table[] = {
241241
{ VIRTIO_ID_I2C_ADAPTER, VIRTIO_DEV_ANY_ID },
242242
{}
243243
};

0 commit comments

Comments
 (0)