diff mbox series

[v1,1/1] gpiolib: cdev: Annotate struct linereq with __counted_by()

Message ID 20230918091553.1103567-1-andriy.shevchenko@linux.intel.com
State New
Headers show
Series [v1,1/1] gpiolib: cdev: Annotate struct linereq with __counted_by() | expand

Commit Message

Andy Shevchenko Sept. 18, 2023, 9:15 a.m. UTC
Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family                                         functions).

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpiolib-cdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andy Shevchenko Sept. 25, 2023, 6:54 a.m. UTC | #1
On Mon, Sep 18, 2023 at 12:15:53PM +0300, Andy Shevchenko wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family                                         functions).

Kees' patch is better, please ignore this one.
Kees Cook Sept. 25, 2023, 5:17 p.m. UTC | #2
On Mon, Sep 25, 2023 at 09:54:34AM +0300, Andy Shevchenko wrote:
> On Mon, Sep 18, 2023 at 12:15:53PM +0300, Andy Shevchenko wrote:
> > Prepare for the coming implementation by GCC and Clang of the __counted_by
> > attribute. Flexible array members annotated with __counted_by can have
> > their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
> > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family                                         functions).
> 
> Kees' patch is better, please ignore this one.

Oh! I didn't get CCed so I didn't know you'd sent this. :)

Thanks for taking the initiative on this, though! (But, yes,
initialization order matters.)
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index a5bbbd44531f..e23f06f58234 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -572,7 +572,7 @@  struct linereq {
 	DECLARE_KFIFO_PTR(events, struct gpio_v2_line_event);
 	atomic_t seqno;
 	struct mutex config_mutex;
-	struct line lines[];
+	struct line lines[] __counted_by(num_lines);
 };
 
 #define GPIO_V2_LINE_BIAS_FLAGS \