public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: trigger: Remove redundant conditionals
@ 2025-05-03 18:56 Gyeyoung Baek
  2025-05-04 14:30 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Gyeyoung Baek @ 2025-05-03 18:56 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
  Cc: Gyeyoung Baek, linux-iio, linux-kernel

Checks for null initially and return early.
So there is no need to check for null later.

Signed-off-by: Gyeyoung Baek <gye976@gmail.com>
---
 drivers/iio/industrialio-trigger.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 54416a384232..6abf2a450202 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -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;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-05  8:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-03 18:56 [PATCH] iio: trigger: Remove redundant conditionals Gyeyoung Baek
2025-05-04 14:30 ` Jonathan Cameron
2025-05-05  8:29   ` Gyeyoung Baek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox