* [PATCH] i2c: atr: annotate i2c_atr_adap_desc->aliases with __counted_by_ptr @ 2026-04-27 17:28 Thorsten Blum 2026-04-28 9:29 ` Luca Ceresoli 0 siblings, 1 reply; 4+ messages in thread From: Thorsten Blum @ 2026-04-27 17:28 UTC (permalink / raw) To: Tomi Valkeinen, Luca Ceresoli, Kees Cook, Gustavo A. R. Silva Cc: Thorsten Blum, linux-i2c, linux-kernel, linux-hardening Add the __counted_by_ptr() compiler attribute to ->aliases to improve bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> --- include/linux/i2c-atr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/i2c-atr.h b/include/linux/i2c-atr.h index 2bb54dc87c8e..b52a7b9ec536 100644 --- a/include/linux/i2c-atr.h +++ b/include/linux/i2c-atr.h @@ -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); }; /** ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: atr: annotate i2c_atr_adap_desc->aliases with __counted_by_ptr 2026-04-27 17:28 [PATCH] i2c: atr: annotate i2c_atr_adap_desc->aliases with __counted_by_ptr Thorsten Blum @ 2026-04-28 9:29 ` Luca Ceresoli 2026-04-28 20:27 ` Rosen Penev 0 siblings, 1 reply; 4+ messages in thread From: Luca Ceresoli @ 2026-04-28 9:29 UTC (permalink / raw) To: Thorsten Blum, Tomi Valkeinen, Kees Cook, Gustavo A. R. Silva Cc: linux-i2c, linux-kernel, linux-hardening, Romain Gantois, Rosen Penev 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/20260327030310.8502-1-rosenp@gmail.com/ On Mon Apr 27, 2026 at 7:28 PM CEST, Thorsten Blum wrote: > Add the __counted_by_ptr() compiler attribute to ->aliases to improve > bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE. > > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> > --- > include/linux/i2c-atr.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/i2c-atr.h b/include/linux/i2c-atr.h > index 2bb54dc87c8e..b52a7b9ec536 100644 > --- a/include/linux/i2c-atr.h > +++ b/include/linux/i2c-atr.h > @@ -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: Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> -- Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: atr: annotate i2c_atr_adap_desc->aliases with __counted_by_ptr 2026-04-28 9:29 ` Luca Ceresoli @ 2026-04-28 20:27 ` Rosen Penev 2026-04-29 10:39 ` Luca Ceresoli 0 siblings, 1 reply; 4+ messages in thread From: Rosen Penev @ 2026-04-28 20:27 UTC (permalink / raw) To: Luca Ceresoli Cc: Thorsten Blum, Tomi Valkeinen, Kees Cook, Gustavo A. R. Silva, linux-i2c, linux-kernel, linux-hardening, Romain Gantois On Tue, Apr 28, 2026 at 2:30 AM Luca Ceresoli <luca.ceresoli@bootlin.com> wrote: > > 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/20260327030310.8502-1-rosenp@gmail.com/ > > On Mon Apr 27, 2026 at 7:28 PM CEST, Thorsten Blum wrote: > > Add the __counted_by_ptr() compiler attribute to ->aliases to improve > > bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE. > > > > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> > > --- > > include/linux/i2c-atr.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/include/linux/i2c-atr.h b/include/linux/i2c-atr.h > > index 2bb54dc87c8e..b52a7b9ec536 100644 > > --- a/include/linux/i2c-atr.h > > +++ b/include/linux/i2c-atr.h > > @@ -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: I prefer my patch. __counted_by is supported by more versions of GCC/Clang than __counted_by_ptr. > > Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> > > -- > Luca Ceresoli, Bootlin > Embedded Linux and Kernel engineering > https://bootlin.com ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: atr: annotate i2c_atr_adap_desc->aliases with __counted_by_ptr 2026-04-28 20:27 ` Rosen Penev @ 2026-04-29 10:39 ` Luca Ceresoli 0 siblings, 0 replies; 4+ messages in thread From: Luca Ceresoli @ 2026-04-29 10:39 UTC (permalink / raw) To: Rosen Penev Cc: Thorsten Blum, Tomi Valkeinen, Kees Cook, Gustavo A. R. Silva, linux-i2c, linux-kernel, linux-hardening, Romain Gantois On Tue Apr 28, 2026 at 10:27 PM CEST, Rosen Penev wrote: > On Tue, Apr 28, 2026 at 2:30 AM Luca Ceresoli <luca.ceresoli@bootlin.com> wrote: >> >> 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/20260327030310.8502-1-rosenp@gmail.com/ >> >> On Mon Apr 27, 2026 at 7:28 PM CEST, Thorsten Blum wrote: >> > Add the __counted_by_ptr() compiler attribute to ->aliases to improve >> > bounds checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE. >> > >> > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> >> > --- >> > include/linux/i2c-atr.h | 2 +- >> > 1 file changed, 1 insertion(+), 1 deletion(-) >> > >> > diff --git a/include/linux/i2c-atr.h b/include/linux/i2c-atr.h >> > index 2bb54dc87c8e..b52a7b9ec536 100644 >> > --- a/include/linux/i2c-atr.h >> > +++ b/include/linux/i2c-atr.h >> > @@ -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: > I prefer my patch. > > __counted_by is 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-29 10:39 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-04-27 17:28 [PATCH] i2c: atr: annotate i2c_atr_adap_desc->aliases with __counted_by_ptr Thorsten Blum 2026-04-28 9:29 ` Luca Ceresoli 2026-04-28 20:27 ` Rosen Penev 2026-04-29 10:39 ` Luca Ceresoli
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox