Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alan Stern <stern@rowland.harvard.edu>, Bin Liu <b-liu@ti.com>,
	Chen-Yu Tsai <wens@kernel.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	Samuel Holland <samuel@sholland.org>,
	Griffin Kroah-Hartman <griffin@kroah.com>,
	Kuen-Han Tsai <khtsai@google.com>,
	Martin Rys <martin@archlinux.org>,
	Oliver Neukum <oneukum@suse.com>, Peng Fan <peng.fan@nxp.com>,
	Nikhil Solanke <nikhilsolanke5@gmail.com>,
	Kees Cook <kees@kernel.org>, Thorsten Blum <blum@kernel.org>,
	Takashi Iwai <tiwai@suse.de>,
	Victor Krawiec <victor.krawiec@arturia.com>,
	Jeffin Philip <jeffinphilip14@gmail.com>,
	Fan Wu <fanwu01@zju.edu.cn>
Cc: linux-kernel@vger.kernel.org,
	Lovekesh Solanki <lovekeshsolanki00@gmail.com>,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev
Subject: [PATCH] usb: use assign_bit() where applicable
Date: Fri, 18 Sep 2026 22:18:50 +0800	[thread overview]
Message-ID: <20260918141905.3023171-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>
---
 drivers/usb/core/hub.c               | 5 +----
 drivers/usb/core/sysfs.c             | 5 +----
 drivers/usb/gadget/function/f_midi.c | 5 +----
 drivers/usb/host/ehci-sysfs.c        | 5 +----
 drivers/usb/host/ohci-hub.c          | 7 ++-----
 drivers/usb/host/uhci-hcd.c          | 6 ++----
 drivers/usb/musb/sunxi.c             | 5 +----
 7 files changed, 9 insertions(+), 29 deletions(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 199d3f535a89..25a1cba39063 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -902,10 +902,7 @@ int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub,
 	if (ret)
 		return ret;
 
-	if (set)
-		set_bit(port1, hub->power_bits);
-	else
-		clear_bit(port1, hub->power_bits);
+	assign_bit(port1, hub->power_bits, set);
 	return 0;
 }
 
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index d22dc78457d7..25e8af8c1bd7 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -1032,10 +1032,7 @@ static ssize_t interface_authorized_default_store(struct device *dev,
 	if (kstrtobool(buf, &val) != 0)
 		return -EINVAL;
 
-	if (val)
-		set_bit(HCD_FLAG_INTF_AUTHORIZED, &hcd->flags);
-	else
-		clear_bit(HCD_FLAG_INTF_AUTHORIZED, &hcd->flags);
+	assign_bit(HCD_FLAG_INTF_AUTHORIZED, &hcd->flags, val);
 
 	return rc;
 }
diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
index 63fb6ee70a3d..eaec5a517faf 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -769,10 +769,7 @@ static void f_midi_out_trigger(struct snd_rawmidi_substream *substream, int up)
 
 	VDBG(midi, "%s()\n", __func__);
 
-	if (up)
-		set_bit(substream->number, &midi->out_triggered);
-	else
-		clear_bit(substream->number, &midi->out_triggered);
+	assign_bit(substream->number, &midi->out_triggered, up);
 }
 
 static const struct snd_rawmidi_ops gmidi_in_ops = {
diff --git a/drivers/usb/host/ehci-sysfs.c b/drivers/usb/host/ehci-sysfs.c
index 5e6b545c30e6..83bbcf759435 100644
--- a/drivers/usb/host/ehci-sysfs.c
+++ b/drivers/usb/host/ehci-sysfs.c
@@ -48,10 +48,7 @@ static ssize_t companion_store(struct device *dev,
 	if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params))
 		return -ENOENT;
 	portnum--;
-	if (new_owner)
-		set_bit(portnum, &ehci->companion_ports);
-	else
-		clear_bit(portnum, &ehci->companion_ports);
+	assign_bit(portnum, &ehci->companion_ports, new_owner);
 	set_owner(ehci, portnum, new_owner);
 	return count;
 }
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 84d10a932942..1ebf6aa4b2a3 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -518,11 +518,8 @@ int ohci_hub_status_data(struct usb_hcd *hcd, char *buf)
 		}
 	}
 
-	if (ohci_root_hub_state_changes(ohci, changed,
-			any_connected, rhsc_status))
-		set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
-	else
-		clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
+	assign_bit(HCD_FLAG_POLL_RH, &hcd->flags,
+		   ohci_root_hub_state_changes(ohci, changed, any_connected, rhsc_status));
 
 
 done:
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 433d64a5fab5..efc1e01005fd 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -376,10 +376,8 @@ __acquires(uhci->lock)
 	 * doesn't work, then we won't get an interrupt when a wakeup event
 	 * occurs.  Thus the suspended root hub needs to be polled.
 	 */
-	if (wakeup_enable && (!int_enable || !egsm_enable))
-		set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
-	else
-		clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
+	assign_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags,
+		   wakeup_enable && (!int_enable || !egsm_enable));
 
 	uhci_scan_schedule(uhci);
 	uhci_fsbr_off(uhci);
diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
index a6bd3e968cc7..347f547696b3 100644
--- a/drivers/usb/musb/sunxi.c
+++ b/drivers/usb/musb/sunxi.c
@@ -208,10 +208,7 @@ static int sunxi_musb_host_notifier(struct notifier_block *nb,
 {
 	struct sunxi_glue *glue = container_of(nb, struct sunxi_glue, host_nb);
 
-	if (event)
-		set_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags);
-	else
-		clear_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags);
+	assign_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags, event);
 
 	set_bit(SUNXI_MUSB_FL_HOSTMODE_PEND, &glue->flags);
 	schedule_work(&glue->work);
-- 
2.51.0



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

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260918141905.3023171-1-peng.fan@oss.nxp.com \
    --to=peng.fan@oss.nxp.com \
    --cc=b-liu@ti.com \
    --cc=blum@kernel.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=fanwu01@zju.edu.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=griffin@kroah.com \
    --cc=jeffinphilip14@gmail.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=kees@kernel.org \
    --cc=khtsai@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=linux-usb@vger.kernel.org \
    --cc=lovekeshsolanki00@gmail.com \
    --cc=martin@archlinux.org \
    --cc=nikhilsolanke5@gmail.com \
    --cc=oneukum@suse.com \
    --cc=peng.fan@nxp.com \
    --cc=samuel@sholland.org \
    --cc=stern@rowland.harvard.edu \
    --cc=tiwai@suse.de \
    --cc=victor.krawiec@arturia.com \
    --cc=wens@kernel.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