Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: fix driver data issues in several rtc drivers

Herton Ronaldo Krzesinski recently raised up, and fixed, an issue with the
rtc_cmos driver, which was referring to an inconsistent driver data.

This patch ensures that driver data registration happens before
rtc_device_register().

Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Acked-by: Thomas Hommel <thomas.hommel@gefanuc.com>
Acked-by: Hans-Christian Egtvedt <hcegtvedt@atmel.com>
Acked-by: Paul Mundt <lethal@linux-sh.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Andrew Sharp <andy.sharp@onstor.com>
Cc: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: Alexander Bigga <ab@mycable.de>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Mark Zhan <rongkai.zhan@windriver.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Alessandro Zummo and committed by
Linus Torvalds
b74d2caa d1b2efa8

+44 -44
+3 -1
drivers/rtc/rtc-at32ap700x.c
··· 256 256 goto out_iounmap; 257 257 } 258 258 259 + platform_set_drvdata(pdev, rtc); 260 + 259 261 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 260 262 &at32_rtc_ops, THIS_MODULE); 261 263 if (IS_ERR(rtc->rtc)) { ··· 266 264 goto out_free_irq; 267 265 } 268 266 269 - platform_set_drvdata(pdev, rtc); 270 267 device_init_wakeup(&pdev->dev, 1); 271 268 272 269 dev_info(&pdev->dev, "Atmel RTC for AT32AP700x at %08lx irq %ld\n", ··· 274 273 return 0; 275 274 276 275 out_free_irq: 276 + platform_set_drvdata(pdev, NULL); 277 277 free_irq(irq, rtc); 278 278 out_iounmap: 279 279 iounmap(rtc->regs);
+2 -1
drivers/rtc/rtc-bq4802.c
··· 169 169 goto out_free; 170 170 } 171 171 172 + platform_set_drvdata(pdev, p); 173 + 172 174 p->rtc = rtc_device_register("bq4802", &pdev->dev, 173 175 &bq4802_ops, THIS_MODULE); 174 176 if (IS_ERR(p->rtc)) { ··· 178 176 goto out_iounmap; 179 177 } 180 178 181 - platform_set_drvdata(pdev, p); 182 179 err = 0; 183 180 out: 184 181 return err;
-1
drivers/rtc/rtc-ds1302.c
··· 143 143 #ifdef RTC_SET_CHARGE 144 144 case RTC_SET_CHARGE: 145 145 { 146 - struct ds1302_rtc *rtc = dev_get_drvdata(dev); 147 146 int tcs_val; 148 147 149 148 if (copy_from_user(&tcs_val, (int __user *)arg, sizeof(int)))
+6 -8
drivers/rtc/rtc-ds1305.c
··· 617 617 static int __devinit ds1305_probe(struct spi_device *spi) 618 618 { 619 619 struct ds1305 *ds1305; 620 - struct rtc_device *rtc; 621 620 int status; 622 621 u8 addr, value; 623 622 struct ds1305_platform_data *pdata = spi->dev.platform_data; ··· 755 756 dev_dbg(&spi->dev, "AM/PM\n"); 756 757 757 758 /* register RTC ... from here on, ds1305->ctrl needs locking */ 758 - rtc = rtc_device_register("ds1305", &spi->dev, 759 + ds1305->rtc = rtc_device_register("ds1305", &spi->dev, 759 760 &ds1305_ops, THIS_MODULE); 760 - if (IS_ERR(rtc)) { 761 - status = PTR_ERR(rtc); 761 + if (IS_ERR(ds1305->rtc)) { 762 + status = PTR_ERR(ds1305->rtc); 762 763 dev_dbg(&spi->dev, "register rtc --> %d\n", status); 763 764 goto fail0; 764 765 } 765 - ds1305->rtc = rtc; 766 766 767 767 /* Maybe set up alarm IRQ; be ready to handle it triggering right 768 768 * away. NOTE that we don't share this. The signal is active low, ··· 772 774 if (spi->irq) { 773 775 INIT_WORK(&ds1305->work, ds1305_work); 774 776 status = request_irq(spi->irq, ds1305_irq, 775 - 0, dev_name(&rtc->dev), ds1305); 777 + 0, dev_name(&ds1305->rtc->dev), ds1305); 776 778 if (status < 0) { 777 779 dev_dbg(&spi->dev, "request_irq %d --> %d\n", 778 780 spi->irq, status); ··· 792 794 fail2: 793 795 free_irq(spi->irq, ds1305); 794 796 fail1: 795 - rtc_device_unregister(rtc); 797 + rtc_device_unregister(ds1305->rtc); 796 798 fail0: 797 799 kfree(ds1305); 798 800 return status; ··· 800 802 801 803 static int __devexit ds1305_remove(struct spi_device *spi) 802 804 { 803 - struct ds1305 *ds1305 = spi_get_drvdata(spi); 805 + struct ds1305 *ds1305 = spi_get_drvdata(spi); 804 806 805 807 sysfs_remove_bin_file(&spi->dev.kobj, &nvram); 806 808
+8 -8
drivers/rtc/rtc-m48t35.c
··· 142 142 143 143 static int __devinit m48t35_probe(struct platform_device *pdev) 144 144 { 145 - struct rtc_device *rtc; 146 145 struct resource *res; 147 146 struct m48t35_priv *priv; 148 147 int ret = 0; ··· 170 171 ret = -ENOMEM; 171 172 goto out; 172 173 } 174 + 173 175 spin_lock_init(&priv->lock); 174 - rtc = rtc_device_register("m48t35", &pdev->dev, 176 + 177 + platform_set_drvdata(pdev, priv); 178 + 179 + priv->rtc = rtc_device_register("m48t35", &pdev->dev, 175 180 &m48t35_ops, THIS_MODULE); 176 - if (IS_ERR(rtc)) { 177 - ret = PTR_ERR(rtc); 181 + if (IS_ERR(priv->rtc)) { 182 + ret = PTR_ERR(priv->rtc); 178 183 goto out; 179 184 } 180 - priv->rtc = rtc; 181 - platform_set_drvdata(pdev, priv); 185 + 182 186 return 0; 183 187 184 188 out: 185 - if (priv->rtc) 186 - rtc_device_unregister(priv->rtc); 187 189 if (priv->reg) 188 190 iounmap(priv->reg); 189 191 if (priv->baseaddr)
+6 -5
drivers/rtc/rtc-m48t59.c
··· 481 481 goto out; 482 482 } 483 483 484 + spin_lock_init(&m48t59->lock); 485 + platform_set_drvdata(pdev, m48t59); 486 + 484 487 m48t59->rtc = rtc_device_register(name, &pdev->dev, ops, THIS_MODULE); 485 488 if (IS_ERR(m48t59->rtc)) { 486 489 ret = PTR_ERR(m48t59->rtc); ··· 493 490 m48t59_nvram_attr.size = pdata->offset; 494 491 495 492 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr); 496 - if (ret) 493 + if (ret) { 494 + rtc_device_unregister(m48t59->rtc); 497 495 goto out; 496 + } 498 497 499 - spin_lock_init(&m48t59->lock); 500 - platform_set_drvdata(pdev, m48t59); 501 498 return 0; 502 499 503 500 out: 504 - if (!IS_ERR(m48t59->rtc)) 505 - rtc_device_unregister(m48t59->rtc); 506 501 if (m48t59->irq != NO_IRQ) 507 502 free_irq(m48t59->irq, &pdev->dev); 508 503 if (m48t59->ioaddr)
+2 -2
drivers/rtc/rtc-pcf8563.c
··· 212 212 213 213 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 214 214 215 + i2c_set_clientdata(client, pcf8563); 216 + 215 217 pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name, 216 218 &client->dev, &pcf8563_rtc_ops, THIS_MODULE); 217 219 ··· 221 219 err = PTR_ERR(pcf8563->rtc); 222 220 goto exit_kfree; 223 221 } 224 - 225 - i2c_set_clientdata(client, pcf8563); 226 222 227 223 return 0; 228 224
+2 -1
drivers/rtc/rtc-pcf8583.c
··· 277 277 if (!pcf8583) 278 278 return -ENOMEM; 279 279 280 + i2c_set_clientdata(client, pcf8583); 281 + 280 282 pcf8583->rtc = rtc_device_register(pcf8583_driver.driver.name, 281 283 &client->dev, &pcf8583_rtc_ops, THIS_MODULE); 282 284 ··· 287 285 goto exit_kfree; 288 286 } 289 287 290 - i2c_set_clientdata(client, pcf8583); 291 288 return 0; 292 289 293 290 exit_kfree:
+12 -12
drivers/rtc/rtc-stk17ta8.c
··· 288 288 289 289 static int __devinit stk17ta8_rtc_probe(struct platform_device *pdev) 290 290 { 291 - struct rtc_device *rtc; 292 291 struct resource *res; 293 292 unsigned int cal; 294 293 unsigned int flags; ··· 337 338 } 338 339 } 339 340 340 - rtc = rtc_device_register(pdev->name, &pdev->dev, 341 - &stk17ta8_rtc_ops, THIS_MODULE); 342 - if (IS_ERR(rtc)) { 343 - ret = PTR_ERR(rtc); 344 - goto out; 345 - } 346 - pdata->rtc = rtc; 347 341 pdata->last_jiffies = jiffies; 348 342 platform_set_drvdata(pdev, pdata); 349 - ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); 350 - if (ret) 343 + 344 + pdata->rtc = rtc_device_register(pdev->name, &pdev->dev, 345 + &stk17ta8_rtc_ops, THIS_MODULE); 346 + if (IS_ERR(pdata->rtc)) { 347 + ret = PTR_ERR(pdata->rtc); 351 348 goto out; 349 + } 350 + 351 + ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); 352 + if (ret) { 353 + rtc_device_unregister(pdata->rtc); 354 + goto out; 355 + } 352 356 return 0; 353 357 out: 354 - if (pdata->rtc) 355 - rtc_device_unregister(pdata->rtc); 356 358 if (pdata->irq > 0) 357 359 free_irq(pdata->irq, pdev); 358 360 if (ioaddr)
+3 -5
drivers/rtc/rtc-v3020.c
··· 304 304 { 305 305 struct v3020_platform_data *pdata = pdev->dev.platform_data; 306 306 struct v3020 *chip; 307 - struct rtc_device *rtc; 308 307 int retval = -EBUSY; 309 308 int i; 310 309 int temp; ··· 352 353 353 354 platform_set_drvdata(pdev, chip); 354 355 355 - rtc = rtc_device_register("v3020", 356 + chip->rtc = rtc_device_register("v3020", 356 357 &pdev->dev, &v3020_rtc_ops, THIS_MODULE); 357 - if (IS_ERR(rtc)) { 358 - retval = PTR_ERR(rtc); 358 + if (IS_ERR(chip->rtc)) { 359 + retval = PTR_ERR(chip->rtc); 359 360 goto err_io; 360 361 } 361 - chip->rtc = rtc; 362 362 363 363 return 0; 364 364