Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1835679ybn; Thu, 26 Sep 2019 02:59:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzzI6B3h/Y/hZHM9entZ10KvXj9Lnof9qKjXVuxnlf4GWBMCWP2+s0lctoms4cjeYYM6h0l X-Received: by 2002:a17:906:d922:: with SMTP id rn2mr2265035ejb.124.1569491966066; Thu, 26 Sep 2019 02:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569491966; cv=none; d=google.com; s=arc-20160816; b=pPc8zSHn8SHcdqVifv0aspIohQrtZLgF4M8oRNwnMe1n+Rr13h3l/lt9FkUp6hrhN3 PQOkaBIOQFEzOCL4We2fOcasKNHnxhijyHpryzBUxzckZZL1PoC6C2ezMdeWl/9xTlEd 63xG7H/FCurbNtIi6kg90OwHsNhEFgD8XOzgQC4g0UhGiLjWpjvetH0IfBl2rlv0C3S4 aTaQ5dGe/QC3uxWhP4DXMmORFlfa1L3Vxx3ZsCG6MdGM0965Z45Xt0KYeZtyMc5xJlM3 fWFzOQrUwTb3h82I+PQN4gGH/aaT4bYX9M8Q1ZYDyTDYK1EqYT1E2AZn++DkeBD/Gt9A JNuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Joen6PgN4Ppb107hjPSYd8q2loeVTGPWBeR8yaoJJfc=; b=srcjw3fWLFstX0OzC8y80YDbwgH0v74H9cHwwTLuM5tkidN1OLjAeL0t7p4V9GC6Sc TViCVrikamlJf9UHebusYm5Dcfj6xuJ5fyFPXMRgADItodg8x34nBJ8EnJtI89BiEje8 5fic01AKB1hh4xNDKlWnMP/9U4hh6lYut+VBsMazEjXKNZjJIQE1f6GGLkS1CA13EyGO ZGx3kcoSYiZKeM77kFb3EwoNjURrO3lB3jhu3c3UXopa35otIyL7rNmVsl8lORRM45Wi pL5ADOjS/KNiKR1my4/Ti6ilGL3p/lzLRQYhYGBO+QW+qmVl5UmfAS2X2dwhreMVBiVe Wn1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iKTW5eGm; 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 a2si965854edc.321.2019.09.26.02.59.02; Thu, 26 Sep 2019 02:59: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=iKTW5eGm; 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 S2393222AbfIYUcX (ORCPT + 99 others); Wed, 25 Sep 2019 16:32:23 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:36933 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393204AbfIYUcW (ORCPT ); Wed, 25 Sep 2019 16:32:22 -0400 Received: by mail-io1-f67.google.com with SMTP id b19so421052iob.4 for ; Wed, 25 Sep 2019 13:32:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Joen6PgN4Ppb107hjPSYd8q2loeVTGPWBeR8yaoJJfc=; b=iKTW5eGmeo7sl0Q4HF9ZqwfjLbHPh77cZyWr36n8dzNdMbT+HJemF9vuYIeQp42jxo Qacg5Pz2zsOsDg/o/arm+Ck81IAphdlBANecSt6LiqOvq9WAOZlKhtqxEJAO4BWKsFmr qDJICSw4ZPcg1YZeuD4zDxTZD0XFTlD27h63s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Joen6PgN4Ppb107hjPSYd8q2loeVTGPWBeR8yaoJJfc=; b=Ik+RPFdpNS0JUtz3ZGLXYJtBFd3pDCXgfskcHZLmQ8kBmSquJ6StsR+TbrswX7D1kf ecNzxDli2uixFw5gWVxY7cvM8t3bTmwdwmFL0l4OBhkY6icBEpVb+bDxqZlGnPO+nEZV 8+m9XFR5BNXESWpQUWFaMWgsWmOLm9DuaQO/PmA3Ji2hQsb/JnXTfzkmVZSLzNn2NgQ0 iUD4goXP8pUzOwnzylKLmZHlkU02f+zR/wD6J+bhq9kCFbbEvkjW2MI0dLEdAVnQtaf0 m/IUTaltMX8rXCyAZ3MffbJtKB91eQKFJmPXbwE2In68fYFT2xCPnlJr3UIpjDu54gVl Hd4w== X-Gm-Message-State: APjAAAX1NzGBW25tFBWfpYLm2phIDSynicK8VjBUR5HQsM/h9RJgflB6 Ki1Ri0ne87BAqvMLmysx8Mathw== X-Received: by 2002:a6b:b704:: with SMTP id h4mr1413903iof.218.1569443541534; Wed, 25 Sep 2019 13:32:21 -0700 (PDT) Received: from ncrews2.bld.corp.google.com ([2620:15c:183:200:cb43:2cd4:65f5:5c84]) by smtp.gmail.com with ESMTPSA id 80sm449790iou.13.2019.09.25.13.32.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Sep 2019 13:32:21 -0700 (PDT) From: Nick Crews To: Alexandre Belloni , Alessandro Zummo Cc: 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, Nick Crews Subject: [PATCH v3] rtc: wilco-ec: Handle reading invalid times Date: Wed, 25 Sep 2019 14:32:09 -0600 Message-Id: <20190925203209.79941-1-ncrews@chromium.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); + return -EIO; + } return 0; } -- 2.21.0