[PATCH] i2c: rzv2m: Constify struct i2c_algorithm

Christophe JAILLET posted 1 patch 8 months, 3 weeks ago
drivers/i2c/busses/i2c-rzv2m.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] i2c: rzv2m: Constify struct i2c_algorithm
Posted by Christophe JAILLET 8 months, 3 weeks ago
'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.

On a x86_64, with allmodconfig, as an example:
Before:
======
   text	   data	    bss	    dec	    hex	filename
  11027	    646	     16	  11689	   2da9	drivers/i2c/busses/i2c-rzv2m.o

After:
=====
   text	   data	    bss	    dec	    hex	filename
  11107	    566	     16	  11689	   2da9	drivers/i2c/busses/i2c-rzv2m.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested-only.
---
 drivers/i2c/busses/i2c-rzv2m.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-rzv2m.c b/drivers/i2c/busses/i2c-rzv2m.c
index 53762cc56d28..b0e9c0b62429 100644
--- a/drivers/i2c/busses/i2c-rzv2m.c
+++ b/drivers/i2c/busses/i2c-rzv2m.c
@@ -402,7 +402,7 @@ static const struct i2c_adapter_quirks rzv2m_i2c_quirks = {
 	.flags = I2C_AQ_NO_ZERO_LEN,
 };
 
-static struct i2c_algorithm rzv2m_i2c_algo = {
+static const struct i2c_algorithm rzv2m_i2c_algo = {
 	.xfer = rzv2m_i2c_xfer,
 	.functionality = rzv2m_i2c_func,
 };
-- 
2.49.0
Re: [PATCH] i2c: rzv2m: Constify struct i2c_algorithm
Posted by Andi Shyti 8 months, 1 week ago
Hi Christophe,

On Sat, Mar 29, 2025 at 03:37:07PM +0100, Christophe JAILLET wrote:
> '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.
> 
> On a x86_64, with allmodconfig, as an example:
> Before:
> ======
>    text	   data	    bss	    dec	    hex	filename
>   11027	    646	     16	  11689	   2da9	drivers/i2c/busses/i2c-rzv2m.o
> 
> After:
> =====
>    text	   data	    bss	    dec	    hex	filename
>   11107	    566	     16	  11689	   2da9	drivers/i2c/busses/i2c-rzv2m.o
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

merged to i2c/i2c-host.

Thanks,
Andi