diff options
author | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2018-09-20 16:35:26 +0200 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2018-09-28 14:21:01 +0200 |
commit | 6a5f2a1f4dcdb31fde467d9ae612505692eb4243 (patch) | |
tree | c9468825c5b51dd5a08d31d4ebc211faedfe5f87 /drivers/rtc | |
parent | cfb74916e2ecf018e3189959edd2a1356b2fd89e (diff) | |
download | linux-6a5f2a1f4dcdb31fde467d9ae612505692eb4243.tar.bz2 |
rtc: ds1307: use rtc_add_group
Register frequency test using rtc_add_group to avoid a possible race
condition and simplify the code.
This also moves the attribute to its proper location under the rtc device
instead of the i2c parent device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/rtc-ds1307.c | 53 |
1 files changed, 14 insertions, 39 deletions
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index edccd0c0da25..982503a168d0 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c @@ -1050,11 +1050,11 @@ static int m41txx_rtc_set_offset(struct device *dev, long offset) ctrl_reg); } -static ssize_t frequency_test_enable_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t frequency_test_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { - struct ds1307 *ds1307 = dev_get_drvdata(dev); + struct ds1307 *ds1307 = dev_get_drvdata(dev->parent); bool freq_test_en; int ret; @@ -1070,11 +1070,11 @@ static ssize_t frequency_test_enable_store(struct device *dev, return count; } -static ssize_t frequency_test_enable_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t frequency_test_show(struct device *dev, + struct device_attribute *attr, + char *buf) { - struct ds1307 *ds1307 = dev_get_drvdata(dev); + struct ds1307 *ds1307 = dev_get_drvdata(dev->parent); unsigned int ctrl_reg; regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg); @@ -1083,10 +1083,10 @@ static ssize_t frequency_test_enable_show(struct device *dev, "off\n"); } -static DEVICE_ATTR_RW(frequency_test_enable); +static DEVICE_ATTR_RW(frequency_test); static struct attribute *rtc_freq_test_attrs[] = { - &dev_attr_frequency_test_enable.attr, + &dev_attr_frequency_test.attr, NULL, }; @@ -1094,13 +1094,6 @@ static const struct attribute_group rtc_freq_test_attr_group = { .attrs = rtc_freq_test_attrs, }; -static void rtc_calib_remove_sysfs_group(void *_dev) -{ - struct device *dev = _dev; - - sysfs_remove_group(&dev->kobj, &rtc_freq_test_attr_group); -} - static int ds1307_add_frequency_test(struct ds1307 *ds1307) { int err; @@ -1109,27 +1102,9 @@ static int ds1307_add_frequency_test(struct ds1307 *ds1307) case m41t0: case m41t00: case m41t11: - /* Export sysfs entries */ - err = sysfs_create_group(&(ds1307->dev)->kobj, - &rtc_freq_test_attr_group); - if (err) { - dev_err(ds1307->dev, - "Failed to create sysfs group: %d\n", - err); - return err; - } - - err = devm_add_action_or_reset(ds1307->dev, - rtc_calib_remove_sysfs_group, - ds1307->dev); - if (err) { - dev_err(ds1307->dev, - "Failed to add sysfs cleanup action: %d\n", - err); - sysfs_remove_group(&(ds1307->dev)->kobj, - &rtc_freq_test_attr_group); + err = rtc_add_group(ds1307->rtc, &rtc_freq_test_attr_group); + if (err) return err; - } break; default: break; @@ -1876,11 +1851,11 @@ read_rtc: } ds1307->rtc->ops = chip->rtc_ops ?: &ds13xx_rtc_ops; - err = rtc_register_device(ds1307->rtc); + err = ds1307_add_frequency_test(ds1307); if (err) return err; - err = ds1307_add_frequency_test(ds1307); + err = rtc_register_device(ds1307->rtc); if (err) return err; |