Linux-RTC Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] rtc: class: avoid unnecessary lookup in hctosys
@ 2020-03-23 21:30 Alexandre Belloni
  0 siblings, 0 replies; only message in thread
From: Alexandre Belloni @ 2020-03-23 21:30 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni; +Cc: linux-rtc, linux-kernel

rtc_hctosys is only called when the relevant RTC is found, avoid looking it
up while we already have a pinter to the proper struct rtc_device.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/class.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 8793b2b8cf9d..03d6516941a8 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -46,20 +46,13 @@ int rtc_hctosys_ret = -ENODEV;
  * the best guess is to add 0.5s.
  */
 
-static int rtc_hctosys(void)
+static void rtc_hctosys(struct rtc_device *rtc)
 {
 	int err = -ENODEV;
 	struct rtc_time tm;
 	struct timespec64 tv64 = {
 		.tv_nsec = NSEC_PER_SEC >> 1,
 	};
-	struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
-
-	if (!rtc) {
-		pr_info("unable to open rtc device (%s)\n",
-			CONFIG_RTC_HCTOSYS_DEVICE);
-		goto err_open;
-	}
 
 	err = rtc_read_time(rtc, &tm);
 	if (err) {
@@ -83,12 +76,7 @@ static int rtc_hctosys(void)
 		 &tm, (long long)tv64.tv_sec);
 
 err_read:
-	rtc_class_close(rtc);
-
-err_open:
 	rtc_hctosys_ret = err;
-
-	return err;
 }
 #endif
 
@@ -433,7 +421,7 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc)
 
 #ifdef CONFIG_RTC_HCTOSYS_DEVICE
 	if (!strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE))
-		rtc_hctosys();
+		rtc_hctosys(rtc);
 #endif
 
 	return 0;
-- 
2.25.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-23 21:30 [PATCH] rtc: class: avoid unnecessary lookup in hctosys Alexandre Belloni

Linux-RTC Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rtc/0 linux-rtc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rtc linux-rtc/ https://lore.kernel.org/linux-rtc \
		linux-rtc@vger.kernel.org
	public-inbox-index linux-rtc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rtc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git