From patchwork Thu Feb 11 10:52:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 45117 Return-Path: <3d-FzSwAACRgFH0-96BIL4CC4924FCIDG.0CA@groups.bounces.google.com> X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-yx0-f142.google.com (mail-yx0-f142.google.com [209.85.210.142]) by ozlabs.org (Postfix) with ESMTP id 9D2A4B7CE8 for ; Thu, 11 Feb 2010 21:52:40 +1100 (EST) Received: by yxe6 with SMTP id 6sf2787117yxe.1 for ; Thu, 11 Feb 2010 02:52:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:x-beenthere:received:received:received :received:received-spf:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references:mime-version :x-sa-exim-connect-ip:x-sa-exim-mail-from:x-sa-exim-scanned :x-ptx-original-recipient:x-original-authentication-results :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:x-thread-url:x-message-url:sender :list-subscribe:list-unsubscribe:content-type :content-transfer-encoding; bh=yBRpKnm5fOVlvDScVAcXsnuWUQcYWyYGImk035+k/sQ=; b=2u9YND8AaU29cHcjLsgvqw5DLre3uhmv4RTjLROogyBj+PbPiTrUeI/n9AykA8gN2/ oyxkhDPEKlVyLzEA8wcg8qtZU+Lh7DkcbvBztEryoySwCIqc3iBbTMcdpjxcsqkx6SYr l/FtDIqHMwKlDR2681gkhyhjrY3s2eB6gEU/4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:from:to:cc:subject:date:message-id :x-mailer:in-reply-to:references:mime-version:x-sa-exim-connect-ip :x-sa-exim-mail-from:x-sa-exim-scanned:x-ptx-original-recipient :x-original-authentication-results:x-original-sender:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :x-thread-url:x-message-url:sender:list-subscribe:list-unsubscribe :content-type:content-transfer-encoding; b=4G2zGpeMTLyDS7/13Z4FVqvC4dl/7wcg6AAxd43MeSXuUJ0MlErtvoDXKQmPQXRVsl 34xzUfXHz4ZynRXLJrUWzrKJxTpq6XNw6eNSuZryon8sSZVzprFz5PkHxBPLue4vgLGO gCRUqzY2Ry5nCjiK+vhYEQml6NxXvPW9hz5RU= Received: by 10.101.180.32 with SMTP id h32mr211757anp.7.1265885559076; Thu, 11 Feb 2010 02:52:39 -0800 (PST) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.87.60.21 with SMTP id n21ls372657fgk.0.p; Thu, 11 Feb 2010 02:52:37 -0800 (PST) Received: by 10.87.74.24 with SMTP id b24mr79923fgl.1.1265885557390; Thu, 11 Feb 2010 02:52:37 -0800 (PST) Received: by 10.87.74.24 with SMTP id b24mr79922fgl.1.1265885557359; Thu, 11 Feb 2010 02:52:37 -0800 (PST) Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [92.198.50.35]) by gmr-mx.google.com with ESMTP id 12si220792fxm.1.2010.02.11.02.52.37; Thu, 11 Feb 2010 02:52:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of ukl@pengutronix.de designates 92.198.50.35 as permitted sender) client-ip=92.198.50.35; Received: from octopus.hi.pengutronix.de ([2001:6f8:1178:2:215:17ff:fe12:23b0]) by metis.ext.pengutronix.de with esmtp (Exim 4.69) (envelope-from ) id 1NfWez-0004RH-2P; Thu, 11 Feb 2010 11:52:37 +0100 Received: from ukl by octopus.hi.pengutronix.de with local (Exim 4.69) (envelope-from ) id 1NfWev-0006En-7K; Thu, 11 Feb 2010 11:52:33 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: rtc-linux@googlegroups.com Cc: Paul Gortmaker , Alessandro Zummo , Andrew Morton , linux-kernel@vger.kernel.org Subject: [rtc-linux] [PATCH RESEND] rtc/hctosys: only claim the RTC provided the system time if it did Date: Thu, 11 Feb 2010 11:52:29 +0100 Message-Id: <1265885549-23920-1-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 1.6.6 In-Reply-To: <1265663419-10165-1-git-send-email-u.kleine-koenig@pengutronix.de> References: <1265663419-10165-1-git-send-email-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:6f8:1178:2:215:17ff:fe12:23b0 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: rtc-linux@googlegroups.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of ukl@pengutronix.de designates 92.198.50.35 as permitted sender) smtp.mail=ukl@pengutronix.de X-Original-Sender: u.kleine-koenig@pengutronix.de Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: X-Thread-Url: http://groups.google.com/group/rtc-linux/t/c7fb28a151baff82 X-Message-Url: http://groups.google.com/group/rtc-linux/msg/7c89816ac5a2c966 Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , Moreover change error handling in rtc_hctosys() to use goto and so reduce the indention level. Signed-off-by: Uwe Kleine-König --- Hello, this time the patch is complete. What do you think about it? Best regards Uwe drivers/rtc/hctosys.c | 59 +++++++++++++++++++++++++++-------------------- drivers/rtc/rtc-sysfs.c | 5 ++- include/linux/rtc.h | 6 ++++ 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c index 33c0e98..bc90b09 100644 --- a/drivers/rtc/hctosys.c +++ b/drivers/rtc/hctosys.c @@ -22,48 +22,57 @@ * the best guess is to add 0.5s. */ +int rtc_hctosys_ret = -ENODEV; + static int __init rtc_hctosys(void) { - int err; + int err = -ENODEV; struct rtc_time tm; + struct timespec tv = { + .tv_nsec = NSEC_PER_SEC >> 1, + }; struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); if (rtc == NULL) { - printk("%s: unable to open rtc device (%s)\n", + pr_err("%s: unable to open rtc device (%s)\n", __FILE__, CONFIG_RTC_HCTOSYS_DEVICE); - return -ENODEV; + goto err_open; } err = rtc_read_time(rtc, &tm); - if (err == 0) { - err = rtc_valid_tm(&tm); - if (err == 0) { - struct timespec tv; + if (err) { + dev_err(rtc->dev.parent, + "hctosys: unable to read the hardware clock\n"); + goto err_read; - tv.tv_nsec = NSEC_PER_SEC >> 1; + } - rtc_tm_to_time(&tm, &tv.tv_sec); + err = rtc_valid_tm(&tm); + if (err) { + dev_err(rtc->dev.parent, + "hctosys: invalid date/time\n"); + goto err_invalid; + } - do_settimeofday(&tv); + rtc_tm_to_time(&tm, &tv.tv_sec); - dev_info(rtc->dev.parent, - "setting system clock to " - "%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n", - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (unsigned int) tv.tv_sec); - } - else - dev_err(rtc->dev.parent, - "hctosys: invalid date/time\n"); - } - else - dev_err(rtc->dev.parent, - "hctosys: unable to read the hardware clock\n"); + do_settimeofday(&tv); + dev_info(rtc->dev.parent, + "setting system clock to " + "%d-%02d-%02d %02d:%02d:%02d UTC (%u)\n", + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec, + (unsigned int) tv.tv_sec); + +err_invalid: +err_read: rtc_class_close(rtc); - return 0; +err_open: + rtc_hctosys_ret = err; + + return err; } late_initcall(rtc_hctosys); diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c index 7dd23a6..380083c 100644 --- a/drivers/rtc/rtc-sysfs.c +++ b/drivers/rtc/rtc-sysfs.c @@ -107,8 +107,9 @@ rtc_sysfs_show_hctosys(struct device *dev, struct device_attribute *attr, char *buf) { #ifdef CONFIG_RTC_HCTOSYS_DEVICE - if (strcmp(dev_name(&to_rtc_device(dev)->dev), - CONFIG_RTC_HCTOSYS_DEVICE) == 0) + if (rtc_hctosys_ret == 0 && + strcmp(dev_name(&to_rtc_device(dev)->dev), + CONFIG_RTC_HCTOSYS_DEVICE) == 0) return sprintf(buf, "1\n"); else #endif diff --git a/include/linux/rtc.h b/include/linux/rtc.h index 60f88a7..14dbc83 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -238,6 +238,12 @@ static inline bool is_leap_year(unsigned int year) return (!(year % 4) && (year % 100)) || !(year % 400); } +#ifdef CONFIG_RTC_HCTOSYS +extern int rtc_hctosys_ret; +#else +#define rtc_hctosys_ret -ENODEV +#endif + #endif /* __KERNEL__ */ #endif /* _LINUX_RTC_H_ */