Commit f9383c42 authored by Matthias Kaehlcke's avatar Matthias Kaehlcke Committed by Bartlomiej Zolnierkiewicz

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: default avatarMatthias Kaehlcke <matthias.kaehlcke@gmail.com>
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>

--
parent 1b9da32a
...@@ -1190,11 +1190,11 @@ static int idedisk_ioctl(struct inode *inode, struct file *file, ...@@ -1190,11 +1190,11 @@ static int idedisk_ioctl(struct inode *inode, struct file *file,
return generic_ide_ioctl(drive, file, bdev, cmd, arg); return generic_ide_ioctl(drive, file, bdev, cmd, arg);
read_val: read_val:
down(&ide_setting_sem); mutex_lock(&ide_setting_mtx);
spin_lock_irqsave(&ide_lock, flags); spin_lock_irqsave(&ide_lock, flags);
err = *val; err = *val;
spin_unlock_irqrestore(&ide_lock, flags); spin_unlock_irqrestore(&ide_lock, flags);
up(&ide_setting_sem); mutex_unlock(&ide_setting_mtx);
return err >= 0 ? put_user(err, (long __user *)arg) : err; return err >= 0 ? put_user(err, (long __user *)arg) : err;
set_val: set_val:
...@@ -1204,9 +1204,9 @@ static int idedisk_ioctl(struct inode *inode, struct file *file, ...@@ -1204,9 +1204,9 @@ static int idedisk_ioctl(struct inode *inode, struct file *file,
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
err = -EACCES; err = -EACCES;
else { else {
down(&ide_setting_sem); mutex_lock(&ide_setting_mtx);
err = setfunc(drive, arg); err = setfunc(drive, arg);
up(&ide_setting_sem); mutex_unlock(&ide_setting_mtx);
} }
} }
return err; return err;
......
...@@ -156,7 +156,7 @@ static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int d ...@@ -156,7 +156,7 @@ static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int d
{ {
ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL; ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
down(&ide_setting_sem); mutex_lock(&ide_setting_mtx);
while ((*p) && strcmp((*p)->name, name) < 0) while ((*p) && strcmp((*p)->name, name) < 0)
p = &((*p)->next); p = &((*p)->next);
if ((setting = kzalloc(sizeof(*setting), GFP_KERNEL)) == NULL) if ((setting = kzalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
...@@ -177,10 +177,10 @@ static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int d ...@@ -177,10 +177,10 @@ static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int d
if (auto_remove) if (auto_remove)
setting->auto_remove = 1; setting->auto_remove = 1;
*p = setting; *p = setting;
up(&ide_setting_sem); mutex_unlock(&ide_setting_mtx);
return 0; return 0;
abort: abort:
up(&ide_setting_sem); mutex_unlock(&ide_setting_mtx);
kfree(setting); kfree(setting);
return -1; return -1;
} }
...@@ -224,7 +224,7 @@ static void __ide_remove_setting (ide_drive_t *drive, char *name) ...@@ -224,7 +224,7 @@ static void __ide_remove_setting (ide_drive_t *drive, char *name)
* *
* Automatically remove all the driver specific settings for this * Automatically remove all the driver specific settings for this
* drive. This function may not be called from IRQ context. The * drive. This function may not be called from IRQ context. The
* caller must hold ide_setting_sem. * caller must hold ide_setting_mtx.
*/ */
static void auto_remove_settings (ide_drive_t *drive) static void auto_remove_settings (ide_drive_t *drive)
...@@ -269,7 +269,7 @@ static ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name) ...@@ -269,7 +269,7 @@ static ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name)
* @setting: drive setting * @setting: drive setting
* *
* Read a drive setting and return the value. The caller * Read a drive setting and return the value. The caller
* must hold the ide_setting_sem when making this call. * must hold the ide_setting_mtx when making this call.
* *
* BUGS: the data return and error are the same return value * BUGS: the data return and error are the same return value
* so an error -EINVAL and true return of the same value cannot * so an error -EINVAL and true return of the same value cannot
...@@ -306,7 +306,7 @@ static int ide_read_setting(ide_drive_t *drive, ide_settings_t *setting) ...@@ -306,7 +306,7 @@ static int ide_read_setting(ide_drive_t *drive, ide_settings_t *setting)
* @val: value * @val: value
* *
* Write a drive setting if it is possible. The caller * Write a drive setting if it is possible. The caller
* must hold the ide_setting_sem when making this call. * must hold the ide_setting_mtx when making this call.
* *
* BUGS: the data return and error are the same return value * BUGS: the data return and error are the same return value
* so an error -EINVAL and true return of the same value cannot * so an error -EINVAL and true return of the same value cannot
...@@ -367,7 +367,7 @@ static int set_xfer_rate (ide_drive_t *drive, int arg) ...@@ -367,7 +367,7 @@ static int set_xfer_rate (ide_drive_t *drive, int arg)
* @drive: drive being configured * @drive: drive being configured
* *
* Add the generic parts of the system settings to the /proc files. * Add the generic parts of the system settings to the /proc files.
* The caller must not be holding the ide_setting_sem. * The caller must not be holding the ide_setting_mtx.
*/ */
void ide_add_generic_settings (ide_drive_t *drive) void ide_add_generic_settings (ide_drive_t *drive)
...@@ -408,7 +408,7 @@ static int proc_ide_read_settings ...@@ -408,7 +408,7 @@ static int proc_ide_read_settings
proc_ide_settings_warn(); proc_ide_settings_warn();
down(&ide_setting_sem); mutex_lock(&ide_setting_mtx);
out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n"); out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n"); out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
while(setting) { while(setting) {
...@@ -428,7 +428,7 @@ static int proc_ide_read_settings ...@@ -428,7 +428,7 @@ static int proc_ide_read_settings
setting = setting->next; setting = setting->next;
} }
len = out - page; len = out - page;
up(&ide_setting_sem); mutex_unlock(&ide_setting_mtx);
PROC_IDE_READ_RETURN(page,start,off,count,eof,len); PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
} }
...@@ -508,16 +508,16 @@ static int proc_ide_write_settings(struct file *file, const char __user *buffer, ...@@ -508,16 +508,16 @@ static int proc_ide_write_settings(struct file *file, const char __user *buffer,
++p; ++p;
} }
down(&ide_setting_sem); mutex_lock(&ide_setting_mtx);
setting = ide_find_setting_by_name(drive, name); setting = ide_find_setting_by_name(drive, name);
if (!setting) if (!setting)
{ {
up(&ide_setting_sem); mutex_unlock(&ide_setting_mtx);
goto parse_error; goto parse_error;
} }
if (for_real) if (for_real)
ide_write_setting(drive, setting, val * setting->div_factor / setting->mul_factor); ide_write_setting(drive, setting, val * setting->div_factor / setting->mul_factor);
up(&ide_setting_sem); mutex_unlock(&ide_setting_mtx);
} }
} while (!for_real++); } while (!for_real++);
free_page((unsigned long)buf); free_page((unsigned long)buf);
...@@ -705,7 +705,7 @@ EXPORT_SYMBOL(ide_proc_register_driver); ...@@ -705,7 +705,7 @@ EXPORT_SYMBOL(ide_proc_register_driver);
* Clean up the driver specific /proc files and IDE settings * Clean up the driver specific /proc files and IDE settings
* for a given drive. * for a given drive.
* *
* Takes ide_setting_sem and ide_lock. * Takes ide_setting_mtx and ide_lock.
* Caller must hold none of the locks. * Caller must hold none of the locks.
*/ */
...@@ -715,10 +715,10 @@ void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver) ...@@ -715,10 +715,10 @@ void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver)
ide_remove_proc_entries(drive->proc, driver->proc); ide_remove_proc_entries(drive->proc, driver->proc);
down(&ide_setting_sem); mutex_lock(&ide_setting_mtx);
spin_lock_irqsave(&ide_lock, flags); spin_lock_irqsave(&ide_lock, flags);
/* /*
* ide_setting_sem protects the settings list * ide_setting_mtx protects the settings list
* ide_lock protects the use of settings * ide_lock protects the use of settings
* *
* so we need to hold both, ide_settings_sem because we want to * so we need to hold both, ide_settings_sem because we want to
...@@ -726,11 +726,11 @@ void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver) ...@@ -726,11 +726,11 @@ void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver)
* a setting out that is being used. * a setting out that is being used.
* *
* OTOH both ide_{read,write}_setting are only ever used under * OTOH both ide_{read,write}_setting are only ever used under
* ide_setting_sem. * ide_setting_mtx.
*/ */
auto_remove_settings(drive); auto_remove_settings(drive);
spin_unlock_irqrestore(&ide_lock, flags); spin_unlock_irqrestore(&ide_lock, flags);
up(&ide_setting_sem); mutex_unlock(&ide_setting_mtx);
} }
EXPORT_SYMBOL(ide_proc_unregister_driver); EXPORT_SYMBOL(ide_proc_unregister_driver);
......
...@@ -817,9 +817,9 @@ EXPORT_SYMBOL(ide_register_hw); ...@@ -817,9 +817,9 @@ EXPORT_SYMBOL(ide_register_hw);
* Locks for IDE setting functionality * Locks for IDE setting functionality
*/ */
DECLARE_MUTEX(ide_setting_sem); DEFINE_MUTEX(ide_setting_mtx);
EXPORT_SYMBOL_GPL(ide_setting_sem); EXPORT_SYMBOL_GPL(ide_setting_mtx);
/** /**
* ide_spin_wait_hwgroup - wait for group * ide_spin_wait_hwgroup - wait for group
...@@ -1192,11 +1192,11 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device ...@@ -1192,11 +1192,11 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
} }
read_val: read_val:
down(&ide_setting_sem); mutex_lock(&ide_setting_mtx);
spin_lock_irqsave(&ide_lock, flags); spin_lock_irqsave(&ide_lock, flags);
err = *val; err = *val;
spin_unlock_irqrestore(&ide_lock, flags); spin_unlock_irqrestore(&ide_lock, flags);
up(&ide_setting_sem); mutex_unlock(&ide_setting_mtx);
return err >= 0 ? put_user(err, (long __user *)arg) : err; return err >= 0 ? put_user(err, (long __user *)arg) : err;
set_val: set_val:
...@@ -1206,9 +1206,9 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device ...@@ -1206,9 +1206,9 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
err = -EACCES; err = -EACCES;
else { else {
down(&ide_setting_sem); mutex_lock(&ide_setting_mtx);
err = setfunc(drive, arg); err = setfunc(drive, arg);
up(&ide_setting_sem); mutex_unlock(&ide_setting_mtx);
} }
} }
return err; return err;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <asm/system.h> #include <asm/system.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/semaphore.h> #include <asm/semaphore.h>
#include <asm/mutex.h>
/****************************************************************************** /******************************************************************************
* IDE driver configuration options (play with these as desired): * IDE driver configuration options (play with these as desired):
...@@ -863,7 +864,7 @@ typedef struct hwgroup_s { ...@@ -863,7 +864,7 @@ typedef struct hwgroup_s {
typedef struct ide_driver_s ide_driver_t; typedef struct ide_driver_s ide_driver_t;
extern struct semaphore ide_setting_sem; extern struct mutex ide_setting_mtx;
int set_io_32bit(ide_drive_t *, int); int set_io_32bit(ide_drive_t *, int);
int set_pio_mode(ide_drive_t *, int); int set_pio_mode(ide_drive_t *, int);
......
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