Commit 10b06b87 authored by Raghavendra Ganiga's avatar Raghavendra Ganiga Committed by Linus Torvalds

drivers/rtc/rtc-ds1343.c: fix potential race condition

Avoid the potential race condition by avoiding bailing out of driver in
probe after registering with rtc subsystem

Also the set_alarm , read_alarm and alarm_irq_enable returns error if irq
registration fails in probe.

Also the sysfs will not create entry for alarm if irq registration fails
in probe.
Signed-off-by: default avatarRaghavendra Chandra Ganiga <ravi23ganiga@gmail.com>
Acked-by: default avatarAlessandro Zummo <a.zummo@towertech.it>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0dd449b1
...@@ -80,6 +80,7 @@ struct ds1343_priv { ...@@ -80,6 +80,7 @@ struct ds1343_priv {
struct regmap *map; struct regmap *map;
struct mutex mutex; struct mutex mutex;
unsigned int irqen; unsigned int irqen;
int irq;
int alarm_sec; int alarm_sec;
int alarm_min; int alarm_min;
int alarm_hour; int alarm_hour;
...@@ -262,28 +263,32 @@ static DEVICE_ATTR(trickle_charger, S_IRUGO, ds1343_show_tricklecharger, NULL); ...@@ -262,28 +263,32 @@ static DEVICE_ATTR(trickle_charger, S_IRUGO, ds1343_show_tricklecharger, NULL);
static int ds1343_sysfs_register(struct device *dev) static int ds1343_sysfs_register(struct device *dev)
{ {
struct ds1343_priv *priv = dev_get_drvdata(dev);
int err; int err;
err = device_create_file(dev, &dev_attr_glitch_filter); err = device_create_file(dev, &dev_attr_glitch_filter);
if (err) if (err)
return err; return err;
err = device_create_file(dev, &dev_attr_alarm_status); err = device_create_file(dev, &dev_attr_trickle_charger);
if (err) if (err)
goto error1; goto error1;
if (priv->irq <= 0)
return err;
err = device_create_file(dev, &dev_attr_alarm_mode); err = device_create_file(dev, &dev_attr_alarm_mode);
if (err) if (err)
goto error2; goto error2;
err = device_create_file(dev, &dev_attr_trickle_charger); err = device_create_file(dev, &dev_attr_alarm_status);
if (!err) if (!err)
return err; return err;
device_remove_file(dev, &dev_attr_alarm_mode); device_remove_file(dev, &dev_attr_alarm_mode);
error2: error2:
device_remove_file(dev, &dev_attr_alarm_status); device_remove_file(dev, &dev_attr_trickle_charger);
error1: error1:
device_remove_file(dev, &dev_attr_glitch_filter); device_remove_file(dev, &dev_attr_glitch_filter);
...@@ -293,10 +298,16 @@ static int ds1343_sysfs_register(struct device *dev) ...@@ -293,10 +298,16 @@ static int ds1343_sysfs_register(struct device *dev)
static void ds1343_sysfs_unregister(struct device *dev) static void ds1343_sysfs_unregister(struct device *dev)
{ {
struct ds1343_priv *priv = dev_get_drvdata(dev);
device_remove_file(dev, &dev_attr_glitch_filter); device_remove_file(dev, &dev_attr_glitch_filter);
device_remove_file(dev, &dev_attr_trickle_charger);
if (priv->irq <= 0)
return;
device_remove_file(dev, &dev_attr_alarm_status); device_remove_file(dev, &dev_attr_alarm_status);
device_remove_file(dev, &dev_attr_alarm_mode); device_remove_file(dev, &dev_attr_alarm_mode);
device_remove_file(dev, &dev_attr_trickle_charger);
} }
static int ds1343_read_time(struct device *dev, struct rtc_time *dt) static int ds1343_read_time(struct device *dev, struct rtc_time *dt)
...@@ -415,11 +426,10 @@ static int ds1343_update_alarm(struct device *dev) ...@@ -415,11 +426,10 @@ static int ds1343_update_alarm(struct device *dev)
static int ds1343_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) static int ds1343_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{ {
struct ds1343_priv *priv = dev_get_drvdata(dev); struct ds1343_priv *priv = dev_get_drvdata(dev);
struct spi_device *spi = priv->spi;
int res = 0; int res = 0;
unsigned int stat; unsigned int stat;
if (spi->irq <= 0) if (priv->irq <= 0)
return -EINVAL; return -EINVAL;
mutex_lock(&priv->mutex); mutex_lock(&priv->mutex);
...@@ -450,10 +460,9 @@ static int ds1343_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -450,10 +460,9 @@ static int ds1343_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
static int ds1343_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) static int ds1343_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{ {
struct ds1343_priv *priv = dev_get_drvdata(dev); struct ds1343_priv *priv = dev_get_drvdata(dev);
struct spi_device *spi = priv->spi;
int res = 0; int res = 0;
if (spi->irq <= 0) if (priv->irq <= 0)
return -EINVAL; return -EINVAL;
mutex_lock(&priv->mutex); mutex_lock(&priv->mutex);
...@@ -476,10 +485,9 @@ static int ds1343_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -476,10 +485,9 @@ static int ds1343_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
static int ds1343_alarm_irq_enable(struct device *dev, unsigned int enabled) static int ds1343_alarm_irq_enable(struct device *dev, unsigned int enabled)
{ {
struct ds1343_priv *priv = dev_get_drvdata(dev); struct ds1343_priv *priv = dev_get_drvdata(dev);
struct spi_device *spi = priv->spi;
int res = 0; int res = 0;
if (spi->irq <= 0) if (priv->irq <= 0)
return -EINVAL; return -EINVAL;
mutex_lock(&priv->mutex); mutex_lock(&priv->mutex);
...@@ -593,19 +601,21 @@ static int ds1343_probe(struct spi_device *spi) ...@@ -593,19 +601,21 @@ static int ds1343_probe(struct spi_device *spi)
return PTR_ERR(priv->rtc); return PTR_ERR(priv->rtc);
} }
if (spi->irq >= 0) { priv->irq = spi->irq;
if (priv->irq >= 0) {
res = devm_request_threaded_irq(&spi->dev, spi->irq, NULL, res = devm_request_threaded_irq(&spi->dev, spi->irq, NULL,
ds1343_thread, ds1343_thread,
IRQF_NO_SUSPEND | IRQF_ONESHOT, IRQF_NO_SUSPEND | IRQF_ONESHOT,
"ds1343", priv); "ds1343", priv);
if (res) { if (res) {
priv->irq = -1;
dev_err(&spi->dev, dev_err(&spi->dev,
"unable to request irq for rtc ds1343\n"); "unable to request irq for rtc ds1343\n");
return res; } else {
}
device_set_wakeup_capable(&spi->dev, 1); device_set_wakeup_capable(&spi->dev, 1);
} }
}
res = ds1343_sysfs_register(&spi->dev); res = ds1343_sysfs_register(&spi->dev);
if (res) if (res)
......
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