linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Mackerras <paulus@samba.org>
To: dbrownell@users.sourceforge.net, greg@kroah.com
Cc: linux-kernel@vger.kernel.org
Subject: unnecessary use of set_bit
Date: Sat, 27 Apr 2002 22:26:02 +1000 (EST)	[thread overview]
Message-ID: <15562.39130.683869.175699@argo.ozlabs.ibm.com> (raw)

The ohci_hub_status_data() procedure in drivers/usb/host/ohci-hub.c in
2.5.11 is broken in a couple of ways: it uses set_bit on a char *
address and it assumes little-endian byte order in the bitmap.

Here is a patch to fix both problems.  As a bonus, the file ends up
one line shorter. :)

Please, people, don't use set_bit when you don't need an atomic
operation.  set_bit(&x, n) is slower than x |= 1 << n on a lot of
platforms, including SMP x86 I believe.  (If the bitmap is more than
one word you can use __set_bit if you don't require atomicity.)

Paul.

diff -urN linux-2.5/drivers/usb/host/ohci-hub.c pmac-2.5/drivers/usb/host/ohci-hub.c
--- linux-2.5/drivers/usb/host/ohci-hub.c	Sat Apr 27 20:51:31 2002
+++ pmac-2.5/drivers/usb/host/ohci-hub.c	Sat Apr 27 15:03:06 2002
@@ -67,7 +67,7 @@
 ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
 {
 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd);
-	int		ports, i, changed = 0, length = 1;
+	int		ports, i, mask = 0, length = 1;
 
 	ports = roothub_a (ohci) & RH_A_NDP; 
 	if (ports > MAX_ROOT_PORTS) {
@@ -80,13 +80,7 @@
 
 	/* init status */
 	if (roothub_status (ohci) & (RH_HS_LPSC | RH_HS_OCIC))
-		buf [0] = changed = 1;
-	else
-		buf [0] = 0;
-	if (ports > 7) {
-		buf [1] = 0;
-		length++;
-	}
+		mask = 1;
 
 	/* look at each port */
 	for (i = 0; i < ports; i++) {
@@ -94,12 +88,17 @@
 
 		status &= RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
 				| RH_PS_OCIC | RH_PS_PRSC;
-		if (status) {
-			changed = 1;
-			set_bit (i + 1, buf);
-		}
+		if (status)
+			mask |= 1 << (i + 1);
+	}
+	if (!mask)
+		return 0;
+	buf[0] = mask;
+	if (ports > 7) {
+		length++;
+		buf[1] = mask >> 8;
 	}
-	return changed ? length : 0;
+	return length;
 }
 
 /*-------------------------------------------------------------------------*/

             reply	other threads:[~2002-04-27 12:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-27 12:26 Paul Mackerras [this message]
2002-04-27 14:19 ` unnecessary use of set_bit David Brownell

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=15562.39130.683869.175699@argo.ozlabs.ibm.com \
    --to=paulus@samba.org \
    --cc=dbrownell@users.sourceforge.net \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).