Skip to content

Commit

Permalink
iio: triggers: Make trigger ops structure explicitly non optional.
Browse files Browse the repository at this point in the history
This structure has not been optional for a long time (if ever) but the
code implies that it is.  As we then use it later in a fashion that would
crash if it was in fact NULL, it's inconsistent so fix it up by removing
unnecessary checks.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
  • Loading branch information
Jonathan Cameron committed May 29, 2016
1 parent 8ac8aa6 commit ef2d71d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions drivers/iio/industrialio-trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ int iio_trigger_register(struct iio_trigger *trig_info)
{
int ret;

/* trig_info->ops is required for the module member */
if (!trig_info->ops)
return -EINVAL;

trig_info->id = ida_simple_get(&iio_trigger_ida, 0, 0, GFP_KERNEL);
if (trig_info->id < 0)
return trig_info->id;
Expand Down Expand Up @@ -164,8 +168,7 @@ EXPORT_SYMBOL(iio_trigger_poll_chained);

void iio_trigger_notify_done(struct iio_trigger *trig)
{
if (atomic_dec_and_test(&trig->use_count) && trig->ops &&
trig->ops->try_reenable)
if (atomic_dec_and_test(&trig->use_count) && trig->ops->try_reenable)
if (trig->ops->try_reenable(trig))
/* Missed an interrupt so launch new poll now */
iio_trigger_poll(trig);
Expand Down Expand Up @@ -219,7 +222,7 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
return ret;
}

if (trig->ops && trig->ops->set_trigger_state && notinuse) {
if (trig->ops->set_trigger_state && notinuse) {
ret = trig->ops->set_trigger_state(trig, true);
if (ret < 0)
module_put(pf->indio_dev->info->driver_module);
Expand All @@ -236,7 +239,7 @@ static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
= (bitmap_weight(trig->pool,
CONFIG_IIO_CONSUMERS_PER_TRIGGER)
== 1);
if (trig->ops && trig->ops->set_trigger_state && no_other_users) {
if (trig->ops->set_trigger_state && no_other_users) {
ret = trig->ops->set_trigger_state(trig, false);
if (ret)
return ret;
Expand Down Expand Up @@ -358,7 +361,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
return ret;
}

if (trig && trig->ops && trig->ops->validate_device) {
if (trig && trig->ops->validate_device) {
ret = trig->ops->validate_device(trig, indio_dev);
if (ret)
return ret;
Expand Down

0 comments on commit ef2d71d

Please sign in to comment.