mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-15 08:44:14 +08:00
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>
This commit is contained in:
parent
cfb74916e2
commit
6a5f2a1f4d
@ -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);
|
||||
err = rtc_add_group(ds1307->rtc, &rtc_freq_test_attr_group);
|
||||
if (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);
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user