Commit 249040dc authored by Richard Purdie's avatar Richard Purdie

backlight: Convert semaphore -> mutex

Convert internal semaphore to a mutex
Signed-off-by: default avatarRichard Purdie <rpurdie@rpsys.net>
parent 28ee086d
...@@ -32,14 +32,14 @@ static int fb_notifier_callback(struct notifier_block *self, ...@@ -32,14 +32,14 @@ static int fb_notifier_callback(struct notifier_block *self,
return 0; return 0;
bd = container_of(self, struct backlight_device, fb_notif); bd = container_of(self, struct backlight_device, fb_notif);
down(&bd->sem); mutex_lock(&bd->props_lock);
if (bd->props) if (bd->props)
if (!bd->props->check_fb || if (!bd->props->check_fb ||
bd->props->check_fb(evdata->info)) { bd->props->check_fb(evdata->info)) {
bd->props->fb_blank = *(int *)evdata->data; bd->props->fb_blank = *(int *)evdata->data;
backlight_update_status(bd); backlight_update_status(bd);
} }
up(&bd->sem); mutex_unlock(&bd->props_lock);
return 0; return 0;
} }
...@@ -71,10 +71,10 @@ static ssize_t backlight_show_power(struct class_device *cdev, char *buf) ...@@ -71,10 +71,10 @@ static ssize_t backlight_show_power(struct class_device *cdev, char *buf)
int rc = -ENXIO; int rc = -ENXIO;
struct backlight_device *bd = to_backlight_device(cdev); struct backlight_device *bd = to_backlight_device(cdev);
down(&bd->sem); mutex_lock(&bd->props_lock);
if (bd->props) if (bd->props)
rc = sprintf(buf, "%d\n", bd->props->power); rc = sprintf(buf, "%d\n", bd->props->power);
up(&bd->sem); mutex_unlock(&bd->props_lock);
return rc; return rc;
} }
...@@ -92,14 +92,14 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, ...@@ -92,14 +92,14 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf,
if (size != count) if (size != count)
return -EINVAL; return -EINVAL;
down(&bd->sem); mutex_lock(&bd->props_lock);
if (bd->props) { if (bd->props) {
pr_debug("backlight: set power to %d\n", power); pr_debug("backlight: set power to %d\n", power);
bd->props->power = power; bd->props->power = power;
backlight_update_status(bd); backlight_update_status(bd);
rc = count; rc = count;
} }
up(&bd->sem); mutex_unlock(&bd->props_lock);
return rc; return rc;
} }
...@@ -109,10 +109,10 @@ static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf) ...@@ -109,10 +109,10 @@ static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf)
int rc = -ENXIO; int rc = -ENXIO;
struct backlight_device *bd = to_backlight_device(cdev); struct backlight_device *bd = to_backlight_device(cdev);
down(&bd->sem); mutex_lock(&bd->props_lock);
if (bd->props) if (bd->props)
rc = sprintf(buf, "%d\n", bd->props->brightness); rc = sprintf(buf, "%d\n", bd->props->brightness);
up(&bd->sem); mutex_unlock(&bd->props_lock);
return rc; return rc;
} }
...@@ -130,7 +130,7 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char ...@@ -130,7 +130,7 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char
if (size != count) if (size != count)
return -EINVAL; return -EINVAL;
down(&bd->sem); mutex_lock(&bd->props_lock);
if (bd->props) { if (bd->props) {
if (brightness > bd->props->max_brightness) if (brightness > bd->props->max_brightness)
rc = -EINVAL; rc = -EINVAL;
...@@ -142,7 +142,7 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char ...@@ -142,7 +142,7 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char
rc = count; rc = count;
} }
} }
up(&bd->sem); mutex_unlock(&bd->props_lock);
return rc; return rc;
} }
...@@ -152,10 +152,10 @@ static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *bu ...@@ -152,10 +152,10 @@ static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *bu
int rc = -ENXIO; int rc = -ENXIO;
struct backlight_device *bd = to_backlight_device(cdev); struct backlight_device *bd = to_backlight_device(cdev);
down(&bd->sem); mutex_lock(&bd->props_lock);
if (bd->props) if (bd->props)
rc = sprintf(buf, "%d\n", bd->props->max_brightness); rc = sprintf(buf, "%d\n", bd->props->max_brightness);
up(&bd->sem); mutex_unlock(&bd->props_lock);
return rc; return rc;
} }
...@@ -166,10 +166,10 @@ static ssize_t backlight_show_actual_brightness(struct class_device *cdev, ...@@ -166,10 +166,10 @@ static ssize_t backlight_show_actual_brightness(struct class_device *cdev,
int rc = -ENXIO; int rc = -ENXIO;
struct backlight_device *bd = to_backlight_device(cdev); struct backlight_device *bd = to_backlight_device(cdev);
down(&bd->sem); mutex_lock(&bd->props_lock);
if (bd->props && bd->props->get_brightness) if (bd->props && bd->props->get_brightness)
rc = sprintf(buf, "%d\n", bd->props->get_brightness(bd)); rc = sprintf(buf, "%d\n", bd->props->get_brightness(bd));
up(&bd->sem); mutex_unlock(&bd->props_lock);
return rc; return rc;
} }
...@@ -228,7 +228,7 @@ struct backlight_device *backlight_device_register(const char *name, ...@@ -228,7 +228,7 @@ struct backlight_device *backlight_device_register(const char *name,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
mutex_init(&new_bd->update_lock); mutex_init(&new_bd->update_lock);
init_MUTEX(&new_bd->sem); mutex_init(&new_bd->props_lock);
new_bd->props = bp; new_bd->props = bp;
memset(&new_bd->class_dev, 0, sizeof(new_bd->class_dev)); memset(&new_bd->class_dev, 0, sizeof(new_bd->class_dev));
new_bd->class_dev.class = &backlight_class; new_bd->class_dev.class = &backlight_class;
...@@ -285,9 +285,9 @@ void backlight_device_unregister(struct backlight_device *bd) ...@@ -285,9 +285,9 @@ void backlight_device_unregister(struct backlight_device *bd)
class_device_remove_file(&bd->class_dev, class_device_remove_file(&bd->class_dev,
&bl_class_device_attributes[i]); &bl_class_device_attributes[i]);
down(&bd->sem); mutex_lock(&bd->props_lock);
bd->props = NULL; bd->props = NULL;
up(&bd->sem); mutex_unlock(&bd->props_lock);
backlight_unregister_fb(bd); backlight_unregister_fb(bd);
......
...@@ -31,11 +31,11 @@ static int fb_notifier_callback(struct notifier_block *self, ...@@ -31,11 +31,11 @@ static int fb_notifier_callback(struct notifier_block *self,
return 0; return 0;
ld = container_of(self, struct lcd_device, fb_notif); ld = container_of(self, struct lcd_device, fb_notif);
down(&ld->sem); mutex_lock(&ld->props_lock);
if (ld->props) if (ld->props)
if (!ld->props->check_fb || ld->props->check_fb(evdata->info)) if (!ld->props->check_fb || ld->props->check_fb(evdata->info))
ld->props->set_power(ld, *(int *)evdata->data); ld->props->set_power(ld, *(int *)evdata->data);
up(&ld->sem); mutex_unlock(&ld->props_lock);
return 0; return 0;
} }
...@@ -66,12 +66,12 @@ static ssize_t lcd_show_power(struct class_device *cdev, char *buf) ...@@ -66,12 +66,12 @@ static ssize_t lcd_show_power(struct class_device *cdev, char *buf)
int rc; int rc;
struct lcd_device *ld = to_lcd_device(cdev); struct lcd_device *ld = to_lcd_device(cdev);
down(&ld->sem); mutex_lock(&ld->props_lock);
if (ld->props && ld->props->get_power) if (ld->props && ld->props->get_power)
rc = sprintf(buf, "%d\n", ld->props->get_power(ld)); rc = sprintf(buf, "%d\n", ld->props->get_power(ld));
else else
rc = -ENXIO; rc = -ENXIO;
up(&ld->sem); mutex_unlock(&ld->props_lock);
return rc; return rc;
} }
...@@ -89,13 +89,13 @@ static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_ ...@@ -89,13 +89,13 @@ static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_
if (size != count) if (size != count)
return -EINVAL; return -EINVAL;
down(&ld->sem); mutex_lock(&ld->props_lock);
if (ld->props && ld->props->set_power) { if (ld->props && ld->props->set_power) {
pr_debug("lcd: set power to %d\n", power); pr_debug("lcd: set power to %d\n", power);
ld->props->set_power(ld, power); ld->props->set_power(ld, power);
rc = count; rc = count;
} }
up(&ld->sem); mutex_unlock(&ld->props_lock);
return rc; return rc;
} }
...@@ -105,10 +105,10 @@ static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf) ...@@ -105,10 +105,10 @@ static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf)
int rc = -ENXIO; int rc = -ENXIO;
struct lcd_device *ld = to_lcd_device(cdev); struct lcd_device *ld = to_lcd_device(cdev);
down(&ld->sem); mutex_lock(&ld->props_lock);
if (ld->props && ld->props->get_contrast) if (ld->props && ld->props->get_contrast)
rc = sprintf(buf, "%d\n", ld->props->get_contrast(ld)); rc = sprintf(buf, "%d\n", ld->props->get_contrast(ld));
up(&ld->sem); mutex_unlock(&ld->props_lock);
return rc; return rc;
} }
...@@ -126,13 +126,13 @@ static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, si ...@@ -126,13 +126,13 @@ static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, si
if (size != count) if (size != count)
return -EINVAL; return -EINVAL;
down(&ld->sem); mutex_lock(&ld->props_lock);
if (ld->props && ld->props->set_contrast) { if (ld->props && ld->props->set_contrast) {
pr_debug("lcd: set contrast to %d\n", contrast); pr_debug("lcd: set contrast to %d\n", contrast);
ld->props->set_contrast(ld, contrast); ld->props->set_contrast(ld, contrast);
rc = count; rc = count;
} }
up(&ld->sem); mutex_unlock(&ld->props_lock);
return rc; return rc;
} }
...@@ -142,10 +142,10 @@ static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf) ...@@ -142,10 +142,10 @@ static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf)
int rc = -ENXIO; int rc = -ENXIO;
struct lcd_device *ld = to_lcd_device(cdev); struct lcd_device *ld = to_lcd_device(cdev);
down(&ld->sem); mutex_lock(&ld->props_lock);
if (ld->props) if (ld->props)
rc = sprintf(buf, "%d\n", ld->props->max_contrast); rc = sprintf(buf, "%d\n", ld->props->max_contrast);
up(&ld->sem); mutex_unlock(&ld->props_lock);
return rc; return rc;
} }
...@@ -197,7 +197,7 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata, ...@@ -197,7 +197,7 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata,
if (!new_ld) if (!new_ld)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
init_MUTEX(&new_ld->sem); mutex_init(&new_ld->props_lock);
mutex_init(&new_ld->update_lock); mutex_init(&new_ld->update_lock);
new_ld->props = lp; new_ld->props = lp;
memset(&new_ld->class_dev, 0, sizeof(new_ld->class_dev)); memset(&new_ld->class_dev, 0, sizeof(new_ld->class_dev));
...@@ -253,9 +253,9 @@ void lcd_device_unregister(struct lcd_device *ld) ...@@ -253,9 +253,9 @@ void lcd_device_unregister(struct lcd_device *ld)
class_device_remove_file(&ld->class_dev, class_device_remove_file(&ld->class_dev,
&lcd_class_device_attributes[i]); &lcd_class_device_attributes[i]);
down(&ld->sem); mutex_lock(&ld->props_lock);
ld->props = NULL; ld->props = NULL;
up(&ld->sem); mutex_unlock(&ld->props_lock);
lcd_unregister_fb(ld); lcd_unregister_fb(ld);
class_device_unregister(&ld->class_dev); class_device_unregister(&ld->class_dev);
} }
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
/* Notes on locking: /* Notes on locking:
* *
* backlight_device->sem is an internal backlight lock protecting the props * backlight_device->props_lock is an internal backlight lock protecting the
* field and no code outside the core should need to touch it. * props field and no code outside the core should need to touch it.
* *
* Access to update_status() is serialised by the update_lock mutex since * Access to update_status() is serialised by the update_lock mutex since
* most drivers seem to need this and historically get it wrong. * most drivers seem to need this and historically get it wrong.
...@@ -57,7 +57,7 @@ struct backlight_device { ...@@ -57,7 +57,7 @@ struct backlight_device {
/* This protects the 'props' field. If 'props' is NULL, the driver that /* This protects the 'props' field. If 'props' is NULL, the driver that
registered this device has been unloaded, and if class_get_devdata() registered this device has been unloaded, and if class_get_devdata()
points to something in the body of that driver, it is also invalid. */ points to something in the body of that driver, it is also invalid. */
struct semaphore sem; struct mutex props_lock;
/* If this is NULL, the backing module is unloaded */ /* If this is NULL, the backing module is unloaded */
struct backlight_properties *props; struct backlight_properties *props;
/* Serialise access to update_status method */ /* Serialise access to update_status method */
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
/* Notes on locking: /* Notes on locking:
* *
* lcd_device->sem is an internal backlight lock protecting the props * lcd_device->props_lock is an internal backlight lock protecting the props
* field and no code outside the core should need to touch it. * field and no code outside the core should need to touch it.
* *
* Access to set_power() is serialised by the update_lock mutex since * Access to set_power() is serialised by the update_lock mutex since
...@@ -52,7 +52,7 @@ struct lcd_device { ...@@ -52,7 +52,7 @@ struct lcd_device {
/* This protects the 'props' field. If 'props' is NULL, the driver that /* This protects the 'props' field. If 'props' is NULL, the driver that
registered this device has been unloaded, and if class_get_devdata() registered this device has been unloaded, and if class_get_devdata()
points to something in the body of that driver, it is also invalid. */ points to something in the body of that driver, it is also invalid. */
struct semaphore sem; struct mutex props_lock;
/* If this is NULL, the backing module is unloaded */ /* If this is NULL, the backing module is unloaded */
struct lcd_properties *props; struct lcd_properties *props;
/* Serialise access to set_power method */ /* Serialise access to set_power method */
......
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