@@ -51,7 +51,6 @@ struct rio_usb_data {
51
51
char * obuf , * ibuf ; /* transfer buffers */
52
52
char bulk_in_ep , bulk_out_ep ; /* Endpoint assignments */
53
53
wait_queue_head_t wait_q ; /* for timeouts */
54
- struct mutex lock ; /* general race avoidance */
55
54
};
56
55
57
56
static DEFINE_MUTEX (rio500_mutex );
@@ -63,18 +62,15 @@ static int open_rio(struct inode *inode, struct file *file)
63
62
64
63
/* against disconnect() */
65
64
mutex_lock (& rio500_mutex );
66
- mutex_lock (& (rio -> lock ));
67
65
68
66
if (rio -> isopen || !rio -> present ) {
69
- mutex_unlock (& (rio -> lock ));
70
67
mutex_unlock (& rio500_mutex );
71
68
return - EBUSY ;
72
69
}
73
70
rio -> isopen = 1 ;
74
71
75
72
init_waitqueue_head (& rio -> wait_q );
76
73
77
- mutex_unlock (& (rio -> lock ));
78
74
79
75
dev_info (& rio -> rio_dev -> dev , "Rio opened.\n" );
80
76
mutex_unlock (& rio500_mutex );
@@ -88,7 +84,6 @@ static int close_rio(struct inode *inode, struct file *file)
88
84
89
85
/* against disconnect() */
90
86
mutex_lock (& rio500_mutex );
91
- mutex_lock (& (rio -> lock ));
92
87
93
88
rio -> isopen = 0 ;
94
89
if (!rio -> present ) {
@@ -100,7 +95,6 @@ static int close_rio(struct inode *inode, struct file *file)
100
95
} else {
101
96
dev_info (& rio -> rio_dev -> dev , "Rio closed.\n" );
102
97
}
103
- mutex_unlock (& (rio -> lock ));
104
98
mutex_unlock (& rio500_mutex );
105
99
return 0 ;
106
100
}
@@ -115,7 +109,7 @@ static long ioctl_rio(struct file *file, unsigned int cmd, unsigned long arg)
115
109
int retries ;
116
110
int retval = 0 ;
117
111
118
- mutex_lock (& ( rio -> lock ) );
112
+ mutex_lock (& rio500_mutex );
119
113
/* Sanity check to make sure rio is connected, powered, etc */
120
114
if (rio -> present == 0 || rio -> rio_dev == NULL ) {
121
115
retval = - ENODEV ;
@@ -259,7 +253,7 @@ static long ioctl_rio(struct file *file, unsigned int cmd, unsigned long arg)
259
253
260
254
261
255
err_out :
262
- mutex_unlock (& ( rio -> lock ) );
256
+ mutex_unlock (& rio500_mutex );
263
257
return retval ;
264
258
}
265
259
@@ -279,12 +273,12 @@ write_rio(struct file *file, const char __user *buffer,
279
273
int errn = 0 ;
280
274
int intr ;
281
275
282
- intr = mutex_lock_interruptible (& ( rio -> lock ) );
276
+ intr = mutex_lock_interruptible (& rio500_mutex );
283
277
if (intr )
284
278
return - EINTR ;
285
279
/* Sanity check to make sure rio is connected, powered, etc */
286
280
if (rio -> present == 0 || rio -> rio_dev == NULL ) {
287
- mutex_unlock (& ( rio -> lock ) );
281
+ mutex_unlock (& rio500_mutex );
288
282
return - ENODEV ;
289
283
}
290
284
@@ -307,7 +301,7 @@ write_rio(struct file *file, const char __user *buffer,
307
301
goto error ;
308
302
}
309
303
if (signal_pending (current )) {
310
- mutex_unlock (& ( rio -> lock ) );
304
+ mutex_unlock (& rio500_mutex );
311
305
return bytes_written ? bytes_written : - EINTR ;
312
306
}
313
307
@@ -345,12 +339,12 @@ write_rio(struct file *file, const char __user *buffer,
345
339
buffer += copy_size ;
346
340
} while (count > 0 );
347
341
348
- mutex_unlock (& ( rio -> lock ) );
342
+ mutex_unlock (& rio500_mutex );
349
343
350
344
return bytes_written ? bytes_written : - EIO ;
351
345
352
346
error :
353
- mutex_unlock (& ( rio -> lock ) );
347
+ mutex_unlock (& rio500_mutex );
354
348
return errn ;
355
349
}
356
350
@@ -367,12 +361,12 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
367
361
char * ibuf ;
368
362
int intr ;
369
363
370
- intr = mutex_lock_interruptible (& ( rio -> lock ) );
364
+ intr = mutex_lock_interruptible (& rio500_mutex );
371
365
if (intr )
372
366
return - EINTR ;
373
367
/* Sanity check to make sure rio is connected, powered, etc */
374
368
if (rio -> present == 0 || rio -> rio_dev == NULL ) {
375
- mutex_unlock (& ( rio -> lock ) );
369
+ mutex_unlock (& rio500_mutex );
376
370
return - ENODEV ;
377
371
}
378
372
@@ -383,11 +377,11 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
383
377
384
378
while (count > 0 ) {
385
379
if (signal_pending (current )) {
386
- mutex_unlock (& ( rio -> lock ) );
380
+ mutex_unlock (& rio500_mutex );
387
381
return read_count ? read_count : - EINTR ;
388
382
}
389
383
if (!rio -> rio_dev ) {
390
- mutex_unlock (& ( rio -> lock ) );
384
+ mutex_unlock (& rio500_mutex );
391
385
return - ENODEV ;
392
386
}
393
387
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)
405
399
count = this_read = partial ;
406
400
} else if (result == - ETIMEDOUT || result == 15 ) { /* FIXME: 15 ??? */
407
401
if (!maxretry -- ) {
408
- mutex_unlock (& ( rio -> lock ) );
402
+ mutex_unlock (& rio500_mutex );
409
403
dev_err (& rio -> rio_dev -> dev ,
410
404
"read_rio: maxretry timeout\n" );
411
405
return - ETIME ;
@@ -415,27 +409,27 @@ read_rio(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
415
409
finish_wait (& rio -> wait_q , & wait );
416
410
continue ;
417
411
} else if (result != - EREMOTEIO ) {
418
- mutex_unlock (& ( rio -> lock ) );
412
+ mutex_unlock (& rio500_mutex );
419
413
dev_err (& rio -> rio_dev -> dev ,
420
414
"Read Whoops - result:%d partial:%u this_read:%u\n" ,
421
415
result , partial , this_read );
422
416
return - EIO ;
423
417
} else {
424
- mutex_unlock (& ( rio -> lock ) );
418
+ mutex_unlock (& rio500_mutex );
425
419
return (0 );
426
420
}
427
421
428
422
if (this_read ) {
429
423
if (copy_to_user (buffer , ibuf , this_read )) {
430
- mutex_unlock (& ( rio -> lock ) );
424
+ mutex_unlock (& rio500_mutex );
431
425
return - EFAULT ;
432
426
}
433
427
count -= this_read ;
434
428
read_count += this_read ;
435
429
buffer += this_read ;
436
430
}
437
431
}
438
- mutex_unlock (& ( rio -> lock ) );
432
+ mutex_unlock (& rio500_mutex );
439
433
return read_count ;
440
434
}
441
435
@@ -500,8 +494,6 @@ static int probe_rio(struct usb_interface *intf,
500
494
}
501
495
dev_dbg (& intf -> dev , "ibuf address:%p\n" , rio -> ibuf );
502
496
503
- mutex_init (& (rio -> lock ));
504
-
505
497
usb_set_intfdata (intf , rio );
506
498
rio -> present = 1 ;
507
499
bail_out :
@@ -519,12 +511,10 @@ static void disconnect_rio(struct usb_interface *intf)
519
511
if (rio ) {
520
512
usb_deregister_dev (intf , & usb_rio_class );
521
513
522
- mutex_lock (& (rio -> lock ));
523
514
if (rio -> isopen ) {
524
515
rio -> isopen = 0 ;
525
516
/* better let it finish - the release will do whats needed */
526
517
rio -> rio_dev = NULL ;
527
- mutex_unlock (& (rio -> lock ));
528
518
mutex_unlock (& rio500_mutex );
529
519
return ;
530
520
}
@@ -534,7 +524,6 @@ static void disconnect_rio(struct usb_interface *intf)
534
524
dev_info (& intf -> dev , "USB Rio disconnected.\n" );
535
525
536
526
rio -> present = 0 ;
537
- mutex_unlock (& (rio -> lock ));
538
527
}
539
528
mutex_unlock (& rio500_mutex );
540
529
}
0 commit comments