diff options
author | Pete Zaitcev <zaitcev@redhat.com> | 2005-12-16 03:39:36 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-01-04 16:48:31 -0500 |
commit | 5ba35bd8f9a4fa6b92ef707826c47a1466ece460 (patch) | |
tree | 2c180db14baa56d05dca8ff66d78bb97348a60cb /drivers/usb/storage | |
parent | a00828e9ac62caed7b830d631914d7748817ccd1 (diff) |
[PATCH] USB: make bias writeable in libusual
Make the bias parameter writeable. Writing the parameter does not trigger
a rebind of currently attached storage devices.
Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/storage')
-rw-r--r-- | drivers/usb/storage/libusual.c | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/drivers/usb/storage/libusual.c b/drivers/usb/storage/libusual.c index 61f73d8a2c0f..2680c69a2417 100644 --- a/drivers/usb/storage/libusual.c +++ b/drivers/usb/storage/libusual.c | |||
@@ -24,10 +24,9 @@ static DEFINE_SPINLOCK(usu_lock); | |||
24 | /* | 24 | /* |
25 | */ | 25 | */ |
26 | #define USB_US_DEFAULT_BIAS USB_US_TYPE_STOR | 26 | #define USB_US_DEFAULT_BIAS USB_US_TYPE_STOR |
27 | static atomic_t usu_bias = ATOMIC_INIT(USB_US_DEFAULT_BIAS); | ||
27 | 28 | ||
28 | #define BIAS_NAME_SIZE (sizeof("usb-storage")) | 29 | #define BIAS_NAME_SIZE (sizeof("usb-storage")) |
29 | static char bias[BIAS_NAME_SIZE]; | ||
30 | static int usb_usual_bias; | ||
31 | static const char *bias_names[3] = { "none", "usb-storage", "ub" }; | 30 | static const char *bias_names[3] = { "none", "usb-storage", "ub" }; |
32 | 31 | ||
33 | static DECLARE_MUTEX_LOCKED(usu_init_notify); | 32 | static DECLARE_MUTEX_LOCKED(usu_init_notify); |
@@ -35,7 +34,6 @@ static DECLARE_COMPLETION(usu_end_notify); | |||
35 | static atomic_t total_threads = ATOMIC_INIT(0); | 34 | static atomic_t total_threads = ATOMIC_INIT(0); |
36 | 35 | ||
37 | static int usu_probe_thread(void *arg); | 36 | static int usu_probe_thread(void *arg); |
38 | static int parse_bias(const char *bias_s); | ||
39 | 37 | ||
40 | /* | 38 | /* |
41 | * The table. | 39 | * The table. |
@@ -107,7 +105,7 @@ int usb_usual_check_type(const struct usb_device_id *id, int caller_type) | |||
107 | if (id_type == caller_type) | 105 | if (id_type == caller_type) |
108 | return 0; | 106 | return 0; |
109 | /* Drivers grab devices biased to them */ | 107 | /* Drivers grab devices biased to them */ |
110 | if (id_type == USB_US_TYPE_NONE && caller_type == usb_usual_bias) | 108 | if (id_type == USB_US_TYPE_NONE && caller_type == atomic_read(&usu_bias)) |
111 | return 0; | 109 | return 0; |
112 | return -ENODEV; | 110 | return -ENODEV; |
113 | } | 111 | } |
@@ -124,7 +122,7 @@ static int usu_probe(struct usb_interface *intf, | |||
124 | 122 | ||
125 | type = USB_US_TYPE(id->driver_info); | 123 | type = USB_US_TYPE(id->driver_info); |
126 | if (type == 0) | 124 | if (type == 0) |
127 | type = usb_usual_bias; | 125 | type = atomic_read(&usu_bias); |
128 | 126 | ||
129 | spin_lock_irqsave(&usu_lock, flags); | 127 | spin_lock_irqsave(&usu_lock, flags); |
130 | if ((stat[type].fls & (USU_MOD_FL_THREAD|USU_MOD_FL_PRESENT)) != 0) { | 128 | if ((stat[type].fls & (USU_MOD_FL_THREAD|USU_MOD_FL_PRESENT)) != 0) { |
@@ -206,9 +204,6 @@ static int __init usb_usual_init(void) | |||
206 | { | 204 | { |
207 | int rc; | 205 | int rc; |
208 | 206 | ||
209 | bias[BIAS_NAME_SIZE-1] = 0; | ||
210 | usb_usual_bias = parse_bias(bias); | ||
211 | |||
212 | rc = usb_register(&usu_driver); | 207 | rc = usb_register(&usu_driver); |
213 | up(&usu_init_notify); | 208 | up(&usu_init_notify); |
214 | return rc; | 209 | return rc; |
@@ -231,36 +226,42 @@ static void __exit usb_usual_exit(void) | |||
231 | 226 | ||
232 | /* | 227 | /* |
233 | * Validate and accept the bias parameter. | 228 | * Validate and accept the bias parameter. |
234 | * Maybe make an sysfs method later. XXX | ||
235 | */ | 229 | */ |
236 | static int parse_bias(const char *bias_s) | 230 | static int usu_set_bias(const char *bias_s, struct kernel_param *kp) |
237 | { | 231 | { |
238 | int i; | 232 | int i; |
233 | int len; | ||
239 | int bias_n = 0; | 234 | int bias_n = 0; |
240 | 235 | ||
241 | if (bias_s[0] == 0 || bias_s[0] == ' ') { | 236 | len = strlen(bias_s); |
242 | bias_n = USB_US_DEFAULT_BIAS; | 237 | if (len == 0) |
243 | } else { | 238 | return -EDOM; |
244 | for (i = 1; i < 3; i++) { | 239 | if (bias_s[len-1] == '\n') |
245 | if (strcmp(bias_s, bias_names[i]) == 0) { | 240 | --len; |
246 | bias_n = i; | 241 | |
247 | break; | 242 | for (i = 1; i < 3; i++) { |
248 | } | 243 | if (strncmp(bias_s, bias_names[i], len) == 0) { |
249 | } | 244 | bias_n = i; |
250 | if (bias_n == 0) { | 245 | break; |
251 | bias_n = USB_US_DEFAULT_BIAS; | ||
252 | printk(KERN_INFO | ||
253 | "libusual: unknown bias \"%s\", using \"%s\"\n", | ||
254 | bias_s, bias_names[bias_n]); | ||
255 | } | 246 | } |
256 | } | 247 | } |
257 | return bias_n; | 248 | if (bias_n == 0) |
249 | return -EINVAL; | ||
250 | |||
251 | atomic_set(&usu_bias, bias_n); | ||
252 | return 0; | ||
253 | } | ||
254 | |||
255 | static int usu_get_bias(char *buffer, struct kernel_param *kp) | ||
256 | { | ||
257 | return strlen(strcpy(buffer, bias_names[atomic_read(&usu_bias)])); | ||
258 | } | 258 | } |
259 | 259 | ||
260 | module_init(usb_usual_init); | 260 | module_init(usb_usual_init); |
261 | module_exit(usb_usual_exit); | 261 | module_exit(usb_usual_exit); |
262 | 262 | ||
263 | module_param_string(bias, bias, BIAS_NAME_SIZE, S_IRUGO|S_IWUSR); | 263 | module_param_call(bias, usu_set_bias, usu_get_bias, NULL, S_IRUGO|S_IWUSR); |
264 | __MODULE_PARM_TYPE(bias, "string"); | ||
264 | MODULE_PARM_DESC(bias, "Bias to usb-storage or ub"); | 265 | MODULE_PARM_DESC(bias, "Bias to usb-storage or ub"); |
265 | 266 | ||
266 | MODULE_LICENSE("GPL"); | 267 | MODULE_LICENSE("GPL"); |