Skip to content

Commit ef2d71d

Browse files
committed
iio: triggers: Make trigger ops structure explicitly non optional.
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>
1 parent 8ac8aa6 commit ef2d71d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎drivers/iio/industrialio-trigger.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ int iio_trigger_register(struct iio_trigger *trig_info)
6868
{
6969
int ret;
7070

71+
/* trig_info->ops is required for the module member */
72+
if (!trig_info->ops)
73+
return -EINVAL;
74+
7175
trig_info->id = ida_simple_get(&iio_trigger_ida, 0, 0, GFP_KERNEL);
7276
if (trig_info->id < 0)
7377
return trig_info->id;
@@ -164,8 +168,7 @@ EXPORT_SYMBOL(iio_trigger_poll_chained);
164168

165169
void iio_trigger_notify_done(struct iio_trigger *trig)
166170
{
167-
if (atomic_dec_and_test(&trig->use_count) && trig->ops &&
168-
trig->ops->try_reenable)
171+
if (atomic_dec_and_test(&trig->use_count) && trig->ops->try_reenable)
169172
if (trig->ops->try_reenable(trig))
170173
/* Missed an interrupt so launch new poll now */
171174
iio_trigger_poll(trig);
@@ -219,7 +222,7 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
219222
return ret;
220223
}
221224

222-
if (trig->ops && trig->ops->set_trigger_state && notinuse) {
225+
if (trig->ops->set_trigger_state && notinuse) {
223226
ret = trig->ops->set_trigger_state(trig, true);
224227
if (ret < 0)
225228
module_put(pf->indio_dev->info->driver_module);
@@ -236,7 +239,7 @@ static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
236239
= (bitmap_weight(trig->pool,
237240
CONFIG_IIO_CONSUMERS_PER_TRIGGER)
238241
== 1);
239-
if (trig->ops && trig->ops->set_trigger_state && no_other_users) {
242+
if (trig->ops->set_trigger_state && no_other_users) {
240243
ret = trig->ops->set_trigger_state(trig, false);
241244
if (ret)
242245
return ret;
@@ -358,7 +361,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
358361
return ret;
359362
}
360363

361-
if (trig && trig->ops && trig->ops->validate_device) {
364+
if (trig && trig->ops->validate_device) {
362365
ret = trig->ops->validate_device(trig, indio_dev);
363366
if (ret)
364367
return ret;

0 commit comments

Comments
 (0)