Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1838103ybn; Thu, 26 Sep 2019 03:01:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyCvsccOpm5hREoClVHupzlOEk5nhbcLxeu66hcdsIpo/nH9M6+jpAiMko++yBX47Mmlxd4 X-Received: by 2002:a05:6402:a48:: with SMTP id bt8mr2578606edb.298.1569492086192; Thu, 26 Sep 2019 03:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569492086; cv=none; d=google.com; s=arc-20160816; b=fdQPjAHUDgsXYX5CmPfkxVJotMebJAZEv4KVwIkjjK+5XXACg6o9fZL4N7NXDdQ6K6 UJBz9Pn9B8UgG+i01825bF5NaLjlyM4Tt01iZI6czE6x6uPkw05vx2caC8zkkrIxvSUZ Xxe4aqGr8DW1L0z6fmXdxUiLrCaePf74grZyCwbq9mi2T9gCxpxOLj7tHuqv3kfK+HFl q62OHlbq7BjD6vphzL9gkK89UOZZn94I5mLJbQ7DfmVk4E2u1BETbgHIBv5Vs27bDbMM IjUxuReNek2Jrt7wzRYcX+pY0QzH/dWzYBncbayqlkr/t9DyjG8vldZXiaw/pah9VZVl F2Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=fwxqGOJ4EK6HWwfzrt6IbqWGZET3zrS4nF5lIFmhKAQ=; b=ntoOFrkAJsAbsSWtRwdrYvNbKmhHRnqoPKuhim/EuBD8HuJknOkUdmhSMMYZzMFZJH mCm2SX8/d4khOplSR9LqnD2CeJE8tdTi2DgLNZPU6sf1etW/NMfYwRQbSuWp5IPtYpW7 1t+ljWxZQYa2dI71ryXsviB/sHuPYtjZyPu60aqbj1BoA0VTdKLUUepiZaEEwkp2eheV UDan/Wbp0uFzfPaczKuUc2zj5TX8vSh3/PiNRGofIPIR4wEu2WgdW5gF9n5Qw7zDtzdl rUPKWMVThr/KhhpDf5MmB/ofXqQvj9sKzNnax8i0eAuLC4vyRBr87xJn/sodYekr9BjA Kh9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HnOQjAxz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d1si894354edr.446.2019.09.26.03.01.02; Thu, 26 Sep 2019 03:01:26 -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; dkim=pass header.i=@chromium.org header.s=google header.b=HnOQjAxz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389130AbfIYUvR (ORCPT + 99 others); Wed, 25 Sep 2019 16:51:17 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:39228 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387977AbfIYUvQ (ORCPT ); Wed, 25 Sep 2019 16:51:16 -0400 Received: by mail-lj1-f195.google.com with SMTP id y3so7123049ljj.6 for ; Wed, 25 Sep 2019 13:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fwxqGOJ4EK6HWwfzrt6IbqWGZET3zrS4nF5lIFmhKAQ=; b=HnOQjAxzxL/iJzgJXaCg8DLlJ7/U1bQzB2lHrCLH5blJi062W+/tBvhocCWxwQVLsG ZdNqs+k7YEQBDqFIPZmRn8Ket7KapoV3xCDu6OtwHCiotUTgZBgy39vuq/TFo6DsxHwT w6dakydXCqPgTAGvQ8t4fyhq30lgeDC8VTFuU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fwxqGOJ4EK6HWwfzrt6IbqWGZET3zrS4nF5lIFmhKAQ=; b=rYR9HyIseuFe8aynGU0v31wy4H7wZu1CA6p92i5b9kKvJkXFiLNqnZdlcB5QH9On1z W6StyX/Im4hVaBC/BMviQBNZUZooPtYf9enZwe1BUDdCi2tJzO04aK2TeHef/+u/GroZ GBfmJW1vmtMfjYc9SuZdLH20pGq009XwXMppMgQsewjSrclCglOZWugVkOXuG0r/L+i2 Tn3c1b1ETOj+x9/yM7cgfoCHctx655YtzFEv8lvbt62wD9IQUHMp2fiRFa4wzBJ9syOr GalllDbpLabMzzWi2VpJC5pWZFMefLmAzrbYw4h66C17v8aZh+GTiZpqXtB9yY34HW11 Murw== X-Gm-Message-State: APjAAAVQXmBiCircSatJu3JZ/yl6KMY4ITlyPFMWZjppvlWjfi7DiXM4 /0avhXIYGIUJUCdrVGuzcyVjqBmXfmU= X-Received: by 2002:a2e:7c17:: with SMTP id x23mr167315ljc.210.1569444674117; Wed, 25 Sep 2019 13:51:14 -0700 (PDT) Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com. [209.85.208.173]) by smtp.gmail.com with ESMTPSA id y26sm1691868ljj.90.2019.09.25.13.51.13 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Sep 2019 13:51:13 -0700 (PDT) Received: by mail-lj1-f173.google.com with SMTP id e17so7114632ljf.13 for ; Wed, 25 Sep 2019 13:51:13 -0700 (PDT) X-Received: by 2002:a2e:2c02:: with SMTP id s2mr183696ljs.156.1569444672670; Wed, 25 Sep 2019 13:51:12 -0700 (PDT) MIME-Version: 1.0 References: <20190925203209.79941-1-ncrews@chromium.org> In-Reply-To: <20190925203209.79941-1-ncrews@chromium.org> From: Dmitry Torokhov Date: Wed, 25 Sep 2019 13:51:01 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] rtc: wilco-ec: Handle reading invalid times To: Nick Crews Cc: Alexandre Belloni , Alessandro Zummo , linux-rtc@vger.kernel.org, lkml , Pavel Machek , enric.balletbo@collabora.com, Benson Leung , dlaurie@chromium.org, Daniel Kurtz Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 25, 2019 at 1:32 PM 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 Reviewed-by: Dmitry Torokhov > --- > 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); > + return -EIO; > + } > > return 0; > } > -- > 2.21.0 > Thanks. -- Dmitry