summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMatthew Dharm <mdharm-usb@one-eyed-alien.net>2002-06-17 23:35:32 -0700
committerGreg Kroah-Hartman <greg@kroah.com>2002-06-17 23:35:32 -0700
commit1c009ca6b0bcfcae817e2f64b77cc72b6bab8958 (patch)
tree0ae851479e5b3c6fd1be65a0dfd317e5af692840 /drivers
parent2cc2b5458a33c5eedc92cbd550b7d8452264b686 (diff)
[PATCH] USB storage: change atomic_t to bitfield, consolidate #defines
This patch changes from using an atomic_t with two states to using a bitfield to determine if a device is attached. It also moves some common #defines into a common header file. courtsey of Alan Stern <stern@rowland.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/storage/scsiglue.c14
-rw-r--r--drivers/usb/storage/usb.c21
-rw-r--r--drivers/usb/storage/usb.h11
3 files changed, 17 insertions, 29 deletions
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 17e861fcae9f..4e9f376c38f5 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -51,12 +51,6 @@
#include <linux/slab.h>
-/*
- * kernel thread actions
- */
-
-#define US_ACT_COMMAND 1
-#define US_ACT_EXIT 5
/***********************************************************************
* Host functions
@@ -204,7 +198,7 @@ static int device_reset( Scsi_Cmnd *srb )
US_DEBUGP("device_reset() called\n" );
/* if the device was removed, then we're already reset */
- if (atomic_read(&us->sm_state) == US_STATE_DETACHED)
+ if (!test_bit(DEV_ATTACHED, &us->bitflags))
return SUCCESS;
scsi_unlock(srb->host);
@@ -235,7 +229,7 @@ static int bus_reset( Scsi_Cmnd *srb )
US_DEBUGP("bus_reset() called\n");
/* if the device has been removed, this worked */
- if (atomic_read(&us->sm_state) == US_STATE_DETACHED) {
+ if (!test_bit(DEV_ATTACHED, &us->bitflags)) {
US_DEBUGP("-- device removed already\n");
return SUCCESS;
}
@@ -337,8 +331,8 @@ static int proc_info (char *buffer, char **start, off_t offset, int length,
/* show the GUID of the device */
SPRINTF(" GUID: " GUID_FORMAT "\n", GUID_ARGS(us->guid));
- SPRINTF(" Attached: %s\n", (atomic_read(&us->sm_state) ==
- US_STATE_DETACHED) ? "Yes" : "No");
+ SPRINTF(" Attached: %s\n", (test_bit(DEV_ATTACHED, &us->bitflags)
+ ? "Yes" : "No"));
/*
* Calculate start of next buffer, and return value.
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index f223b3901772..76d70eb5a9bf 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -99,13 +99,6 @@ MODULE_LICENSE("GPL");
static int my_host_number;
-/*
- * kernel thread actions
- */
-
-#define US_ACT_COMMAND 1
-#define US_ACT_EXIT 5
-
/* The list of structures and the protective lock for them */
struct us_data *us_list;
struct semaphore us_list_semaphore;
@@ -426,7 +419,7 @@ static int usb_stor_control_thread(void * __us)
down(&(us->dev_semaphore));
/* our device has gone - pretend not ready */
- if (atomic_read(&us->device_state) == US_STATE_DETACHED) {
+ if (!test_bit(DEV_ATTACHED, &us->bitflags)) {
US_DEBUGP("Request is for removed device\n");
/* For REQUEST_SENSE, it's the data. But
* for anything else, it should look like
@@ -450,7 +443,7 @@ static int usb_stor_control_thread(void * __us)
sizeof(usb_stor_sense_notready));
us->srb->result = CHECK_CONDITION << 1;
}
- } else { /* atomic_read(&us->device_state) == STATE_DETACHED */
+ } else { /* test_bit(DEV_ATTACHED, &us->bitflags) */
/* Handle those devices which need us to fake
* their inquiry data */
@@ -695,7 +688,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
*/
ss = us_list;
while ((ss != NULL) &&
- ((atomic_read(&ss->device_state) == US_STATE_ATTACHED) ||
+ (test_bit(DEV_ATTACHED, &ss->bitflags) ||
!GUID_EQUAL(guid, ss->guid)))
ss = ss->next;
@@ -710,7 +703,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
/* establish the connection to the new device upon reconnect */
ss->ifnum = ifnum;
ss->pusb_dev = dev;
- atomic_set(&ss->device_state, US_STATE_ATTACHED);
+ set_bit(DEV_ATTACHED, &ss->bitflags);
/* copy over the endpoint data */
ss->ep_in = ep_in->bEndpointAddress &
@@ -979,7 +972,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
/* start up our control thread */
atomic_set(&ss->sm_state, US_STATE_IDLE);
- atomic_set(&ss->device_state, US_STATE_ATTACHED);
+ set_bit(DEV_ATTACHED, &ss->bitflags);
ss->pid = kernel_thread(usb_stor_control_thread, ss,
CLONE_VM);
if (ss->pid < 0) {
@@ -1040,7 +1033,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
ss->current_urb = NULL;
}
- atomic_set(&ss->device_state, US_STATE_DETACHED);
+ clear_bit(DEV_ATTACHED, &ss->bitflags);
ss->pusb_dev = NULL;
if (new_device)
kfree(ss);
@@ -1088,7 +1081,7 @@ static void storage_disconnect(struct usb_device *dev, void *ptr)
/* mark the device as gone */
usb_put_dev(ss->pusb_dev);
ss->pusb_dev = NULL;
- atomic_set(&ss->sm_state, US_STATE_DETACHED);
+ clear_bit(DEV_ATTACHED, &ss->bitflags);
/* unlock access to the device data structure */
up(&(ss->dev_semaphore));
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index 6c90eb638a4b..d0f1f24ded28 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -103,9 +103,10 @@ struct us_unusual_dev {
#define US_FL_SCM_MULT_TARG 0x00000020 /* supports multiple targets */
#define US_FL_FIX_INQUIRY 0x00000040 /* INQUIRY response needs fixing */
-/* device attached/detached states */
-#define US_STATE_DETACHED 1
-#define US_STATE_ATTACHED 2
+
+/* kernel thread actions */
+#define US_ACT_COMMAND 1
+#define US_ACT_EXIT 5
/* processing state machine states */
#define US_STATE_IDLE 1
@@ -127,10 +128,9 @@ struct us_data {
/* The device we're working with
* It's important to note:
* (o) you must hold dev_semaphore to change pusb_dev
- * (o) device_state should change whenever pusb_dev does
+ * (o) DEV_ATTACHED in bitflags should change whenever pusb_dev does
*/
struct semaphore dev_semaphore; /* protect pusb_dev */
- atomic_t device_state; /* attached or detached */
struct usb_device *pusb_dev; /* this usb_device */
unsigned int flags; /* from filter initially */
@@ -174,6 +174,7 @@ struct us_data {
struct semaphore ip_waitq; /* for CBI interrupts */
unsigned long bitflags; /* single-bit flags: */
#define IP_WANTED 1 /* is an IRQ expected? */
+#define DEV_ATTACHED 2 /* is the dev. attached?*/
/* interrupt communications data */
struct semaphore irq_urb_sem; /* to protect irq_urb */