lkml.org 
[lkml]   [2022]   [Jun]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/2] Input: usbtouchscreen - suppress empty array warnings
On Wed, Jun 22, 2022 at 04:22:08PM -0700, Dmitry Torokhov wrote:
> Hi Johan,
>
> On Mon, Jun 20, 2022 at 10:46:27AM +0200, Johan Hovold wrote:
> > When compile-testing the USB touchscreen driver without enabling any of
> > the device type options the usbtouch_dev_info array ends up being empty,
> > something which triggers compiler warning with -Warray-bounds
> > (gcc-11.3.0).
> >
> > drivers/input/touchscreen/usbtouchscreen.c: In function 'usbtouch_probe':
> > drivers/input/touchscreen/usbtouchscreen.c:1668:16:warning: array subscript <unknown> is outside array bounds of 'struct usbtouch_device_info[0]' [-Warray-bounds]
> > 1668 | type = &usbtouch_dev_info[id->driver_info];
> >
> > Suppress the warnings by making sure that the array is always non-empty.
>
> Does it still warn if you add a check for type, something like
>
> if (type >= ARRAY_SIZE(usbtouch_device_info))
> return -ENODEV;
>
> ?

It seems

if (id->driver_info >= ARRAY_SIZE(usbtouch_dev_info))
return -ENODEV;

indeed does the trick. I'll send a v2.

Johan

\
 
 \ /
  Last update: 2022-06-23 07:54    [W:0.055 / U:0.856 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site