Commit 46b24311ccc8b37da9e6e006c6158229a5354268

Authored by Sascha Hauer
Committed by Jonathan Cameron
1 parent a91aff1c09

iio: Fix unitialized use of list

The dev_attr list is initialized in __iio_add_event_config_attrs which
is called only when indio_dev->channels is true. Nevertheless the list
is used unconditionally later in iio_device_register_eventset which
results in a NULL pointer exception. To fix this unconditionally
initialize the list in iio_device_register_eventset.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

Showing 1 changed file with 2 additions and 1 deletions Side-by-side Diff

drivers/iio/industrialio-event.c
... ... @@ -345,7 +345,6 @@
345 345 {
346 346 int j, ret, attrcount = 0;
347 347  
348   - INIT_LIST_HEAD(&indio_dev->event_interface->dev_attr_list);
349 348 /* Dynically created from the channels array */
350 349 for (j = 0; j < indio_dev->num_channels; j++) {
351 350 ret = iio_device_add_event_sysfs(indio_dev,
... ... @@ -395,6 +394,8 @@
395 394 ret = -ENOMEM;
396 395 goto error_ret;
397 396 }
  397 +
  398 + INIT_LIST_HEAD(&indio_dev->event_interface->dev_attr_list);
398 399  
399 400 iio_setup_ev_int(indio_dev->event_interface);
400 401 if (indio_dev->info->event_attrs != NULL) {