diff options
author | Atsushi Nemoto <anemo@mba.ocn.ne.jp> | 2009-12-15 19:46:02 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-16 10:19:59 -0500 |
commit | ac18eb622f4d8cdd544222e56230db850259cd37 (patch) | |
tree | 1eea601a9f0f4bbe79d6e0a993cff484238c3da0 /drivers/rtc | |
parent | 618161f71cb10ff9bfe74c9bd766faf339f98274 (diff) |
rtc-ds1742: fix races around device registration
* Call dev_set_drvdata before rtc device creation
* Use devres APIs and simplify error/remove path
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/rtc-ds1742.c | 51 |
1 files changed, 16 insertions, 35 deletions
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c index 09249459e9a..19d2f3333cf 100644 --- a/drivers/rtc/rtc-ds1742.c +++ b/drivers/rtc/rtc-ds1742.c | |||
@@ -21,7 +21,7 @@ | |||
21 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
23 | 23 | ||
24 | #define DRV_VERSION "0.3" | 24 | #define DRV_VERSION "0.4" |
25 | 25 | ||
26 | #define RTC_SIZE 8 | 26 | #define RTC_SIZE 8 |
27 | 27 | ||
@@ -55,7 +55,6 @@ struct rtc_plat_data { | |||
55 | void __iomem *ioaddr_rtc; | 55 | void __iomem *ioaddr_rtc; |
56 | size_t size_nvram; | 56 | size_t size_nvram; |
57 | size_t size; | 57 | size_t size; |
58 | resource_size_t baseaddr; | ||
59 | unsigned long last_jiffies; | 58 | unsigned long last_jiffies; |
60 | struct bin_attribute nvram_attr; | 59 | struct bin_attribute nvram_attr; |
61 | }; | 60 | }; |
@@ -163,27 +162,24 @@ static int __devinit ds1742_rtc_probe(struct platform_device *pdev) | |||
163 | struct rtc_device *rtc; | 162 | struct rtc_device *rtc; |
164 | struct resource *res; | 163 | struct resource *res; |
165 | unsigned int cen, sec; | 164 | unsigned int cen, sec; |
166 | struct rtc_plat_data *pdata = NULL; | 165 | struct rtc_plat_data *pdata; |
167 | void __iomem *ioaddr = NULL; | 166 | void __iomem *ioaddr; |
168 | int ret = 0; | 167 | int ret = 0; |
169 | 168 | ||
170 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 169 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
171 | if (!res) | 170 | if (!res) |
172 | return -ENODEV; | 171 | return -ENODEV; |
173 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); | 172 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
174 | if (!pdata) | 173 | if (!pdata) |
175 | return -ENOMEM; | 174 | return -ENOMEM; |
176 | pdata->size = res->end - res->start + 1; | 175 | pdata->size = res->end - res->start + 1; |
177 | if (!request_mem_region(res->start, pdata->size, pdev->name)) { | 176 | if (!devm_request_mem_region(&pdev->dev, res->start, pdata->size, |
178 | ret = -EBUSY; | 177 | pdev->name)) |
179 | goto out; | 178 | return -EBUSY; |
180 | } | 179 | ioaddr = devm_ioremap(&pdev->dev, res->start, pdata->size); |
181 | pdata->baseaddr = res->start; | 180 | if (!ioaddr) |
182 | ioaddr = ioremap(pdata->baseaddr, pdata->size); | 181 | return -ENOMEM; |
183 | if (!ioaddr) { | 182 | |
184 | ret = -ENOMEM; | ||
185 | goto out; | ||
186 | } | ||
187 | pdata->ioaddr_nvram = ioaddr; | 183 | pdata->ioaddr_nvram = ioaddr; |
188 | pdata->size_nvram = pdata->size - RTC_SIZE; | 184 | pdata->size_nvram = pdata->size - RTC_SIZE; |
189 | pdata->ioaddr_rtc = ioaddr + pdata->size_nvram; | 185 | pdata->ioaddr_rtc = ioaddr + pdata->size_nvram; |
@@ -207,31 +203,19 @@ static int __devinit ds1742_rtc_probe(struct platform_device *pdev) | |||
207 | if (!(readb(ioaddr + RTC_DAY) & RTC_BATT_FLAG)) | 203 | if (!(readb(ioaddr + RTC_DAY) & RTC_BATT_FLAG)) |
208 | dev_warn(&pdev->dev, "voltage-low detected.\n"); | 204 | dev_warn(&pdev->dev, "voltage-low detected.\n"); |
209 | 205 | ||
206 | pdata->last_jiffies = jiffies; | ||
207 | platform_set_drvdata(pdev, pdata); | ||
210 | rtc = rtc_device_register(pdev->name, &pdev->dev, | 208 | rtc = rtc_device_register(pdev->name, &pdev->dev, |
211 | &ds1742_rtc_ops, THIS_MODULE); | 209 | &ds1742_rtc_ops, THIS_MODULE); |
212 | if (IS_ERR(rtc)) { | 210 | if (IS_ERR(rtc)) |
213 | ret = PTR_ERR(rtc); | 211 | return PTR_ERR(rtc); |
214 | goto out; | ||
215 | } | ||
216 | pdata->rtc = rtc; | 212 | pdata->rtc = rtc; |
217 | pdata->last_jiffies = jiffies; | ||
218 | platform_set_drvdata(pdev, pdata); | ||
219 | 213 | ||
220 | ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); | 214 | ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); |
221 | if (ret) { | 215 | if (ret) { |
222 | dev_err(&pdev->dev, "creating nvram file in sysfs failed\n"); | 216 | dev_err(&pdev->dev, "creating nvram file in sysfs failed\n"); |
223 | goto out; | 217 | rtc_device_unregister(rtc); |
224 | } | 218 | } |
225 | |||
226 | return 0; | ||
227 | out: | ||
228 | if (pdata->rtc) | ||
229 | rtc_device_unregister(pdata->rtc); | ||
230 | if (pdata->ioaddr_nvram) | ||
231 | iounmap(pdata->ioaddr_nvram); | ||
232 | if (pdata->baseaddr) | ||
233 | release_mem_region(pdata->baseaddr, pdata->size); | ||
234 | kfree(pdata); | ||
235 | return ret; | 219 | return ret; |
236 | } | 220 | } |
237 | 221 | ||
@@ -241,9 +225,6 @@ static int __devexit ds1742_rtc_remove(struct platform_device *pdev) | |||
241 | 225 | ||
242 | sysfs_remove_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); | 226 | sysfs_remove_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); |
243 | rtc_device_unregister(pdata->rtc); | 227 | rtc_device_unregister(pdata->rtc); |
244 | iounmap(pdata->ioaddr_nvram); | ||
245 | release_mem_region(pdata->baseaddr, pdata->size); | ||
246 | kfree(pdata); | ||
247 | return 0; | 228 | return 0; |
248 | } | 229 | } |
249 | 230 | ||