rtc: isl1208: avoid possible sysfs race
authorAlexandre Belloni <alexandre.belloni@bootlin.com>
Sat, 15 Sep 2018 11:29:56 +0000 (13:29 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Nov 2019 17:47:52 +0000 (18:47 +0100)
[ Upstream commit 1b4c794fda583edabe864ac466e9cd43c707be80 ]

Use rtc_add_group to add the common sysfs group to avoid a possible race
condition.

[Denis.Osterland@diehl.com: use to_i2c_client(dev->parent)]
Signed-off-by: Denis Osterland <Denis.Osterland@diehl.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
The move of atrim, dtrim usr sysfs properties from i2c device
to rtc device require to access them via dev->parent.
This patch also aligns timestamp0.

Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/rtc/rtc-isl1208.c

index ea18a8f..033f65a 100644 (file)
@@ -518,7 +518,7 @@ static ssize_t timestamp0_store(struct device *dev,
                                struct device_attribute *attr,
                                const char *buf, size_t count)
 {
-       struct i2c_client *client = dev_get_drvdata(dev);
+       struct i2c_client *client = to_i2c_client(dev->parent);
        int sr;
 
        sr = isl1208_i2c_get_sr(client);
@@ -540,7 +540,7 @@ static ssize_t timestamp0_store(struct device *dev,
 static ssize_t timestamp0_show(struct device *dev,
                               struct device_attribute *attr, char *buf)
 {
-       struct i2c_client *client = dev_get_drvdata(dev);
+       struct i2c_client *client = to_i2c_client(dev->parent);
        u8 regs[ISL1219_EVT_SECTION_LEN] = { 0, };
        struct rtc_time tm;
        int sr;
@@ -650,7 +650,7 @@ static ssize_t
 isl1208_sysfs_show_atrim(struct device *dev,
                         struct device_attribute *attr, char *buf)
 {
-       int atr = isl1208_i2c_get_atr(to_i2c_client(dev));
+       int atr = isl1208_i2c_get_atr(to_i2c_client(dev->parent));
        if (atr < 0)
                return atr;
 
@@ -663,7 +663,7 @@ static ssize_t
 isl1208_sysfs_show_dtrim(struct device *dev,
                         struct device_attribute *attr, char *buf)
 {
-       int dtr = isl1208_i2c_get_dtr(to_i2c_client(dev));
+       int dtr = isl1208_i2c_get_dtr(to_i2c_client(dev->parent));
        if (dtr < 0)
                return dtr;
 
@@ -676,7 +676,7 @@ static ssize_t
 isl1208_sysfs_show_usr(struct device *dev,
                       struct device_attribute *attr, char *buf)
 {
-       int usr = isl1208_i2c_get_usr(to_i2c_client(dev));
+       int usr = isl1208_i2c_get_usr(to_i2c_client(dev->parent));
        if (usr < 0)
                return usr;
 
@@ -701,7 +701,10 @@ isl1208_sysfs_store_usr(struct device *dev,
        if (usr < 0 || usr > 0xffff)
                return -EINVAL;
 
-       return isl1208_i2c_set_usr(to_i2c_client(dev), usr) ? -EIO : count;
+       if (isl1208_i2c_set_usr(to_i2c_client(dev->parent), usr))
+               return -EIO;
+
+       return count;
 }
 
 static DEVICE_ATTR(usr, S_IRUGO | S_IWUSR, isl1208_sysfs_show_usr,
@@ -765,7 +768,6 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
        rtc->ops = &isl1208_rtc_ops;
 
        i2c_set_clientdata(client, rtc);
-       dev_set_drvdata(&rtc->dev, client);
 
        rc = isl1208_i2c_get_sr(client);
        if (rc < 0) {
@@ -804,7 +806,7 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
                evdet_irq = of_irq_get_byname(np, "evdet");
        }
 
-       rc = sysfs_create_group(&client->dev.kobj, &isl1208_rtc_sysfs_files);
+       rc = rtc_add_group(rtc, &isl1208_rtc_sysfs_files);
        if (rc)
                return rc;
 
@@ -821,14 +823,6 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
        return rtc_register_device(rtc);
 }
 
-static int
-isl1208_remove(struct i2c_client *client)
-{
-       sysfs_remove_group(&client->dev.kobj, &isl1208_rtc_sysfs_files);
-
-       return 0;
-}
-
 static const struct i2c_device_id isl1208_id[] = {
        { "isl1208", TYPE_ISL1208 },
        { "isl1218", TYPE_ISL1218 },
@@ -851,7 +845,6 @@ static struct i2c_driver isl1208_driver = {
                .of_match_table = of_match_ptr(isl1208_of_match),
        },
        .probe = isl1208_probe,
-       .remove = isl1208_remove,
        .id_table = isl1208_id,
 };