Commit f254bea4 authored by Johan Hovold's avatar Johan Hovold Committed by Bryan Wu

input: lm8323: fix attribute-creation race

Use the attribute groups of the led-class to create the time attribute
during probe in order to avoid racing with userspace.
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Acked-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarBryan Wu <cooloney@gmail.com>
parent b2015ed5
...@@ -558,6 +558,12 @@ static ssize_t lm8323_pwm_store_time(struct device *dev, ...@@ -558,6 +558,12 @@ static ssize_t lm8323_pwm_store_time(struct device *dev,
} }
static DEVICE_ATTR(time, 0644, lm8323_pwm_show_time, lm8323_pwm_store_time); static DEVICE_ATTR(time, 0644, lm8323_pwm_show_time, lm8323_pwm_store_time);
static struct attribute *lm8323_pwm_attrs[] = {
&dev_attr_time.attr,
NULL
};
ATTRIBUTE_GROUPS(lm8323_pwm);
static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev, static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev,
const char *name) const char *name)
{ {
...@@ -580,16 +586,11 @@ static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev, ...@@ -580,16 +586,11 @@ static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev,
if (name) { if (name) {
pwm->cdev.name = name; pwm->cdev.name = name;
pwm->cdev.brightness_set = lm8323_pwm_set_brightness; pwm->cdev.brightness_set = lm8323_pwm_set_brightness;
pwm->cdev.groups = lm8323_pwm_groups;
if (led_classdev_register(dev, &pwm->cdev) < 0) { if (led_classdev_register(dev, &pwm->cdev) < 0) {
dev_err(dev, "couldn't register PWM %d\n", id); dev_err(dev, "couldn't register PWM %d\n", id);
return -1; return -1;
} }
if (device_create_file(pwm->cdev.dev,
&dev_attr_time) < 0) {
dev_err(dev, "couldn't register time attribute\n");
led_classdev_unregister(&pwm->cdev);
return -1;
}
pwm->enabled = true; pwm->enabled = true;
} }
...@@ -753,11 +754,8 @@ static int lm8323_probe(struct i2c_client *client, ...@@ -753,11 +754,8 @@ static int lm8323_probe(struct i2c_client *client,
device_remove_file(&client->dev, &dev_attr_disable_kp); device_remove_file(&client->dev, &dev_attr_disable_kp);
fail2: fail2:
while (--pwm >= 0) while (--pwm >= 0)
if (lm->pwm[pwm].enabled) { if (lm->pwm[pwm].enabled)
device_remove_file(lm->pwm[pwm].cdev.dev,
&dev_attr_time);
led_classdev_unregister(&lm->pwm[pwm].cdev); led_classdev_unregister(&lm->pwm[pwm].cdev);
}
fail1: fail1:
input_free_device(idev); input_free_device(idev);
kfree(lm); kfree(lm);
...@@ -777,10 +775,8 @@ static int lm8323_remove(struct i2c_client *client) ...@@ -777,10 +775,8 @@ static int lm8323_remove(struct i2c_client *client)
device_remove_file(&lm->client->dev, &dev_attr_disable_kp); device_remove_file(&lm->client->dev, &dev_attr_disable_kp);
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
if (lm->pwm[i].enabled) { if (lm->pwm[i].enabled)
device_remove_file(lm->pwm[i].cdev.dev, &dev_attr_time);
led_classdev_unregister(&lm->pwm[i].cdev); led_classdev_unregister(&lm->pwm[i].cdev);
}
kfree(lm); kfree(lm);
......
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