[PATCH v4 20/40] media: radio-shark: optimize the driver by using atomic find_bit() API

Yury Norov
2024-06-20T17:58:06Z

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@gmail.com>
Acked-by: Hans Verkuil <hverkuil-cisco@xs4all.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