Commit 4071ea25 authored by Alessandro Zummo's avatar Alessandro Zummo Committed by Linus Torvalds

rtc: fix potential race condition

RTC drivers must not return an error after device registration.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: default avatarAlessandro Zummo <a.zummo@towertech.it>
Reported-by: default avatarAles Novak <alnovak@suse.cz>
Cc: Alexander Shiyan <shc_work@mail.ru>
Cc: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Srikanth Srinivasan <srikanth.srinivasan@freescale.com>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a68b3108
...@@ -756,19 +756,17 @@ static int ds1305_probe(struct spi_device *spi) ...@@ -756,19 +756,17 @@ static int ds1305_probe(struct spi_device *spi)
status = devm_request_irq(&spi->dev, spi->irq, ds1305_irq, status = devm_request_irq(&spi->dev, spi->irq, ds1305_irq,
0, dev_name(&ds1305->rtc->dev), ds1305); 0, dev_name(&ds1305->rtc->dev), ds1305);
if (status < 0) { if (status < 0) {
dev_dbg(&spi->dev, "request_irq %d --> %d\n", dev_err(&spi->dev, "request_irq %d --> %d\n",
spi->irq, status); spi->irq, status);
return status; } else {
device_set_wakeup_capable(&spi->dev, 1);
} }
device_set_wakeup_capable(&spi->dev, 1);
} }
/* export NVRAM */ /* export NVRAM */
status = sysfs_create_bin_file(&spi->dev.kobj, &nvram); status = sysfs_create_bin_file(&spi->dev.kobj, &nvram);
if (status < 0) { if (status < 0) {
dev_dbg(&spi->dev, "register nvram --> %d\n", status); dev_err(&spi->dev, "register nvram --> %d\n", status);
return status;
} }
return 0; return 0;
......
...@@ -930,52 +930,58 @@ static int ds1307_probe(struct i2c_client *client, ...@@ -930,52 +930,58 @@ static int ds1307_probe(struct i2c_client *client,
ds1307->rtc = devm_rtc_device_register(&client->dev, client->name, ds1307->rtc = devm_rtc_device_register(&client->dev, client->name,
&ds13xx_rtc_ops, THIS_MODULE); &ds13xx_rtc_ops, THIS_MODULE);
if (IS_ERR(ds1307->rtc)) { if (IS_ERR(ds1307->rtc)) {
err = PTR_ERR(ds1307->rtc); return PTR_ERR(ds1307->rtc);
dev_err(&client->dev,
"unable to register the class device\n");
goto exit;
} }
if (want_irq) { if (want_irq) {
err = request_irq(client->irq, ds1307_irq, IRQF_SHARED, err = request_irq(client->irq, ds1307_irq, IRQF_SHARED,
ds1307->rtc->name, client); ds1307->rtc->name, client);
if (err) { if (err) {
dev_err(&client->dev, client->irq = 0;
"unable to request IRQ!\n"); dev_err(&client->dev, "unable to request IRQ!\n");
goto exit; } else {
}
device_set_wakeup_capable(&client->dev, 1); device_set_wakeup_capable(&client->dev, 1);
set_bit(HAS_ALARM, &ds1307->flags); set_bit(HAS_ALARM, &ds1307->flags);
dev_dbg(&client->dev, "got IRQ %d\n", client->irq); dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
}
} }
if (chip->nvram_size) { if (chip->nvram_size) {
ds1307->nvram = devm_kzalloc(&client->dev, ds1307->nvram = devm_kzalloc(&client->dev,
sizeof(struct bin_attribute), sizeof(struct bin_attribute),
GFP_KERNEL); GFP_KERNEL);
if (!ds1307->nvram) { if (!ds1307->nvram) {
err = -ENOMEM; dev_err(&client->dev, "cannot allocate memory for nvram sysfs\n");
goto err_irq; } else {
ds1307->nvram->attr.name = "nvram";
ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR;
sysfs_bin_attr_init(ds1307->nvram);
ds1307->nvram->read = ds1307_nvram_read;
ds1307->nvram->write = ds1307_nvram_write;
ds1307->nvram->size = chip->nvram_size;
ds1307->nvram_offset = chip->nvram_offset;
err = sysfs_create_bin_file(&client->dev.kobj,
ds1307->nvram);
if (err) {
dev_err(&client->dev,
"unable to create sysfs file: %s\n",
ds1307->nvram->attr.name);
} else {
set_bit(HAS_NVRAM, &ds1307->flags);
dev_info(&client->dev, "%zu bytes nvram\n",
ds1307->nvram->size);
}
} }
ds1307->nvram->attr.name = "nvram";
ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR;
sysfs_bin_attr_init(ds1307->nvram);
ds1307->nvram->read = ds1307_nvram_read;
ds1307->nvram->write = ds1307_nvram_write;
ds1307->nvram->size = chip->nvram_size;
ds1307->nvram_offset = chip->nvram_offset;
err = sysfs_create_bin_file(&client->dev.kobj, ds1307->nvram);
if (err)
goto err_irq;
set_bit(HAS_NVRAM, &ds1307->flags);
dev_info(&client->dev, "%zu bytes nvram\n", ds1307->nvram->size);
} }
return 0; return 0;
err_irq:
free_irq(client->irq, client);
exit: exit:
return err; return err;
} }
......
...@@ -473,7 +473,6 @@ static struct bin_attribute ds1511_nvram_attr = { ...@@ -473,7 +473,6 @@ static struct bin_attribute ds1511_nvram_attr = {
static int ds1511_rtc_probe(struct platform_device *pdev) static int ds1511_rtc_probe(struct platform_device *pdev)
{ {
struct rtc_device *rtc;
struct resource *res; struct resource *res;
struct rtc_plat_data *pdata; struct rtc_plat_data *pdata;
int ret = 0; int ret = 0;
...@@ -512,6 +511,12 @@ static int ds1511_rtc_probe(struct platform_device *pdev) ...@@ -512,6 +511,12 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
spin_lock_init(&pdata->lock); spin_lock_init(&pdata->lock);
platform_set_drvdata(pdev, pdata); platform_set_drvdata(pdev, pdata);
pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
&ds1511_rtc_ops, THIS_MODULE);
if (IS_ERR(pdata->rtc))
return PTR_ERR(pdata->rtc);
/* /*
* if the platform has an interrupt in mind for this device, * if the platform has an interrupt in mind for this device,
* then by all means, set it * then by all means, set it
...@@ -526,15 +531,12 @@ static int ds1511_rtc_probe(struct platform_device *pdev) ...@@ -526,15 +531,12 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
} }
} }
rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &ds1511_rtc_ops,
THIS_MODULE);
if (IS_ERR(rtc))
return PTR_ERR(rtc);
pdata->rtc = rtc;
ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr); ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
if (ret)
dev_err(&pdev->dev, "Unable to create sysfs entry: %s\n",
ds1511_nvram_attr.attr.name);
return ret; return 0;
} }
static int ds1511_rtc_remove(struct platform_device *pdev) static int ds1511_rtc_remove(struct platform_device *pdev)
......
...@@ -278,7 +278,6 @@ static struct bin_attribute ds1553_nvram_attr = { ...@@ -278,7 +278,6 @@ static struct bin_attribute ds1553_nvram_attr = {
static int ds1553_rtc_probe(struct platform_device *pdev) static int ds1553_rtc_probe(struct platform_device *pdev)
{ {
struct rtc_device *rtc;
struct resource *res; struct resource *res;
unsigned int cen, sec; unsigned int cen, sec;
struct rtc_plat_data *pdata; struct rtc_plat_data *pdata;
...@@ -311,6 +310,12 @@ static int ds1553_rtc_probe(struct platform_device *pdev) ...@@ -311,6 +310,12 @@ static int ds1553_rtc_probe(struct platform_device *pdev)
spin_lock_init(&pdata->lock); spin_lock_init(&pdata->lock);
pdata->last_jiffies = jiffies; pdata->last_jiffies = jiffies;
platform_set_drvdata(pdev, pdata); platform_set_drvdata(pdev, pdata);
pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
&ds1553_rtc_ops, THIS_MODULE);
if (IS_ERR(pdata->rtc))
return PTR_ERR(pdata->rtc);
if (pdata->irq > 0) { if (pdata->irq > 0) {
writeb(0, ioaddr + RTC_INTERRUPTS); writeb(0, ioaddr + RTC_INTERRUPTS);
if (devm_request_irq(&pdev->dev, pdata->irq, if (devm_request_irq(&pdev->dev, pdata->irq,
...@@ -321,15 +326,12 @@ static int ds1553_rtc_probe(struct platform_device *pdev) ...@@ -321,15 +326,12 @@ static int ds1553_rtc_probe(struct platform_device *pdev)
} }
} }
rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
&ds1553_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc))
return PTR_ERR(rtc);
pdata->rtc = rtc;
ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr); ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr);
if (ret)
dev_err(&pdev->dev, "unable to create sysfs file: %s\n",
ds1553_nvram_attr.attr.name);
return ret; return 0;
} }
static int ds1553_rtc_remove(struct platform_device *pdev) static int ds1553_rtc_remove(struct platform_device *pdev)
......
...@@ -177,8 +177,9 @@ static int ds1672_probe(struct i2c_client *client, ...@@ -177,8 +177,9 @@ static int ds1672_probe(struct i2c_client *client,
/* read control register */ /* read control register */
err = ds1672_get_control(client, &control); err = ds1672_get_control(client, &control);
if (err) if (err) {
goto exit_devreg; dev_warn(&client->dev, "Unable to read the control register\n");
}
if (control & DS1672_REG_CONTROL_EOSC) if (control & DS1672_REG_CONTROL_EOSC)
dev_warn(&client->dev, "Oscillator not enabled. " dev_warn(&client->dev, "Oscillator not enabled. "
...@@ -187,12 +188,10 @@ static int ds1672_probe(struct i2c_client *client, ...@@ -187,12 +188,10 @@ static int ds1672_probe(struct i2c_client *client,
/* Register sysfs hooks */ /* Register sysfs hooks */
err = device_create_file(&client->dev, &dev_attr_control); err = device_create_file(&client->dev, &dev_attr_control);
if (err) if (err)
goto exit_devreg; dev_err(&client->dev, "Unable to create sysfs entry: %s\n",
dev_attr_control.attr.name);
return 0; return 0;
exit_devreg:
return err;
} }
static struct i2c_device_id ds1672_id[] = { static struct i2c_device_id ds1672_id[] = {
......
...@@ -204,8 +204,11 @@ static int ds1742_rtc_probe(struct platform_device *pdev) ...@@ -204,8 +204,11 @@ static int ds1742_rtc_probe(struct platform_device *pdev)
return PTR_ERR(rtc); return PTR_ERR(rtc);
ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
if (ret)
dev_err(&pdev->dev, "Unable to create sysfs entry: %s\n",
pdata->nvram_attr.attr.name);
return ret; return 0;
} }
static int ds1742_rtc_remove(struct platform_device *pdev) static int ds1742_rtc_remove(struct platform_device *pdev)
......
...@@ -414,7 +414,6 @@ static int ds3232_probe(struct i2c_client *client, ...@@ -414,7 +414,6 @@ static int ds3232_probe(struct i2c_client *client,
ds3232->rtc = devm_rtc_device_register(&client->dev, client->name, ds3232->rtc = devm_rtc_device_register(&client->dev, client->name,
&ds3232_rtc_ops, THIS_MODULE); &ds3232_rtc_ops, THIS_MODULE);
if (IS_ERR(ds3232->rtc)) { if (IS_ERR(ds3232->rtc)) {
dev_err(&client->dev, "unable to register the class device\n");
return PTR_ERR(ds3232->rtc); return PTR_ERR(ds3232->rtc);
} }
...@@ -423,7 +422,6 @@ static int ds3232_probe(struct i2c_client *client, ...@@ -423,7 +422,6 @@ static int ds3232_probe(struct i2c_client *client,
"ds3232", client); "ds3232", client);
if (ret) { if (ret) {
dev_err(&client->dev, "unable to request IRQ\n"); dev_err(&client->dev, "unable to request IRQ\n");
return ret;
} }
} }
......
...@@ -104,20 +104,17 @@ static int test_probe(struct platform_device *plat_dev) ...@@ -104,20 +104,17 @@ static int test_probe(struct platform_device *plat_dev)
rtc = devm_rtc_device_register(&plat_dev->dev, "test", rtc = devm_rtc_device_register(&plat_dev->dev, "test",
&test_rtc_ops, THIS_MODULE); &test_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) { if (IS_ERR(rtc)) {
err = PTR_ERR(rtc); return PTR_ERR(rtc);
return err;
} }
err = device_create_file(&plat_dev->dev, &dev_attr_irq); err = device_create_file(&plat_dev->dev, &dev_attr_irq);
if (err) if (err)
goto err; dev_err(&plat_dev->dev, "Unable to create sysfs entry: %s\n",
dev_attr_irq.attr.name);
platform_set_drvdata(plat_dev, rtc); platform_set_drvdata(plat_dev, rtc);
return 0; return 0;
err:
return err;
} }
static int test_remove(struct platform_device *plat_dev) static int test_remove(struct platform_device *plat_dev)
......
...@@ -660,7 +660,7 @@ static int x1205_probe(struct i2c_client *client, ...@@ -660,7 +660,7 @@ static int x1205_probe(struct i2c_client *client,
err = x1205_sysfs_register(&client->dev); err = x1205_sysfs_register(&client->dev);
if (err) if (err)
return err; dev_err(&client->dev, "Unable to create sysfs entries\n");
return 0; return 0;
} }
......
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