diff mbox series

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

Message ID 20240922160304.520613-2-vassilisamir@gmail.com (mailing list archive)
State Rejected
Headers show
Series iio: Remove assignment to pf->timestamp by using elvis | expand

Commit Message

Vasileios Amoiridis Sept. 22, 2024, 4:03 p.m. UTC
By using the elvis operator here, we can get rid of the if statement
and simplify the code.

Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
---
 drivers/iio/light/acpi-als.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Jonathan Cameron Sept. 28, 2024, 2:58 p.m. UTC | #1
On Sun, 22 Sep 2024 18:03:04 +0200
Vasileios Amoiridis <vassilisamir@gmail.com> wrote:

> By using the elvis operator here, we can get rid of the if statement
> and simplify the code.
> 
> Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
> ---
>  drivers/iio/light/acpi-als.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
> index 2d91caf24dd0..cea3499c3af3 100644
> --- a/drivers/iio/light/acpi-als.c
> +++ b/drivers/iio/light/acpi-als.c
> @@ -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

>  out:
>  	mutex_unlock(&als->lock);
>  	iio_trigger_notify_done(indio_dev->trig);
diff mbox series

Patch

diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
index 2d91caf24dd0..cea3499c3af3 100644
--- a/drivers/iio/light/acpi-als.c
+++ b/drivers/iio/light/acpi-als.c
@@ -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);