Commit 1c009ca6 authored by Matthew Dharm's avatar Matthew Dharm Committed by Greg Kroah-Hartman

[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>
parent 2cc2b545
......@@ -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.
......
......@@ -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));
......
......@@ -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 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment