From nobody Wed Dec 17 08:29:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90395C4332F for ; Tue, 12 Dec 2023 02:29:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345966AbjLLC3e (ORCPT ); Mon, 11 Dec 2023 21:29:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345813AbjLLC2s (ORCPT ); Mon, 11 Dec 2023 21:28:48 -0500 Received: from mail-yw1-x1129.google.com (mail-yw1-x1129.google.com [IPv6:2607:f8b0:4864:20::1129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3A39EB; Mon, 11 Dec 2023 18:28:42 -0800 (PST) Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-5d7a47d06eeso52156897b3.1; Mon, 11 Dec 2023 18:28:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702348121; x=1702952921; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s1ziCHmUMRjRbO8uC0DQdJSiPRQP/fDCaegFJhzzCaw=; b=Wp1lG46/3S4h92lGr9FmU3vpqbCUWbjNtZfAfZLy1j+FwlaLb4wvIYWG+6axBfmpBi YrQbQTK1VTrruc/nqjLdoYQIG9QcxRxu4aZ66X5YaOzPYfTZogft+qVIeqUg3yEJUZX1 9DnFtHDfPW6hLWLv6gkaxBt6BL0aCDzLyU/v/Q21qMTEou0N36aigSR0X9+NXl1u+Lab YRkjWdEyeDnbGEKcI2wbZz8WvcKh5JTCugM4MwsMpll6XBYsTHyJQb11cSpgTy6Ob6nq 6Nn9HPzwRQvxMKenbUOqQXz1SliC3s9kW+3jLSCPoAIDxahdsvSlTWx/1BiaqRPzkQN9 hMRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702348121; x=1702952921; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s1ziCHmUMRjRbO8uC0DQdJSiPRQP/fDCaegFJhzzCaw=; b=L8WBvz04Dy9BPO01cU1tcxpjXB6vgsQ4o+cJ+6vqEdFQSPlFU6ZthxY50shHIAJYFg W3BVZi2mCeQhPZ73vdvvt+OJ5I2jitNkiyrDVGP7igRevSKWeVVnASZcw4aUOL7aZ28L MbsQ3apEIIa/fmQtVOzKlPUUqba+KXgxMJyxRo9Us67F0LzcaSuX4nuZz6lrRZ13xAxX 34tBlU8mtc5Ic+/ZJwKGnQOtiG8afXGtGTRaHJ77HvuX00d1lzUDDhs3+Uv2Jd2/Eeye Q6ErOyU6rHPj5HQb318fNuFHgKxvdKNxlNS/xJKmzVgHxyL/ssY9VSwYl04jni/rE6iv jV8A== X-Gm-Message-State: AOJu0Yx9lGJyBDBBeHxFQ97df3F8fTbha/zFtYS7agVMTANKfMbAmGr/ gII3WcyG2m/pXy68/1X4ejufa8mjDY2ZDw== X-Google-Smtp-Source: AGHT+IEkj3SrO47EktQbRudrxe7SbWLYCP6nELjcTaeJUHnC5fYO3ykVx8HOtGA5GggcJQHNwWRRGA== X-Received: by 2002:a0d:dbc5:0:b0:5cb:eac7:38aa with SMTP id d188-20020a0ddbc5000000b005cbeac738aamr4593499ywe.35.1702348120890; Mon, 11 Dec 2023 18:28:40 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id u11-20020a0deb0b000000b005af5bb5e840sm3454168ywe.34.2023.12.11.18.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:28:40 -0800 (PST) From: Yury Norov To: linux-kernel@vger.kernel.org, Jaroslav Kysela , Takashi Iwai , Daniel Mack , Cezary Rojewski , Kai Vehmanen , Yury Norov , Kees Cook , linux-sound@vger.kernel.org, alsa-devel@alsa-project.org Cc: Jan Kara , Mirsad Todorovac , Matthew Wilcox , Rasmus Villemoes , Andy Shevchenko , Maxim Kuvyrkov , Alexey Klimov , Bart Van Assche , Sergey Shtylyov , Takashi Iwai Subject: [PATCH v3 32/35] ALSA: use atomic find_bit() functions where applicable Date: Mon, 11 Dec 2023 18:27:46 -0800 Message-Id: <20231212022749.625238-33-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212022749.625238-1-yury.norov@gmail.com> References: <20231212022749.625238-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Acked-by: Takashi Iwai --- sound/pci/hda/hda_codec.c | 7 +++---- sound/usb/caiaq/audio.c | 13 +++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 01718b1fc9a7..29254005f394 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -3275,10 +3275,9 @@ static int get_empty_pcm_device(struct hda_bus *bus,= unsigned int type) =20 #ifdef CONFIG_SND_DYNAMIC_MINORS /* non-fixed slots starting from 10 */ - for (i =3D 10; i < 32; i++) { - if (!test_and_set_bit(i, bus->pcm_dev_bits)) - return i; - } + i =3D find_and_set_next_bit(bus->pcm_dev_bits, 32, 10); + if (i < 32) + return i; #endif =20 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..74dfcf32b439 100644 --- a/sound/usb/caiaq/audio.c +++ b/sound/usb/caiaq/audio.c @@ -610,7 +610,7 @@ static void read_completed(struct urb *urb) struct snd_usb_caiaq_cb_info *info =3D urb->context; struct snd_usb_caiaqdev *cdev; struct device *dev; - struct urb *out =3D NULL; + struct urb *out; int i, frame, len, send_it =3D 0, outframe =3D 0; unsigned long flags; size_t offset =3D 0; @@ -625,17 +625,14 @@ static void read_completed(struct urb *urb) return; =20 /* find an unused output urb that is unused */ - for (i =3D 0; i < N_URBS; i++) - if (test_and_set_bit(i, &cdev->outurb_active_mask) =3D=3D 0) { - out =3D cdev->data_urbs_out[i]; - break; - } - - if (!out) { + i =3D find_and_set_bit(&cdev->outurb_active_mask, N_URBS); + if (i >=3D N_URBS) { dev_err(dev, "Unable to find an output urb to use\n"); goto requeue; } =20 + out =3D cdev->data_urbs_out[i]; + /* read the recently received packet and send back one which has * the same layout */ for (frame =3D 0; frame < FRAMES_PER_URB; frame++) { --=20 2.40.1