Commit f9383c4269d264c3cf563bd2de365891f6592ebd

Authored by Matthias Kaehlcke
Committed by Bartlomiej Zolnierkiewicz
1 parent 1b9da32a28

ide: use mutex instead of ide_setting_sem semaphore in IDE driver

The IDE driver uses a semaphore as mutex.
Use the mutex API instead of the (binary) semaphore.

Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>

--

Showing 4 changed files with 29 additions and 28 deletions Side-by-side Diff

drivers/ide/ide-disk.c
... ... @@ -1190,11 +1190,11 @@
1190 1190 return generic_ide_ioctl(drive, file, bdev, cmd, arg);
1191 1191  
1192 1192 read_val:
1193   - down(&ide_setting_sem);
  1193 + mutex_lock(&ide_setting_mtx);
1194 1194 spin_lock_irqsave(&ide_lock, flags);
1195 1195 err = *val;
1196 1196 spin_unlock_irqrestore(&ide_lock, flags);
1197   - up(&ide_setting_sem);
  1197 + mutex_unlock(&ide_setting_mtx);
1198 1198 return err >= 0 ? put_user(err, (long __user *)arg) : err;
1199 1199  
1200 1200 set_val:
1201 1201  
... ... @@ -1204,9 +1204,9 @@
1204 1204 if (!capable(CAP_SYS_ADMIN))
1205 1205 err = -EACCES;
1206 1206 else {
1207   - down(&ide_setting_sem);
  1207 + mutex_lock(&ide_setting_mtx);
1208 1208 err = setfunc(drive, arg);
1209   - up(&ide_setting_sem);
  1209 + mutex_unlock(&ide_setting_mtx);
1210 1210 }
1211 1211 }
1212 1212 return err;
drivers/ide/ide-proc.c
... ... @@ -156,7 +156,7 @@
156 156 {
157 157 ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
158 158  
159   - down(&ide_setting_sem);
  159 + mutex_lock(&ide_setting_mtx);
160 160 while ((*p) && strcmp((*p)->name, name) < 0)
161 161 p = &((*p)->next);
162 162 if ((setting = kzalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
163 163  
... ... @@ -177,10 +177,10 @@
177 177 if (auto_remove)
178 178 setting->auto_remove = 1;
179 179 *p = setting;
180   - up(&ide_setting_sem);
  180 + mutex_unlock(&ide_setting_mtx);
181 181 return 0;
182 182 abort:
183   - up(&ide_setting_sem);
  183 + mutex_unlock(&ide_setting_mtx);
184 184 kfree(setting);
185 185 return -1;
186 186 }
... ... @@ -224,7 +224,7 @@
224 224 *
225 225 * Automatically remove all the driver specific settings for this
226 226 * drive. This function may not be called from IRQ context. The
227   - * caller must hold ide_setting_sem.
  227 + * caller must hold ide_setting_mtx.
228 228 */
229 229  
230 230 static void auto_remove_settings (ide_drive_t *drive)
... ... @@ -269,7 +269,7 @@
269 269 * @setting: drive setting
270 270 *
271 271 * Read a drive setting and return the value. The caller
272   - * must hold the ide_setting_sem when making this call.
  272 + * must hold the ide_setting_mtx when making this call.
273 273 *
274 274 * BUGS: the data return and error are the same return value
275 275 * so an error -EINVAL and true return of the same value cannot
... ... @@ -306,7 +306,7 @@
306 306 * @val: value
307 307 *
308 308 * Write a drive setting if it is possible. The caller
309   - * must hold the ide_setting_sem when making this call.
  309 + * must hold the ide_setting_mtx when making this call.
310 310 *
311 311 * BUGS: the data return and error are the same return value
312 312 * so an error -EINVAL and true return of the same value cannot
... ... @@ -367,7 +367,7 @@
367 367 * @drive: drive being configured
368 368 *
369 369 * Add the generic parts of the system settings to the /proc files.
370   - * The caller must not be holding the ide_setting_sem.
  370 + * The caller must not be holding the ide_setting_mtx.
371 371 */
372 372  
373 373 void ide_add_generic_settings (ide_drive_t *drive)
... ... @@ -408,7 +408,7 @@
408 408  
409 409 proc_ide_settings_warn();
410 410  
411   - down(&ide_setting_sem);
  411 + mutex_lock(&ide_setting_mtx);
412 412 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
413 413 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
414 414 while(setting) {
... ... @@ -428,7 +428,7 @@
428 428 setting = setting->next;
429 429 }
430 430 len = out - page;
431   - up(&ide_setting_sem);
  431 + mutex_unlock(&ide_setting_mtx);
432 432 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
433 433 }
434 434  
435 435  
436 436  
... ... @@ -508,16 +508,16 @@
508 508 ++p;
509 509 }
510 510  
511   - down(&ide_setting_sem);
  511 + mutex_lock(&ide_setting_mtx);
512 512 setting = ide_find_setting_by_name(drive, name);
513 513 if (!setting)
514 514 {
515   - up(&ide_setting_sem);
  515 + mutex_unlock(&ide_setting_mtx);
516 516 goto parse_error;
517 517 }
518 518 if (for_real)
519 519 ide_write_setting(drive, setting, val * setting->div_factor / setting->mul_factor);
520   - up(&ide_setting_sem);
  520 + mutex_unlock(&ide_setting_mtx);
521 521 }
522 522 } while (!for_real++);
523 523 free_page((unsigned long)buf);
... ... @@ -705,7 +705,7 @@
705 705 * Clean up the driver specific /proc files and IDE settings
706 706 * for a given drive.
707 707 *
708   - * Takes ide_setting_sem and ide_lock.
  708 + * Takes ide_setting_mtx and ide_lock.
709 709 * Caller must hold none of the locks.
710 710 */
711 711  
712 712  
... ... @@ -715,10 +715,10 @@
715 715  
716 716 ide_remove_proc_entries(drive->proc, driver->proc);
717 717  
718   - down(&ide_setting_sem);
  718 + mutex_lock(&ide_setting_mtx);
719 719 spin_lock_irqsave(&ide_lock, flags);
720 720 /*
721   - * ide_setting_sem protects the settings list
  721 + * ide_setting_mtx protects the settings list
722 722 * ide_lock protects the use of settings
723 723 *
724 724 * so we need to hold both, ide_settings_sem because we want to
725 725  
... ... @@ -726,11 +726,11 @@
726 726 * a setting out that is being used.
727 727 *
728 728 * OTOH both ide_{read,write}_setting are only ever used under
729   - * ide_setting_sem.
  729 + * ide_setting_mtx.
730 730 */
731 731 auto_remove_settings(drive);
732 732 spin_unlock_irqrestore(&ide_lock, flags);
733   - up(&ide_setting_sem);
  733 + mutex_unlock(&ide_setting_mtx);
734 734 }
735 735  
736 736 EXPORT_SYMBOL(ide_proc_unregister_driver);
... ... @@ -817,9 +817,9 @@
817 817 * Locks for IDE setting functionality
818 818 */
819 819  
820   -DECLARE_MUTEX(ide_setting_sem);
  820 +DEFINE_MUTEX(ide_setting_mtx);
821 821  
822   -EXPORT_SYMBOL_GPL(ide_setting_sem);
  822 +EXPORT_SYMBOL_GPL(ide_setting_mtx);
823 823  
824 824 /**
825 825 * ide_spin_wait_hwgroup - wait for group
826 826  
... ... @@ -1192,11 +1192,11 @@
1192 1192 }
1193 1193  
1194 1194 read_val:
1195   - down(&ide_setting_sem);
  1195 + mutex_lock(&ide_setting_mtx);
1196 1196 spin_lock_irqsave(&ide_lock, flags);
1197 1197 err = *val;
1198 1198 spin_unlock_irqrestore(&ide_lock, flags);
1199   - up(&ide_setting_sem);
  1199 + mutex_unlock(&ide_setting_mtx);
1200 1200 return err >= 0 ? put_user(err, (long __user *)arg) : err;
1201 1201  
1202 1202 set_val:
1203 1203  
... ... @@ -1206,9 +1206,9 @@
1206 1206 if (!capable(CAP_SYS_ADMIN))
1207 1207 err = -EACCES;
1208 1208 else {
1209   - down(&ide_setting_sem);
  1209 + mutex_lock(&ide_setting_mtx);
1210 1210 err = setfunc(drive, arg);
1211   - up(&ide_setting_sem);
  1211 + mutex_unlock(&ide_setting_mtx);
1212 1212 }
1213 1213 }
1214 1214 return err;
... ... @@ -25,6 +25,7 @@
25 25 #include <asm/system.h>
26 26 #include <asm/io.h>
27 27 #include <asm/semaphore.h>
  28 +#include <asm/mutex.h>
28 29  
29 30 /******************************************************************************
30 31 * IDE driver configuration options (play with these as desired):
... ... @@ -863,7 +864,7 @@
863 864  
864 865 typedef struct ide_driver_s ide_driver_t;
865 866  
866   -extern struct semaphore ide_setting_sem;
  867 +extern struct mutex ide_setting_mtx;
867 868  
868 869 int set_io_32bit(ide_drive_t *, int);
869 870 int set_pio_mode(ide_drive_t *, int);