From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Yury Norov <yury.norov@gmail.com>,
linux-media@vger.kernel.org
Cc: Alexey Klimov <alexey.klimov@linaro.org>,
Bart Van Assche <bvanassche@acm.org>, Jan Kara <jack@suse.cz>,
Linus Torvalds <torvalds@linux-foundation.org>,
Matthew Wilcox <willy@infradead.org>,
Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Sergey Shtylyov <s.shtylyov@omp.ru>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>
Subject: [PATCH v4 26/40] media: em28xx: cx231xx: optimize drivers by using find_and_set_bit()
Date: Thu, 20 Jun 2024 10:56:49 -0700 [thread overview]
Message-ID: <20240620175703.605111-27-yury.norov@gmail.com> (raw)
In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com>
Functions in the media/usb drivers opencode find_and_set_bit(). Simplify
them by using the function.
Signed-off-by: Yury Norov <yury.norov@gmail.com>
Acked-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
drivers/media/usb/cx231xx/cx231xx-cards.c | 17 +++++-----
drivers/media/usb/em28xx/em28xx-cards.c | 38 ++++++++++-------------
2 files changed, 23 insertions(+), 32 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 92efe6c1f47b..8bdfbc4454f1 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -9,6 +9,7 @@
*/
#include "cx231xx.h"
+#include <linux/find_atomic.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
@@ -1708,16 +1709,12 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
return -ENODEV;
/* Check to see next free device and mark as used */
- do {
- nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
- if (nr >= CX231XX_MAXBOARDS) {
- /* No free device slots */
- dev_err(d,
- "Supports only %i devices.\n",
- CX231XX_MAXBOARDS);
- return -ENOMEM;
- }
- } while (test_and_set_bit(nr, &cx231xx_devused));
+ nr = find_and_set_bit(&cx231xx_devused, CX231XX_MAXBOARDS);
+ if (nr >= CX231XX_MAXBOARDS) {
+ /* No free device slots */
+ dev_err(d, "Supports only %i devices.\n", CX231XX_MAXBOARDS);
+ return -ENOMEM;
+ }
udev = usb_get_dev(interface_to_usbdev(interface));
diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
index bae76023cf71..59e6d7f894ad 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -11,6 +11,7 @@
#include "em28xx.h"
+#include <linux/find_atomic.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
@@ -3684,17 +3685,14 @@ static int em28xx_duplicate_dev(struct em28xx *dev)
return -ENOMEM;
}
/* Check to see next free device and mark as used */
- do {
- nr = find_first_zero_bit(em28xx_devused, EM28XX_MAXBOARDS);
- if (nr >= EM28XX_MAXBOARDS) {
- /* No free device slots */
- dev_warn(&dev->intf->dev, ": Supports only %i em28xx boards.\n",
- EM28XX_MAXBOARDS);
- kfree(sec_dev);
- dev->dev_next = NULL;
- return -ENOMEM;
- }
- } while (test_and_set_bit(nr, em28xx_devused));
+ nr = find_and_set_bit(em28xx_devused, EM28XX_MAXBOARDS);
+ if (nr >= EM28XX_MAXBOARDS) {
+ /* No free device slots */
+ dev_warn(&dev->intf->dev, ": Supports only %i em28xx boards.\n", EM28XX_MAXBOARDS);
+ kfree(sec_dev);
+ dev->dev_next = NULL;
+ return -ENOMEM;
+ }
sec_dev->devno = nr;
snprintf(sec_dev->name, 28, "em28xx #%d", nr);
sec_dev->dev_next = NULL;
@@ -3827,17 +3825,13 @@ static int em28xx_usb_probe(struct usb_interface *intf,
udev = usb_get_dev(interface_to_usbdev(intf));
/* Check to see next free device and mark as used */
- do {
- nr = find_first_zero_bit(em28xx_devused, EM28XX_MAXBOARDS);
- if (nr >= EM28XX_MAXBOARDS) {
- /* No free device slots */
- dev_err(&intf->dev,
- "Driver supports up to %i em28xx boards.\n",
- EM28XX_MAXBOARDS);
- retval = -ENOMEM;
- goto err_no_slot;
- }
- } while (test_and_set_bit(nr, em28xx_devused));
+ nr = find_and_set_bit(em28xx_devused, EM28XX_MAXBOARDS);
+ if (nr >= EM28XX_MAXBOARDS) {
+ /* No free device slots */
+ dev_err(&intf->dev, "Driver supports up to %i em28xx boards.\n", EM28XX_MAXBOARDS);
+ retval = -ENOMEM;
+ goto err_no_slot;
+ }
/* Don't register audio interfaces */
if (intf->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) {
--
2.43.0
next prev parent reply other threads:[~2024-06-20 17:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-20 17:56 [PATCH v4 00/40] lib/find: add atomic find_bit() primitives Yury Norov
2024-06-20 17:56 ` [PATCH v4 01/40] " Yury Norov
2024-06-20 17:56 ` [PATCH v4 02/40] lib/find: add test for atomic find_bit() ops Yury Norov
2024-06-20 17:56 ` [PATCH v4 20/40] media: radio-shark: optimize the driver by using atomic find_bit() API Yury Norov
2024-06-20 17:56 ` Yury Norov [this message]
2024-06-20 18:00 ` [PATCH v4 00/40] lib/find: add atomic find_bit() primitives Linus Torvalds
2024-06-20 18:32 ` Yury Norov
2024-06-20 19:26 ` Linus Torvalds
2024-06-20 20:20 ` Yury Norov
2024-06-20 20:32 ` Linus Torvalds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240620175703.605111-27-yury.norov@gmail.com \
--to=yury.norov@gmail.com \
--cc=alexey.klimov@linaro.org \
--cc=bvanassche@acm.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mchehab@kernel.org \
--cc=mirsad.todorovac@alu.unizg.hr \
--cc=s.shtylyov@omp.ru \
--cc=torvalds@linux-foundation.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox