iio: trigger: Remove redundant conditionals
PATCH 1/1 iio: trigger: Remove redundant conditionals
Checks for null initially and return early.
So there is no need to check for null later.
--- drivers/iio/industrialio-trigger.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/iio/industrialio-trigger.c +8 -12
@@ -453,36 +453,32 @@ static ssize_t current_trigger_store(struct device *dev, } trig =iio_trigger_acquire_by_name (buf); -if (oldtrig == trig) { +if (!trig || trig == oldtrig) { ret = len; goto out_trigger_put; } - -if (trig && indio_dev->info->validate_trigger) { +if (indio_dev->info->validate_trigger) { ret = indio_dev->info->validate_trigger (indio_dev, trig);if (ret) goto out_trigger_put; } - -if (trig && trig->ops && trig->ops->validate_device) { +if (trig->ops && trig->ops->validate_device) { ret = trig->ops->validate_device (trig, indio_dev);if (ret) goto out_trigger_put; } - indio_dev->trig = trig; -if (oldtrig) {if (indio_dev->modes &INDIO_EVENT_TRIGGERED )iio_trigger_detach_poll_func (oldtrig, indio_dev->pollfunc_event);iio_trigger_put (oldtrig); } -if (indio_dev->trig) { -if (indio_dev->modes &INDIO_EVENT_TRIGGERED ) -iio_trigger_attach_poll_func (indio_dev->trig, - indio_dev->pollfunc_event); - } +if (indio_dev->modes &INDIO_EVENT_TRIGGERED ) +iio_trigger_attach_poll_func (trig, + indio_dev->pollfunc_event); + + indio_dev->trig = trig;return len;
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerQuoted 4 lines · On Sun, 4 May 2025 03:56:50 +0900 Gyeyoung Baek <[email protected]> wrote:
Checks for null initially and return early.
So there is no need to check for null later.Signed-off-by Gyeyoung Baek <[email protected]>
So the key thing here is what does this path mean. trig == NULL means we are clearing the current trigger. The snag is you just jumped over the code that removes the old trigger or sets indio_dev->trig = NULL.
So I think the new version you have here is broken.
For changes like this it is fairly easy to test them using the dummy driver. Please make sure to do so and make sure you trigger all paths. Here that would be.
No trigger -> trigger 1
trigger 1 -> trigger 2
trigger 2 -> no trigger
Quoted 23 lines
--- drivers/iio/industrialio-trigger.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)drivers/iio/industrialio-trigger.c +2
-3@@ -453,36 +453,32 @@ static ssize_t current_trigger_store(struct device *dev, } trig =iio_trigger_acquire_by_name (buf); -if (oldtrig == trig) { +if (!trig || trig == oldtrig) { ret = len; goto out_trigger_put; } - -if (trig && indio_dev->info->validate_trigger) { +if (indio_dev->info->validate_trigger) { ret = indio_dev->info->validate_trigger (indio_dev, trig);if (ret) goto out_trigger_put;
drivers/iio/industrialio-trigger.c static ssize_t current_trigger_store(struct device *dev, · line 473
Quoted 10 lines
drivers/iio/industrialio-trigger.c +1
-3} - -if (trig && trig->ops && trig->ops->validate_device) { +if (trig->ops && trig->ops->validate_device) { ret = trig->ops->validate_device (trig, indio_dev);if (ret) goto out_trigger_put; } - indio_dev->trig = trig;
This and...
drivers/iio/industrialio-trigger.c static ssize_t current_trigger_store(struct device *dev, · line 471
Quoted 2 lines
drivers/iio/industrialio-trigger.c +0
-1-if (oldtrig) {
this need to run if oldtrig was set and trig is not.
Quoted 18 lines
drivers/iio/industrialio-trigger.c +5
-5if (indio_dev->modes &INDIO_EVENT_TRIGGERED )iio_trigger_detach_poll_func (oldtrig, indio_dev->pollfunc_event);iio_trigger_put (oldtrig); } -if (indio_dev->trig) { -if (indio_dev->modes &INDIO_EVENT_TRIGGERED ) -iio_trigger_attach_poll_func (indio_dev->trig, - indio_dev->pollfunc_event); - } +if (indio_dev->modes &INDIO_EVENT_TRIGGERED ) +iio_trigger_attach_poll_func (trig, + indio_dev->pollfunc_event); + + indio_dev->trig = trig;return len;
Quoted 16 lines · Jonathan Cameron
Quoted 4 lines · On Sun, 4 May 2025 03:56:50 +0900 Gyeyoung Baek <[email protected]> wrote:
Checks for null initially and return early.
So there is no need to check for null later.Signed-off-by Gyeyoung Baek <[email protected]>So the key thing here is what does this path mean. trig == NULL means we are clearing the current trigger. The snag is you just jumped over the code that removes the old trigger or sets
indio_dev->trig= NULL.So I think the new version you have here is broken.
Quoted 8 lines
For changes like this it is fairly easy to test them using the dummy driver. Please make sure to do so and make sure you trigger all paths. Here that would be.
No trigger -> trigger 1
trigger 1 -> trigger 2
trigger 2 -> no trigger
Apologies, I misunderstood the logic.
I’ll make sure to verify it thoroughly before sending a patch. Thanks for the review.
--
Regards,
Gyeyoung