mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Shenghao Ding <shenghao-ding@ti.com>, Kevin Lu <kevin-lu@ti.com>,
	Baojun Xu <baojun.xu@ti.com>, Sen Wang <sen@ti.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Clemens Ladisch <clemens@ladisch.de>, Peng Fan <peng.fan@nxp.com>,
	Zhao Dongdong <zhaodongdong@kylinos.cn>,
	Arun Raghavan <arunr@valvesoftware.com>,
	Fu Hao <fuhao@open-hieco.net>,
	Joakim Zhang <joakim.zhang@cixtech.com>
Cc: linux-kernel@vger.kernel.org, Takashi Iwai <tiwai@suse.de>,
	linux-sound@vger.kernel.org
Subject: [PATCH] ALSA/ASoC: use assign_bit() where applicable
Date: Fri, 18 Sep 2026 22:15:20 +0800	[thread overview]
Message-ID: <20260918141532.3022761-1-peng.fan@oss.nxp.com> (raw)

From: Peng Fan <peng.fan@nxp.com>

Convert open-coded if/else with set_bit/clear_bit and their
non-atomic __set_bit/__clear_bit variants to the assign_bit/__assign_bit
API.

Done with Coccinelle semantic patch:
    // set_bit -> clear_bit => assign_bit

    @@
    expression cond, bit, addr;
    @@

    -if (cond)
    -        set_bit(bit, addr);
    -else
    -        clear_bit(bit, addr);
    +assign_bit(bit, addr, cond);

    // clear_bit -> set_bit => assign_bit

    @@
    expression cond, bit, addr;
    @@

    -if (cond)
    -        clear_bit(bit, addr);
    -else
    -        set_bit(bit, addr);
    +assign_bit(bit, addr, !cond);

    // __set_bit -> __clear_bit => __assign_bit

    @@
    expression cond, bit, addr;
    @@

    -if (cond)
    -        __set_bit(bit, addr);
    -else
    -        __clear_bit(bit, addr);
    +__assign_bit(bit, addr, cond);

    // __clear_bit -> __set_bit => __assign_bit

    @@
    expression cond, bit, addr;
    @@

    -if (cond)
    -        __clear_bit(bit, addr);
    -else
    -        __set_bit(bit, addr);
    +__assign_bit(bit, addr, !cond);

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 sound/drivers/serial-generic.c | 10 ++--------
 sound/hda/core/component.c     |  5 +----
 sound/hda/core/controller.c    |  5 +----
 sound/soc/codecs/tas675x.c     | 10 ++--------
 sound/usb/midi.c               |  5 +----
 5 files changed, 7 insertions(+), 28 deletions(-)

diff --git a/sound/drivers/serial-generic.c b/sound/drivers/serial-generic.c
index 766206c6ca75..8ba5e35af4a1 100644
--- a/sound/drivers/serial-generic.c
+++ b/sound/drivers/serial-generic.c
@@ -183,10 +183,7 @@ static void snd_serial_generic_input_trigger(struct snd_rawmidi_substream *subst
 {
 	struct snd_serial_generic *drvdata = substream->rmidi->card->private_data;
 
-	if (up)
-		set_bit(SERIAL_MODE_INPUT_TRIGGERED, &drvdata->filemode);
-	else
-		clear_bit(SERIAL_MODE_INPUT_TRIGGERED, &drvdata->filemode);
+	assign_bit(SERIAL_MODE_INPUT_TRIGGERED, &drvdata->filemode, up);
 }
 
 static int snd_serial_generic_output_open(struct snd_rawmidi_substream *substream)
@@ -230,10 +227,7 @@ static void snd_serial_generic_output_trigger(struct snd_rawmidi_substream *subs
 {
 	struct snd_serial_generic *drvdata = substream->rmidi->card->private_data;
 
-	if (up)
-		set_bit(SERIAL_MODE_OUTPUT_TRIGGERED, &drvdata->filemode);
-	else
-		clear_bit(SERIAL_MODE_OUTPUT_TRIGGERED, &drvdata->filemode);
+	assign_bit(SERIAL_MODE_OUTPUT_TRIGGERED, &drvdata->filemode, up);
 
 	if (up)
 		snd_serial_generic_tx_wakeup(drvdata);
diff --git a/sound/hda/core/component.c b/sound/hda/core/component.c
index 04755903880e..83b31186b027 100644
--- a/sound/hda/core/component.c
+++ b/sound/hda/core/component.c
@@ -70,10 +70,7 @@ void snd_hdac_display_power(struct hdac_bus *bus, unsigned int idx, bool enable)
 	dev_dbg(bus->dev, "display power %s\n", str_enable_disable(enable));
 
 	guard(mutex)(&bus->lock);
-	if (enable)
-		set_bit(idx, &bus->display_power_status);
-	else
-		clear_bit(idx, &bus->display_power_status);
+	assign_bit(idx, &bus->display_power_status, enable);
 
 	if (!acomp || !acomp->ops)
 		return;
diff --git a/sound/hda/core/controller.c b/sound/hda/core/controller.c
index 78855ac357c6..e8d40c24ed00 100644
--- a/sound/hda/core/controller.c
+++ b/sound/hda/core/controller.c
@@ -781,9 +781,6 @@ EXPORT_SYMBOL_GPL(snd_hdac_bus_free_stream_pages);
  */
 void snd_hdac_bus_link_power(struct hdac_device *codec, bool enable)
 {
-	if (enable)
-		set_bit(codec->addr, &codec->bus->codec_powered);
-	else
-		clear_bit(codec->addr, &codec->bus->codec_powered);
+	assign_bit(codec->addr, &codec->bus->codec_powered, enable);
 }
 EXPORT_SYMBOL_GPL(snd_hdac_bus_link_power);
diff --git a/sound/soc/codecs/tas675x.c b/sound/soc/codecs/tas675x.c
index 404706b62156..82eeaceb1dac 100644
--- a/sound/soc/codecs/tas675x.c
+++ b/sound/soc/codecs/tas675x.c
@@ -1379,10 +1379,7 @@ static int tas675x_mute_stream(struct snd_soc_dai *dai, int mute, int direction)
 	int ret;
 
 	if (direction == SNDRV_PCM_STREAM_CAPTURE) {
-		if (mute)
-			clear_bit(dai->id, &tas->active_capture_dais);
-		else
-			set_bit(dai->id, &tas->active_capture_dais);
+		assign_bit(dai->id, &tas->active_capture_dais, !mute);
 		return 0;
 	}
 
@@ -1391,10 +1388,7 @@ static int tas675x_mute_stream(struct snd_soc_dai *dai, int mute, int direction)
 	 * The TAS675x has two playback DAIs (main audio and LLP).
 	 * Only transition to SLEEP when ALL are muted.
 	 */
-	if (mute)
-		clear_bit(dai->id, &tas->active_playback_dais);
-	else
-		set_bit(dai->id, &tas->active_playback_dais);
+	assign_bit(dai->id, &tas->active_playback_dais, !mute);
 
 	/* Last playback stream */
 	if (mute && !READ_ONCE(tas->active_playback_dais)) {
diff --git a/sound/usb/midi.c b/sound/usb/midi.c
index 353217b3629b..0480a9b89e8f 100644
--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -1282,10 +1282,7 @@ static void snd_usbmidi_input_trigger(struct snd_rawmidi_substream *substream,
 {
 	struct snd_usb_midi *umidi = substream->rmidi->private_data;
 
-	if (up)
-		set_bit(substream->number, &umidi->input_triggered);
-	else
-		clear_bit(substream->number, &umidi->input_triggered);
+	assign_bit(substream->number, &umidi->input_triggered, up);
 }
 
 static const struct snd_rawmidi_ops snd_usbmidi_output_ops = {
-- 
2.51.0


             reply	other threads:[~2026-09-18 14:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 14:15 Peng Fan (OSS) [this message]
2026-09-18 22:14 ` Mark Brown
2026-09-28 11:09 ` Takashi Iwai

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=20260918141532.3022761-1-peng.fan@oss.nxp.com \
    --to=peng.fan@oss.nxp.com \
    --cc=arunr@valvesoftware.com \
    --cc=baojun.xu@ti.com \
    --cc=broonie@kernel.org \
    --cc=clemens@ladisch.de \
    --cc=fuhao@open-hieco.net \
    --cc=joakim.zhang@cixtech.com \
    --cc=kevin-lu@ti.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=peng.fan@nxp.com \
    --cc=perex@perex.cz \
    --cc=sen@ti.com \
    --cc=shenghao-ding@ti.com \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    --cc=zhaodongdong@kylinos.cn \
    /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

all inboxes | Powered by JetHome®