i2c: atr: annotate i2c_atr_adap_desc->aliases with __counted_by_ptr
Subsystems (2)
PATCH 1/1 i2c: atr: annotate i2c_atr_adap_desc->aliases with __counted_by_ptr
Add the __counted_by_ptr() compiler attribute to ->aliases to improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE.
--- include/linux/i2c-atr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/i2c-atr.h +1 -1
@@ -71,7 +71,7 @@ struct i2c_atr_adap_desc {struct device *parent;struct fwnode_handle *bus_handle;size_t num_aliases; -u16 *aliases; + u16 *aliases __counted_by_ptr(num_aliases); };/**
Hello Thorsten,
+Cc Romain, author of the involved code
+Cc Rosen, author of a similar patch elsewhere in i2c-atr [0]
[0] https://lore.kernel.org/linux-i2c/[email protected]/
Quoted 13 lines · Thorsten Blum
Add the
__counted_by_ptr()compiler attribute to ->aliases to improve bounds checking viaCONFIG_UBSAN_BOUNDSandCONFIG_FORTIFY_SOURCE.Signed-off-by Thorsten Blum <[email protected]>--- include/linux/i2c-atr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/i2c-atr.h +0
-0
include/linux/i2c-atr.h struct i2c_atr_adap_desc { · line 74
Quoted 5 lines
include/linux/i2c-atr.h +1
-1@@ -71,7 +71,7 @@ struct i2c_atr_adap_desc {struct device *parent;struct fwnode_handle *bus_handle;size_t num_aliases; -u16 *aliases; + u16 *aliases __counted_by_ptr(num_aliases);
I'm not fully proficient about all counted_by things, but the patch looks OK to me, and definitely @num_aliases is the number of items @aliases must have, so:
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Quoted 17 lines · Luca Ceresoli
Hello Thorsten,
(quoted diff) +2
-0+Cc Romain, author of the involved code +Cc Rosen, author of a similar patch elsewhere in i2c-atr [0][0] https://lore.kernel.org/linux-i2c/[email protected]/
Quoted 8 lines · Thorsten Blum
Add the
__counted_by_ptr()compiler attribute to ->aliases to improve bounds checking viaCONFIG_UBSAN_BOUNDSandCONFIG_FORTIFY_SOURCE.Signed-off-by Thorsten Blum <[email protected]>--- include/linux/i2c-atr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
include/linux/i2c-atr.h struct i2c_atr_adap_desc { · line 74
Quoted 10 lines
include/linux/i2c-atr.h +1
-1@@ -71,7 +71,7 @@ struct i2c_atr_adap_desc {struct device *parent;struct fwnode_handle *bus_handle;size_t num_aliases; -u16 *aliases; + u16 *aliases __counted_by_ptr(num_aliases);I'm not fully proficient about all
counted_bythings, but the patch looks OK to me, and definitely @num_aliases is the number of items @aliases must have, so:
I prefer my patch.
__counted_by is supported by more versions of GCC/Clang than __counted_by_ptr.
Quoted 7 lines
Reviewed-by Luca Ceresoli <[email protected]>--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Luca Ceresoli
reviewerQuoted 32 lines · Rosen Penev
Quoted 17 lines · Luca Ceresoli
Hello Thorsten,
(quoted diff) +2
-0+Cc Romain, author of the involved code +Cc Rosen, author of a similar patch elsewhere in i2c-atr [0][0] https://lore.kernel.org/linux-i2c/[email protected]/
Quoted 8 lines · Thorsten Blum
Add the
__counted_by_ptr()compiler attribute to ->aliases to improve bounds checking viaCONFIG_UBSAN_BOUNDSandCONFIG_FORTIFY_SOURCE.Signed-off-by Thorsten Blum <[email protected]>--- include/linux/i2c-atr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
include/linux/i2c-atr.h struct i2c_atr_adap_desc { · line 74
Quoted 10 lines
include/linux/i2c-atr.h +1
-1@@ -71,7 +71,7 @@ struct i2c_atr_adap_desc {struct device *parent;struct fwnode_handle *bus_handle;size_t num_aliases; -u16 *aliases; + u16 *aliases __counted_by_ptr(num_aliases);I'm not fully proficient about all
counted_bythings, but the patch looks OK to me, and definitely @num_aliases is the number of items @aliases must have, so:
Quoted 3 lines
I prefer my patch.
__counted_byis supported by more versions of GCC/Clang than__counted_by_ptr.
At a quick grep check, they seem to be different things: __counted_by for arrays embedded in structs, __counted_by_ptr for pointers in structs for dynamically allocated arrays. I wish this were documented, though, especially as their implementation is currently identical. :-/
Based on this, I think both Rosen's and Thorsten's changes are OK, using different macros for different members.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com