From: Yury Norov <yury.norov@gmail.com>
To: linux-kernel@vger.kernel.org, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>, Daniel Mack <zonque@gmail.com>,
Cezary Rojewski <cezary.rojewski@intel.com>,
Kai Vehmanen <kai.vehmanen@linux.intel.com>,
Yury Norov <yury.norov@gmail.com>,
Kees Cook <keescook@chromium.org>,
linux-sound@vger.kernel.org, alsa-devel@alsa-project.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>, Takashi Iwai <tiwai@suse.de>
Subject: [PATCH v4 30/40] ALSA: use atomic find_bit() functions where applicable
Date: Thu, 20 Jun 2024 10:56:53 -0700 [thread overview]
Message-ID: <20240620175703.605111-31-yury.norov@gmail.com> (raw)
In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com>
ALSA code tests each bit in bitmaps in a for-loop. Switch it to
using dedicated atomic find_bit() API.
Signed-off-by: Yury Norov <yury.norov@gmail.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
---
sound/pci/hda/hda_codec.c | 8 ++++----
sound/usb/caiaq/audio.c | 14 ++++++--------
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 325e8f0b99a8..7201afa82990 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -7,6 +7,7 @@
#include <linux/init.h>
#include <linux/delay.h>
+#include <linux/find_atomic.h>
#include <linux/slab.h>
#include <linux/mutex.h>
#include <linux/module.h>
@@ -3263,10 +3264,9 @@ static int get_empty_pcm_device(struct hda_bus *bus, unsigned int type)
#ifdef CONFIG_SND_DYNAMIC_MINORS
/* non-fixed slots starting from 10 */
- for (i = 10; i < 32; i++) {
- if (!test_and_set_bit(i, bus->pcm_dev_bits))
- return i;
- }
+ i = find_and_set_next_bit(bus->pcm_dev_bits, 32, 10);
+ if (i < 32)
+ return i;
#endif
dev_warn(bus->card->dev, "Too many %s devices\n",
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index 4981753652a7..93ecd5cfcb7d 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -4,6 +4,7 @@
*/
#include <linux/device.h>
+#include <linux/find_atomic.h>
#include <linux/spinlock.h>
#include <linux/slab.h>
#include <linux/init.h>
@@ -610,7 +611,7 @@ static void read_completed(struct urb *urb)
struct snd_usb_caiaq_cb_info *info = urb->context;
struct snd_usb_caiaqdev *cdev;
struct device *dev;
- struct urb *out = NULL;
+ struct urb *out;
int i, frame, len, send_it = 0, outframe = 0;
unsigned long flags;
size_t offset = 0;
@@ -625,17 +626,14 @@ static void read_completed(struct urb *urb)
return;
/* find an unused output urb that is unused */
- for (i = 0; i < N_URBS; i++)
- if (test_and_set_bit(i, &cdev->outurb_active_mask) == 0) {
- out = cdev->data_urbs_out[i];
- break;
- }
-
- if (!out) {
+ i = find_and_set_bit(&cdev->outurb_active_mask, N_URBS);
+ if (i >= N_URBS) {
dev_err(dev, "Unable to find an output urb to use\n");
goto requeue;
}
+ out = cdev->data_urbs_out[i];
+
/* read the recently received packet and send back one which has
* the same layout */
for (frame = 0; frame < FRAMES_PER_URB; frame++) {
--
2.43.0
next prev parent reply other threads:[~2024-06-20 17:58 UTC|newest]
Thread overview: 9+ 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 ` 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-31-yury.norov@gmail.com \
--to=yury.norov@gmail.com \
--cc=alexey.klimov@linaro.org \
--cc=alsa-devel@alsa-project.org \
--cc=bvanassche@acm.org \
--cc=cezary.rojewski@intel.com \
--cc=jack@suse.cz \
--cc=kai.vehmanen@linux.intel.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mirsad.todorovac@alu.unizg.hr \
--cc=perex@perex.cz \
--cc=s.shtylyov@omp.ru \
--cc=tiwai@suse.com \
--cc=tiwai@suse.de \
--cc=torvalds@linux-foundation.org \
--cc=willy@infradead.org \
--cc=zonque@gmail.com \
/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