Skip to content

Commit d710734

Browse files
oneukumgregkh
authored andcommitted
USB: rio500: simplify locking
Admitting that there can be only one device allows us to drop any pretense about locking one device or a table of devices. Signed-off-by: Oliver Neukum <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e0feb73 commit d710734

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

drivers/usb/misc/rio500.c

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ struct rio_usb_data {
5151
char *obuf, *ibuf; /* transfer buffers */
5252
char bulk_in_ep, bulk_out_ep; /* Endpoint assignments */
5353
wait_queue_head_t wait_q; /* for timeouts */
54-
struct mutex lock; /* general race avoidance */
5554
};
5655

5756
static DEFINE_MUTEX(rio500_mutex);
@@ -63,18 +62,15 @@ static int open_rio(struct inode *inode, struct file *file)
6362

6463
/* against disconnect() */
6564
mutex_lock(&rio500_mutex);
66-
mutex_lock(&(rio->lock));
6765

6866
if (rio->isopen || !rio->present) {
69-
mutex_unlock(&(rio->lock));
7067
mutex_unlock(&rio500_mutex);
7168
return -EBUSY;
7269
}
7370
rio->isopen = 1;
7471

7572
init_waitqueue_head(&rio->wait_q);
7673

77-
mutex_unlock(&(rio->lock));
7874

7975
dev_info(&rio->rio_dev->dev, "Rio opened.\n");
8076
mutex_unlock(&rio500_mutex);
@@ -88,7 +84,6 @@ static int close_rio(struct inode *inode, struct file *file)
8884

8985
/* against disconnect() */
9086
mutex_lock(&rio500_mutex);
91-
mutex_lock(&(rio->lock));
9287

9388
rio->isopen = 0;
9489
if (!rio->present) {
@@ -100,7 +95,6 @@ static int close_rio(struct inode *inode, struct file *file)
10095
} else {
10196
dev_info(&rio->rio_dev->dev, "Rio closed.\n");
10297
}
103-
mutex_unlock(&(rio->lock));
10498
mutex_unlock(&rio500_mutex);
10599
return 0;
106100
}
@@ -115,7 +109,7 @@ static long ioctl_rio(struct file *file, unsigned int cmd, unsigned long arg)
115109
int retries;
116110
int retval=0;
117111

118-
mutex_lock(&(rio->lock));
112+
mutex_lock(&rio500_mutex);
119113
/* Sanity check to make sure rio is connected, powered, etc */
120114
if (rio->present == 0 || rio->rio_dev == NULL) {
121115
retval = -ENODEV;
@@ -259,7 +253,7 @@ static long ioctl_rio(struct file *file, unsigned int cmd, unsigned long arg)
259253

260254

261255
err_out:
262-
mutex_unlock(&(rio->lock));
256+
mutex_unlock(&rio500_mutex);
263257
return retval;
264258
}
265259

@@ -279,12 +273,12 @@ write_rio(struct file *file, const char __user *buffer,
279273
int errn = 0;
280274
int intr;
281275

282-
intr = mutex_lock_interruptible(&(rio->lock));
276+
intr = mutex_lock_interruptible(&rio500_mutex);
283277
if (intr)
284278
return -EINTR;
285279
/* Sanity check to make sure rio is connected, powered, etc */
286280
if (rio->present == 0 || rio->rio_dev == NULL) {
287-
mutex_unlock(&(rio->lock));
281+
mutex_unlock(&rio500_mutex);
288282
return -ENODEV;
289283
}
290284

@@ -307,7 +301,7 @@ write_rio(struct file *file, const char __user *buffer,
307301
goto error;
308302
}
309303
if (signal_pending(current)) {
310-
mutex_unlock(&(rio->lock));
304+
mutex_unlock(&rio500_mutex);
311305
return bytes_written ? bytes_written : -EINTR;
312306
}
313307

@@ -345,12 +339,12 @@ write_rio(struct file *file, const char __user *buffer,
345339
buffer += copy_size;
346340
} while (count > 0);
347341

348-
mutex_unlock(&(rio->lock));
342+
mutex_unlock(&rio500_mutex);
349343

350344
return bytes_written ? bytes_written : -EIO;
351345

352346
error:
353-
mutex_unlock(&(rio->lock));
347+
mutex_unlock(&rio500_mutex);
354348
return errn;
355349
}
356350

@@ -367,12 +361,12 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
367361
char *ibuf;
368362
int intr;
369363

370-
intr = mutex_lock_interruptible(&(rio->lock));
364+
intr = mutex_lock_interruptible(&rio500_mutex);
371365
if (intr)
372366
return -EINTR;
373367
/* Sanity check to make sure rio is connected, powered, etc */
374368
if (rio->present == 0 || rio->rio_dev == NULL) {
375-
mutex_unlock(&(rio->lock));
369+
mutex_unlock(&rio500_mutex);
376370
return -ENODEV;
377371
}
378372

@@ -383,11 +377,11 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
383377

384378
while (count > 0) {
385379
if (signal_pending(current)) {
386-
mutex_unlock(&(rio->lock));
380+
mutex_unlock(&rio500_mutex);
387381
return read_count ? read_count : -EINTR;
388382
}
389383
if (!rio->rio_dev) {
390-
mutex_unlock(&(rio->lock));
384+
mutex_unlock(&rio500_mutex);
391385
return -ENODEV;
392386
}
393387
this_read = (count >= IBUF_SIZE) ? IBUF_SIZE : count;
@@ -405,7 +399,7 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
405399
count = this_read = partial;
406400
} else if (result == -ETIMEDOUT || result == 15) { /* FIXME: 15 ??? */
407401
if (!maxretry--) {
408-
mutex_unlock(&(rio->lock));
402+
mutex_unlock(&rio500_mutex);
409403
dev_err(&rio->rio_dev->dev,
410404
"read_rio: maxretry timeout\n");
411405
return -ETIME;
@@ -415,27 +409,27 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
415409
finish_wait(&rio->wait_q, &wait);
416410
continue;
417411
} else if (result != -EREMOTEIO) {
418-
mutex_unlock(&(rio->lock));
412+
mutex_unlock(&rio500_mutex);
419413
dev_err(&rio->rio_dev->dev,
420414
"Read Whoops - result:%d partial:%u this_read:%u\n",
421415
result, partial, this_read);
422416
return -EIO;
423417
} else {
424-
mutex_unlock(&(rio->lock));
418+
mutex_unlock(&rio500_mutex);
425419
return (0);
426420
}
427421

428422
if (this_read) {
429423
if (copy_to_user(buffer, ibuf, this_read)) {
430-
mutex_unlock(&(rio->lock));
424+
mutex_unlock(&rio500_mutex);
431425
return -EFAULT;
432426
}
433427
count -= this_read;
434428
read_count += this_read;
435429
buffer += this_read;
436430
}
437431
}
438-
mutex_unlock(&(rio->lock));
432+
mutex_unlock(&rio500_mutex);
439433
return read_count;
440434
}
441435

@@ -500,8 +494,6 @@ static int probe_rio(struct usb_interface *intf,
500494
}
501495
dev_dbg(&intf->dev, "ibuf address:%p\n", rio->ibuf);
502496

503-
mutex_init(&(rio->lock));
504-
505497
usb_set_intfdata (intf, rio);
506498
rio->present = 1;
507499
bail_out:
@@ -519,12 +511,10 @@ static void disconnect_rio(struct usb_interface *intf)
519511
if (rio) {
520512
usb_deregister_dev(intf, &usb_rio_class);
521513

522-
mutex_lock(&(rio->lock));
523514
if (rio->isopen) {
524515
rio->isopen = 0;
525516
/* better let it finish - the release will do whats needed */
526517
rio->rio_dev = NULL;
527-
mutex_unlock(&(rio->lock));
528518
mutex_unlock(&rio500_mutex);
529519
return;
530520
}
@@ -534,7 +524,6 @@ static void disconnect_rio(struct usb_interface *intf)
534524
dev_info(&intf->dev, "USB Rio disconnected.\n");
535525

536526
rio->present = 0;
537-
mutex_unlock(&(rio->lock));
538527
}
539528
mutex_unlock(&rio500_mutex);
540529
}

0 commit comments

Comments
 (0)