Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp592918ybn; Tue, 24 Sep 2019 06:42:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqylzPow+e3WzcIoTNnDba5KrPveOqahqctD1LGdvfwLc/Bjrt9yRQWw4k9E7WwO8f3R30em X-Received: by 2002:a1c:1d8d:: with SMTP id d135mr64603wmd.7.1569332525670; Tue, 24 Sep 2019 06:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569332525; cv=none; d=google.com; s=arc-20160816; b=wzgLSubjd5XcZta6rY8y13stY+5kG8nHnQDC2LtbqyCZzy0yyzEE9/UZqsejelYZWk AqBU8lnPEt7zWVbgcrWgIppuIIArVQHCozhbUqET4FKQfhnZkOPv0tWfPcdd2+8FSzTr qfH9bO7G0TIT4UuLKWomcFdA3PEWx8Se6DgCN6F2US46Sjnmef2A8oVMQrrpUn3dMkd7 ldZMc8hjtNfZAPxghlCKVTBNH6o9k+azvOPFG6m/9vI1kXUeP3MpfzFQd5vwcNZZgMGF vnO48lBJNVjLrrP27w9QzmdF4lH5svs6p8pz2Cxusx8pUpuWA14I3FD3OclFbMEoe7E1 eJ3w== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=/89z4efq1xdz2wpc++T3fgAW480EBQhfEkKOzKYz4vY=; b=FqPcKHIQk1a31wNx1+TTQgNU2BoWZS6GCYh1ReI44uOGhOmfcyooHbTb/xHVgG5hRl WgnORl5HYcO8Kqe8mtcmYY6fHatowW7UaChHZI0GJbsMUY6Y9s0F8qfh+5NPGqCrxcv8 F182TZjqZ0VlZso05+5iQkx+76WxntmhhsG6wzvRe0NgYYcNEOE+Msmey3NWhjbGYhlk 3Kym6OLIC1ygkaGVcbOQAR5Iv2ovVVzbAQEvhUoM0+ob+4HwMCsTzyIYwgelTLh1nZFI Y/rc5ZJMI0iqySbFQuJpLADEvNQofvxdfw+O0fCayJkHjFLQvcPEmtbcMG/k0FDi6DFZ C0Yg== 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 w10si1071991edv.21.2019.09.24.06.41.38; Tue, 24 Sep 2019 06:42:05 -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 S1730202AbfIVTGn (ORCPT + 99 others); Sun, 22 Sep 2019 15:06:43 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:58321 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439182AbfIVTFo (ORCPT ); Sun, 22 Sep 2019 15:05:44 -0400 X-Originating-IP: 90.65.161.137 Received: from localhost (lfbn-1-1545-137.w90-65.abo.wanadoo.fr [90.65.161.137]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 0162360006; Sun, 22 Sep 2019 19:05:42 +0000 (UTC) Date: Sun, 22 Sep 2019 21:05:42 +0200 From: Alexandre Belloni To: Pavel Machek Cc: Nick Crews , bleung@chromium.org, Alessandro Zummo , enric.balletbo@collabora.com, linux-kernel@vger.kernel.org, dlaurie@chromium.org Subject: Re: [PATCH v2 1/2] rtc: wilco-ec: Remove yday and wday calculations Message-ID: <20190922190542.GC3185@piout.net> References: <20190916181215.501-1-ncrews@chromium.org> <20190922161306.GA1999@bug> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190922161306.GA1999@bug> 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 22/09/2019 18:13:06+0200, Pavel Machek wrote: > On Mon 2019-09-16 12:12:15, Nick Crews wrote: > > The tm_yday and tm_wday fields are not used by userspace, > > so since they aren't needed within the driver, don't > > bother calculating them. This is especially needed since > > the rtc_year_days() call was crashing if the HW returned > > an invalid time. > > > > Signed-off-by: Nick Crews > > --- > > drivers/rtc/rtc-wilco-ec.c | 4 ---- > > 1 file changed, 4 deletions(-) > > > > diff --git a/drivers/rtc/rtc-wilco-ec.c b/drivers/rtc/rtc-wilco-ec.c > > index 8ad4c4e6d557..e84faa268caf 100644 > > --- a/drivers/rtc/rtc-wilco-ec.c > > +++ b/drivers/rtc/rtc-wilco-ec.c > > @@ -110,10 +110,6 @@ 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; > > > > return 0; > > Are you sure? It would be bad to pass unititialized memory to userspace... > This problem doesn't exist because userspace is passing the memory, not the other way around. > If userspace does not need those fields, why are they there? > This is coming from struct tm, it is part of C89 but I think I was not born when this decision was made. man rtc properly reports that those fields are unused and no userspace tools are actually making use of them. Nobody cares about the broken down representation of the time. What is done is use the ioctl then mktime to have a UNIX timestamp. "The mktime function ignores the specified contents of the tm_wday, tm_yday, tm_gmtoff, and tm_zone members of the broken-down time structure. It uses the values of the other components to determine the calendar time; it’s permissible for these components to have unnormalized values outside their normal ranges. The last thing that mktime does is adjust the components of the brokentime structure, including the members that were initially ignored." -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com