Skip to contentSkip to conversation

iio: Remove assignment to pf->timestamp by using elvis

PATCH In review Vasileios Amoiridis 2 participants 3 messages Sep 22, 2024 – Sep 28, 2024 IIO

lore
Share & tools
lore
#0 lore raw

cover iio: Remove assignment to pf->timestamp by using elvis

Instead of checking the value of the pf->timestamp and determining to assign to it a new one or not, use the elvis operator to save some lines and to simplify it.

Vasileios Amoiridis (1):
iio: acpi-als: Use elvis operator to simplify if statement

 drivers/iio/light/acpi-als.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

base-commit: 8bea3878a1511bceadc2fbf284b00bcc5a2ef28d

Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 iio: acpi-als: Use elvis operator to simplify if statement

By using the elvis operator here, we can get rid of the if statement and simplify the code.

---
 drivers/iio/light/acpi-als.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/light/acpi-als.c +2 -4
index 2d91caf24dd0..cea3499c3af3 100644
@@ -171,10 +171,8 @@ static irqreturn_t acpi_als_trigger_handler(int irq, void *p)
 	 *
 	 * If the timestamp was actually 0, the timestamp is set one more time.
 	 */
-	if (!pf->timestamp)
-		pf->timestamp = iio_get_time_ns(indio_dev);
-
-	iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp);
+	iio_push_to_buffers_with_timestamp(indio_dev, buffer,
+					   pf->timestamp ?: iio_get_time_ns(indio_dev));
 out:
 	mutex_unlock(&als->lock);
 	iio_trigger_notify_done(indio_dev->trig);
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH v1 1/1] iio: acpi-als: Use elvis operator to simplify if statement

Quoted 13 lines · On Sun, 22 Sep 2024 18:03:04 +0200 Vasileios Amoiridis…

By using the elvis operator here, we can get rid of the if statement and simplify the code.

---
 drivers/iio/light/acpi-als.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/light/acpi-als.c +0 -0
index 2d91caf24dd0..cea3499c3af3 100644

drivers/iio/light/acpi-als.c static irqreturn_t acpi_als_trigger_handler(int irq, void *p) · line 175

Quoted 9 lines
drivers/iio/light/acpi-als.c +2 -4
@@ -171,10 +171,8 @@ static irqreturn_t acpi_als_trigger_handler(int irq, void *p)
 	 *
 	 * If the timestamp was actually 0, the timestamp is set one more time.
 	 */
-	if (!pf->timestamp)
-		pf->timestamp = iio_get_time_ns(indio_dev);
-
-	iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp);
+	iio_push_to_buffers_with_timestamp(indio_dev, buffer,
+					   pf->timestamp ?: iio_get_time_ns(indio_dev));

Hi Vasileios,

If the original code had looked like this I wouldn't mind, but
I actually prefer the original from a readability point of view, particularly as it keeps the comment and code more closely coupled than after the patch.

So to my eyes this isn't an improvement.

Thanks

Jonathan

Quoted 3 lines
drivers/iio/light/acpi-als.c +0 -0
 out:
 	mutex_unlock(&als->lock);
 	iio_trigger_notify_done(indio_dev->trig);