Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8790151ybn; Tue, 1 Oct 2019 12:56:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyldb8B/dZpm1bm6/4bAqkkzPJ8hmg397NCnoXKxfvqkGAU2os2PQK0IF2q8o3Kgzlmqur8 X-Received: by 2002:a17:906:6994:: with SMTP id i20mr4458188ejr.239.1569959772419; Tue, 01 Oct 2019 12:56:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569959772; cv=none; d=google.com; s=arc-20160816; b=FUZcHIQEof5L3TFL4DZiMhkk7PB4xGy39LardescIaJ48wGBHPL1JEsgn3rmDspe0W ySHF+4l5XdEFEHjccgm8quug6Fx1pNDsYAX3IFXnzzi7OWuWQ3PFy+F2hu9rs0gO2RNE MVAtEbkaeJh8r7jhSjUWTypJH9qMDG3mRfRehLNTu3Bt2tQeq80LjWpY9Nd8dcSG6hiF txZ3iVk120UO4aOmglg99rqslqQ2Hpep3k5YSI/USJn091aCZhkAwhNLYPTY8lcK69Ot WVYdcxr9j5CBVzWNzC6JN5MZamSztoUuNDvWm/YmCpBHLDya0mkv5CsMO55TYikNZOhe a87Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=LoGlkkHYJLjzPg62O8aXSqMKqllC6GOjqkFumi4PMpg=; b=0ssEQfMIG/gT0mcPdivNfIT3f+QRNUxJrcTO4O4t1I5y5UieitxhX4nXRW1puJLZlk AscDhhBO3Tux2yYZXdOoEqGcpHAu9LgLwem7lpBIVws+7PCg0W3m2cn649p7dW9aghyq 6hPNRAmVQ27KN5aeDNNfxwLu/uyXfU+0R5Dmz5DegtDJxU9EMklMFc4geNjj2A+xeHOD UA+NfIY9iBmU5gwnjXfyMWrBQPzvbUqUqva2jjxd11YGlx8Dm9Lp8i1PpWGieCQw78MD htDH7EkThFuwBnCEcTQZuBZCPXeu4NdMEefZY3/ZoblnQsfu9knqWcyR29n/lzCVk/tS PPUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5si10502578edk.157.2019.10.01.12.55.48; Tue, 01 Oct 2019 12:56:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726368AbfJATxp (ORCPT + 99 others); Tue, 1 Oct 2019 15:53:45 -0400 Received: from relay2-d.mail.gandi.net ([217.70.183.194]:41235 "EHLO relay2-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725851AbfJATxp (ORCPT ); Tue, 1 Oct 2019 15:53:45 -0400 X-Originating-IP: 86.202.229.42 Received: from localhost (lfbn-lyo-1-146-42.w86-202.abo.wanadoo.fr [86.202.229.42]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id E4C6240002; Tue, 1 Oct 2019 19:53:42 +0000 (UTC) Date: Tue, 1 Oct 2019 21:53:42 +0200 From: Alexandre Belloni To: Nick Crews Cc: Alessandro Zummo , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, Pavel Machek , enric.balletbo@collabora.com, bleung@chromium.org, dlaurie@chromium.org, djkurtz@chromium.org, dtor@google.com Subject: Re: [PATCH v3] rtc: wilco-ec: Handle reading invalid times Message-ID: <20191001195342.GH4106@piout.net> References: <20190925203209.79941-1-ncrews@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190925203209.79941-1-ncrews@chromium.org> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Nick, On 25/09/2019 14:32:09-0600, Nick Crews wrote: > If the RTC HW returns an invalid time, the rtc_year_days() > call would crash. This patch adds error logging in this > situation, and removes the tm_yday and tm_wday calculations. > These fields should not be relied upon by userspace > according to man rtc, and thus we don't need to calculate > them. > > Signed-off-by: Nick Crews > --- > drivers/rtc/rtc-wilco-ec.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/drivers/rtc/rtc-wilco-ec.c b/drivers/rtc/rtc-wilco-ec.c > index 8ad4c4e6d557..53da355d996a 100644 > --- a/drivers/rtc/rtc-wilco-ec.c > +++ b/drivers/rtc/rtc-wilco-ec.c > @@ -110,10 +110,15 @@ static int wilco_ec_rtc_read(struct device *dev, struct rtc_time *tm) > tm->tm_mday = rtc.day; > tm->tm_mon = rtc.month - 1; > tm->tm_year = rtc.year + (rtc.century * 100) - 1900; > - tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); > - > - /* Don't compute day of week, we don't need it. */ > - tm->tm_wday = -1; > + /* Ignore other tm fields, man rtc says userspace shouldn't use them. */ > + > + if (rtc_valid_tm(tm)) { > + dev_err(dev, > + "Time from RTC is invalid: second=%u, minute=%u, hour=%u, day=%u, month=%u, year=%u, century=%u", > + rtc.second, rtc.minute, rtc.hour, rtc.day, rtc.month, > + rtc.year, rtc.century); Do you mind using %ptR? At this point you already filled the tm struct anyway and if you print century separately, you can infer tm_year. -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com