Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp714391ybn; Wed, 2 Oct 2019 05:09:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXNqPJpaJU67ktx9faBAs57tlYCaN5gO00xBhk8LhvdpE+QP7f9MwSS5/SkY9elQnppxXq X-Received: by 2002:a17:906:768f:: with SMTP id o15mr2669734ejm.42.1570018177098; Wed, 02 Oct 2019 05:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570018177; cv=none; d=google.com; s=arc-20160816; b=Tvu5mmdhkfK1ond0XeHEk9oOY0K7LTegUQqOTivpVCD0M5ynVzCbrD9S1tjMbunR2n imBxCx9O8rU1FQSQteDg9duRhvRQneebik+jZpVs66uWUyvN6Hh/nea5SXrQi/LtFm4A me9iCbFER/QJFS+/92xG5K3yWxjliJRiOWbcbnwg3ckE2+dki/0WQiG9EFnGrUTVDKhR 1Sb3b+RSYvkitv8n6KzIUxe+GviEiuxVQ8w0HqdYhSSZ0/7gm1oLgVItTvCtGrJk7SDM S7kjvjEgwOHyYAeiWfC84+O0FX4B8SkGEMkvJhLDFAG1WnO47B0HucSHgp4emaKBpN+r Q/kg== 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=SZSfoAsU9c+ULhgVkMTc3yjqTrGAfkX70xVwrMkWHTo=; b=hvKbiK7gU8tihg6qlaXP4gr6TFp/+DoEQVyXP8oPnUEHBFMjPap3ZUZuaTfV8coUfn yBR+epE0n8L7BCD7NT3CPuZ+i/ws9ZGBGAvaZnTpGneukR0NBvEYNvSNVQlHcE0dJ7SA ANpJsTt0dC6T0nVt3QNidreKkkH/R+pdiWZ0VM1F8wTy3eh/z6qtvnLVH/FyOxiL3dNR CtXc8yQIPMEkWZiCw+McHEPynvgEcSeQE/kk7Fp9ZpYfpjbrNymh2x7qkwRmOfpiXJ5D bdN0yEED43gROnpxJ7x85TDIqmmM9n3Mc72i5b+M2tGazwZtVjoHZ+JzuEe0VX9MDDDc 4Hkw== 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 q23si10943562ejx.376.2019.10.02.05.09.12; Wed, 02 Oct 2019 05:09:37 -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 S1727883AbfJBKcl (ORCPT + 99 others); Wed, 2 Oct 2019 06:32:41 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:58703 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726109AbfJBKck (ORCPT ); Wed, 2 Oct 2019 06:32:40 -0400 X-Originating-IP: 86.207.98.53 Received: from localhost (aclermont-ferrand-651-1-259-53.w86-207.abo.wanadoo.fr [86.207.98.53]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 9674FE0007; Wed, 2 Oct 2019 10:32:37 +0000 (UTC) Date: Wed, 2 Oct 2019 12:32:36 +0200 From: Alexandre Belloni To: Dmitry Torokhov Cc: Nick Crews , Alessandro Zummo , linux-rtc@vger.kernel.org, lkml , Pavel Machek , enric.balletbo@collabora.com, Benson Leung , dlaurie@chromium.org, Daniel Kurtz Subject: Re: [PATCH v3] rtc: wilco-ec: Handle reading invalid times Message-ID: <20191002103236.GM4106@piout.net> References: <20190925203209.79941-1-ncrews@chromium.org> <20191001195342.GH4106@piout.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 On 01/10/2019 13:42:24-0700, Dmitry Torokhov wrote: > On Tue, Oct 1, 2019 at 12:53 PM Alexandre Belloni > wrote: > > > > 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. > > I do not think this is a good idea: we have just established that tm > does not contain valid data. Does %ptR guarantee that it handles junk > better than, let's say, rtc_year_days(), and does not crash when > presented with garbage? > It is safe to use. You can also use %ptRr if you want to ensure no extra operations are done on the value before printing them out. I'm still not convinced it is useful to have an error in dmesg when the time is invalid, as long as userspace knows it is invalid. What is the course of action for the end user when that happens? -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com