[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240620175703.605111-21-yury.norov@gmail.com>
Date: Thu, 20 Jun 2024 10:56:43 -0700
From: Yury Norov <yury.norov@...il.com>
To: linux-kernel@...r.kernel.org,
Hans Verkuil <hverkuil@...all.nl>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
linux-media@...r.kernel.org
Cc: Yury Norov <yury.norov@...il.com>,
Alexey Klimov <alexey.klimov@...aro.org>,
Bart Van Assche <bvanassche@....org>,
Jan Kara <jack@...e.cz>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Matthew Wilcox <willy@...radead.org>,
Mirsad Todorovac <mirsad.todorovac@....unizg.hr>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Sergey Shtylyov <s.shtylyov@....ru>,
Hans Verkuil <hverkuil-cisco@...all.nl>
Subject: [PATCH v4 20/40] media: radio-shark: optimize the driver by using atomic find_bit() API
Despite that it's only 2- or 3-bit maps, convert for-loop followed by
test_bit() to for_each_test_and_clear_bit() as it makes the code cleaner.
Signed-off-by: Yury Norov <yury.norov@...il.com>
Acked-by: Hans Verkuil <hverkuil-cisco@...all.nl>
---
drivers/media/radio/radio-shark.c | 6 ++----
drivers/media/radio/radio-shark2.c | 6 ++----
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
index 127a3be0e0f0..c7e5c08d034a 100644
--- a/drivers/media/radio/radio-shark.c
+++ b/drivers/media/radio/radio-shark.c
@@ -21,6 +21,7 @@
* GNU General Public License for more details.
*/
+#include <linux/find_atomic.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/leds.h>
@@ -158,10 +159,7 @@ static void shark_led_work(struct work_struct *work)
container_of(work, struct shark_device, led_work);
int i, res, brightness, actual_len;
- for (i = 0; i < 3; i++) {
- if (!test_and_clear_bit(i, &shark->brightness_new))
- continue;
-
+ for_each_test_and_clear_bit(i, &shark->brightness_new, 3) {
brightness = atomic_read(&shark->brightness[i]);
memset(shark->transfer_buffer, 0, TB_LEN);
if (i != RED_LED) {
diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
index e3e6aa87fe08..d897a3e6fcb0 100644
--- a/drivers/media/radio/radio-shark2.c
+++ b/drivers/media/radio/radio-shark2.c
@@ -21,6 +21,7 @@
* GNU General Public License for more details.
*/
+#include <linux/find_atomic.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/leds.h>
@@ -145,10 +146,7 @@ static void shark_led_work(struct work_struct *work)
container_of(work, struct shark_device, led_work);
int i, res, brightness, actual_len;
- for (i = 0; i < 2; i++) {
- if (!test_and_clear_bit(i, &shark->brightness_new))
- continue;
-
+ for_each_test_and_clear_bit(i, &shark->brightness_new, 2) {
brightness = atomic_read(&shark->brightness[i]);
memset(shark->transfer_buffer, 0, TB_LEN);
shark->transfer_buffer[0] = 0x83 + i;
--
2.43.0
Powered by blists - more mailing lists