Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp599819pxb; Tue, 19 Oct 2021 09:08:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwI2AxTgPxptbAw5Bjq6no61pb1K7M5z2WOfEToMClBzQHvE1nI2/u7TXyTA9yMCTmEUNAz X-Received: by 2002:a7b:c741:: with SMTP id w1mr6910212wmk.9.1634659691943; Tue, 19 Oct 2021 09:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634659691; cv=none; d=google.com; s=arc-20160816; b=TOBshIxsCesuHGWzjeQl7ZjvVppo5vlDclNxvlWXux/33Zg1Rbvu1HWFY3uWs2/9Sj 6TEcRFAcmfb5ngj8jZNmRJiNEtfGoddtQ/p0t2oQ6mnhFgqdWlKLyNbh/nIbb6FJ2W4E omKdrnvqdA8nn6Mhnt6lDWPOV1fS9Sp30pvMOvJDoeCchUm16Q3ENFjdgRbIXhH41Ogu yzi0I8IJuzaTjBs0fqSmhT+GZmTiRc01glc1Bv3yhPXmyQ/oJeMZWtboH0kbu12SXtuI 1wq93n+JqEBcD9EhkO3Phm6WsuOIGYnCeipYjc6Fd7zpt3tuZn7SXu/698L44Zw6NZnB ZK3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5J1xMt/vQlR8SVOww8V/YvYALhrphrCuVMa2HeQBAzE=; b=fm4M4BTQc2bXAStbo3mN2uBCm7rxEO/gCTn5ZAXye2ctYa14yZJtJc5etRgUVy9Ce8 5Vy67CdVtsAsTMyj8xWNtjyjtw7ki1eR25yxuLAmy+QG/XjDy14FKgvxxVjoohlnAMlx pNcZ676Y+G3Aw3MvDEEFe8BPVznNKoWDLLjpYkWopYe7RVqdaVhcY4zgW+8Hmzoz5uKY FufsCuPOjlTPxESyMs0MRifOryAcgcpf800sOXbVp+Gq5oN2Wuoznkn+HBHjupSnrtnE zqlG8EnujZfPlqFXPazGoRd79lmN6wMJ29lVDrudwvdjq0vaCVWcLDa2l1W9DnftNPbe FWQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fX3bi6ey; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a28si23031233edj.191.2021.10.19.09.07.47; Tue, 19 Oct 2021 09:08:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fX3bi6ey; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234125AbhJSQG7 (ORCPT + 99 others); Tue, 19 Oct 2021 12:06:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234184AbhJSQGt (ORCPT ); Tue, 19 Oct 2021 12:06:49 -0400 Received: from mail-ua1-x929.google.com (mail-ua1-x929.google.com [IPv6:2607:f8b0:4864:20::929]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A32D6C061769 for ; Tue, 19 Oct 2021 09:04:35 -0700 (PDT) Received: by mail-ua1-x929.google.com with SMTP id i22so839927ual.10 for ; Tue, 19 Oct 2021 09:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5J1xMt/vQlR8SVOww8V/YvYALhrphrCuVMa2HeQBAzE=; b=fX3bi6ey8uPD0A0n8+0h4il+uzx946plN1BAtTJ7rzpPI8ZO0JJs5fcCkR9GNNqoRZ H7kOZInq9pMr2LJkJt8p3rPUVlx++EIJJBWllI8UI9V4xDk705FU+8a5Rsr1G7vVts6n UNQM1r1jr5QNY+uFxnN+s4zFfuBlH4qrFQ8s4jNP1TmjszCeNhWvZk4CO5d/SwLY+TGe 6Teyju4FQq1SUW8ZOWAeCabVBQHPjZ0eb12z+MZcHCAnCRtIY/oR5gV6748faOcR4Fk8 yFGEOaxrVpKJhTk72O2aASsNtG++CCTj6ufiSGBMvMuIyyQLyRO7eEzyRpJiBB7ungIE zLHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5J1xMt/vQlR8SVOww8V/YvYALhrphrCuVMa2HeQBAzE=; b=wLi99sXMPIpdBs/WbA/YBHSP2mBkk3qBr98GZJ9y5vJwzFSG1+mlQMkrFB4YiUA0I2 WNwY80rZdCJRjYFczgVn5aQWBopQvSiSeMcISk3n2wsy6ytf9QtZbPfM1Ul1RL/0yzUA +a+n/15noMbFCqiuS+724xSDBiLWXotuqq6TZMk8LkYJ2Y4NHJeYBGR55CO6/jamr5dP t5iAI6sSREqewlgCSp7CW8/PBZF+RgyKUfY7oFSqwaFIdzV0nmLeF5Ek6wN4J0oe6C2v 36Avy+s6xSiEoby6CqhwzXGt4M6FJT2tWgRknKBP98W1wnXxkqNP1bvTnOoDHSGsaJq9 nxRQ== X-Gm-Message-State: AOAM5332cQvizcoGrY/blGb85OODn6HqGQCwH2aY5Oq0pwaNBSe6SLUP nlLd8J5JrEROiF4UsGPCbbwB1w6JQ51WjoDxAI/4rA== X-Received: by 2002:ab0:3303:: with SMTP id r3mr872053uao.17.1634659474630; Tue, 19 Oct 2021 09:04:34 -0700 (PDT) MIME-Version: 1.0 References: <20211019131724.3109-1-semen.protsenko@linaro.org> <20211019131724.3109-5-semen.protsenko@linaro.org> In-Reply-To: From: Sam Protsenko Date: Tue, 19 Oct 2021 19:04:23 +0300 Message-ID: Subject: Re: [PATCH 4/4] rtc: s3c: Fix RTC read on first boot To: Alexandre Belloni Cc: Alessandro Zummo , Krzysztof Kozlowski , linux-rtc@vger.kernel.org, Linux Samsung SOC , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 19 Oct 2021 at 18:48, Alexandre Belloni wrote: > > On 19/10/2021 16:17:24+0300, Sam Protsenko wrote: > > On first RTC boot it has the month register value set to 0. > > Unconditional subtracting of 1 subsequently in s3c_rtc_gettime() leads > > to the next error message in kernel log: > > > > hctosys: unable to read the hardware clock > > > > That happens in s3c_rtc_probe() when trying to register the RTC, which > > in turn tries to read and validate the time. Initialize RTC date/time > > registers to valid values in probe function on the first boot to prevent > > such errors. > > > > No, never ever do that, the time is bogus and it has to stay this way, > else userspace can't know whether the time on the RTC is the actual wall > time or just some random value that you have set from the driver. > Thought about that, but that error message looked distracting and not very helpful in understanding what's actually going on. Anyway, can you please drop this patch from series (and maybe [PATCH 3/4] too) and apply the rest? > > Signed-off-by: Sam Protsenko > > --- > > drivers/rtc/rtc-s3c.c | 26 ++++++++++++++++++++++++++ > > 1 file changed, 26 insertions(+) > > > > diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c > > index 238928e29fbc..c7e763bcf61f 100644 > > --- a/drivers/rtc/rtc-s3c.c > > +++ b/drivers/rtc/rtc-s3c.c > > @@ -403,6 +403,28 @@ static int s3c_rtc_remove(struct platform_device *pdev) > > return 0; > > } > > > > +/* Set RTC with valid date/time values on first boot */ > > +static int s3c_rtc_init_time(struct s3c_rtc *info) > > +{ > > + struct rtc_time tm; > > + int ret; > > + > > + ret = s3c_rtc_read_time(info, &tm); > > + if (ret) > > + return ret; > > + > > + /* Only init RTC date/time on first boot */ > > + if (tm.tm_mday > 0) > > + return 0; > > + > > + /* Init date/time: 1 Jan 2000 00:00:00 */ > > + memset(&tm, 0, sizeof(struct rtc_time)); > > + tm.tm_mday = 1; /* tm_mday min valid value is 1 */ > > + tm.tm_mon = 1; /* January in internal representation */ > > + > > + return s3c_rtc_write_time(info, &tm); > > +} > > + > > static int s3c_rtc_probe(struct platform_device *pdev) > > { > > struct s3c_rtc *info = NULL; > > @@ -471,6 +493,10 @@ static int s3c_rtc_probe(struct platform_device *pdev) > > > > device_init_wakeup(&pdev->dev, 1); > > > > + ret = s3c_rtc_init_time(info); > > + if (ret) > > + goto err_nortc; > > + > > info->rtc = devm_rtc_allocate_device(&pdev->dev); > > if (IS_ERR(info->rtc)) { > > ret = PTR_ERR(info->rtc); > > -- > > 2.30.2 > > > > -- > Alexandre Belloni, co-owner and COO, Bootlin > Embedded Linux and Kernel engineering > https://bootlin.com