linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: linux-rtc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Alexandre Belloni <alexandre.belloni@bootlin.com>
Subject: [PATCH] rtc: ds1307: use rtc_add_group
Date: Thu, 20 Sep 2018 16:35:26 +0200	[thread overview]
Message-ID: <20180920143526.18704-1-alexandre.belloni@bootlin.com> (raw)

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>
---
 drivers/rtc/rtc-ds1307.c | 53 +++++++++++-----------------------------
 1 file 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 @@ static int ds1307_probe(struct i2c_client *client,
 	}
 
 	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;
 
-- 
2.19.0

                 reply	other threads:[~2018-09-20 20:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180920143526.18704-1-alexandre.belloni@bootlin.com \
    --to=alexandre.belloni@bootlin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).