aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-ns2.c
diff options
context:
space:
mode:
authorSimon Guinot <sguinot@lacie.com>2010-10-07 10:35:40 -0400
committerNicolas Pitre <nico@fluxnic.net>2010-10-07 14:00:23 -0400
commite5971bbc1caf0ccbab3fea74fe37abb649d1c7cf (patch)
tree727aface2c486bbea7b70f1b587497bad9885771 /drivers/leds/leds-ns2.c
parentb51d92da4ebb52b61fdc99c911171562673e88ef (diff)
leds: leds-ns2: fix private driver data storage
dev_set_drvdata() can't be used to set the driver private data pointer. This would overwrite the led classdev object previously registered by led_classdev_register(). Note that despite this mistake, the driver work fine because led_dat and led_dat->cdev are at the same memory address. Signed-off-by: Simon Guinot <sguinot@lacie.com> Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
Diffstat (limited to 'drivers/leds/leds-ns2.c')
-rw-r--r--drivers/leds/leds-ns2.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 350eb34f049c..f77d48d0b3e4 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -141,10 +141,12 @@ static ssize_t ns2_led_sata_store(struct device *dev,
141 struct device_attribute *attr, 141 struct device_attribute *attr,
142 const char *buff, size_t count) 142 const char *buff, size_t count)
143{ 143{
144 struct led_classdev *led_cdev = dev_get_drvdata(dev);
145 struct ns2_led_data *led_dat =
146 container_of(led_cdev, struct ns2_led_data, cdev);
144 int ret; 147 int ret;
145 unsigned long enable; 148 unsigned long enable;
146 enum ns2_led_modes mode; 149 enum ns2_led_modes mode;
147 struct ns2_led_data *led_dat = dev_get_drvdata(dev);
148 150
149 ret = strict_strtoul(buff, 10, &enable); 151 ret = strict_strtoul(buff, 10, &enable);
150 if (ret < 0) 152 if (ret < 0)
@@ -172,7 +174,9 @@ static ssize_t ns2_led_sata_store(struct device *dev,
172static ssize_t ns2_led_sata_show(struct device *dev, 174static ssize_t ns2_led_sata_show(struct device *dev,
173 struct device_attribute *attr, char *buf) 175 struct device_attribute *attr, char *buf)
174{ 176{
175 struct ns2_led_data *led_dat = dev_get_drvdata(dev); 177 struct led_classdev *led_cdev = dev_get_drvdata(dev);
178 struct ns2_led_data *led_dat =
179 container_of(led_cdev, struct ns2_led_data, cdev);
176 180
177 return sprintf(buf, "%d\n", led_dat->sata); 181 return sprintf(buf, "%d\n", led_dat->sata);
178} 182}
@@ -234,7 +238,6 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
234 if (ret < 0) 238 if (ret < 0)
235 goto err_free_slow; 239 goto err_free_slow;
236 240
237 dev_set_drvdata(led_dat->cdev.dev, led_dat);
238 ret = device_create_file(led_dat->cdev.dev, &dev_attr_sata); 241 ret = device_create_file(led_dat->cdev.dev, &dev_attr_sata);
239 if (ret < 0) 242 if (ret < 0)
240 goto err_free_cdev; 243 goto err_free_cdev;