Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2262851pxk; Sun, 27 Sep 2020 00:54:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8tStn2xeD1QaHJGf6sGCtedmfyJ9Tvm71R7Oy9/ZZGiHBzIzDAHltjeLQEuL9o836CSm8 X-Received: by 2002:a05:6402:1451:: with SMTP id d17mr9815294edx.48.1601193261334; Sun, 27 Sep 2020 00:54:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601193261; cv=none; d=google.com; s=arc-20160816; b=TinbOrCwpz93ZdKHX8bJI6e8y1bn5Dg0eBO0cGTZ76kUbjt1WIUX+8YGEolOC38S+t 49cO9UzTTHuucMfMXUkTx7C707p5cqT/QfgoROuVeDWK4RjHxcxBqZcTuzUCrAwcwHHn N4+UxxGDYnHtqyglxvxADaX6c8SVZ0CudlyFqS79giQzZOAmUgAdJKQiok5dwMndBahK Heoh7Hwwwaj2InvMPydbvdu9dYrSURbQ9zBG5/ItK4enFbO4SJf/DiTlmFsXy9ehYtTN mxMtFEsRGgKnTEfT28mfF4Ejm06uoSiUH1L9SRE3Wcc/cMwBdFd3CZTdpI5Co0CrmRmv gdzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=xiszwSzHIPu42VE8ycq9IrzTJRg5eh3Qelq5ghdg0ls=; b=rVbrjrZCfkq/r+c7GjAzSPHx9RNVVxnZuQS90j0RQigOmLBxsanCnH0tGZ3PhVEt4p N6g2JZzIQlGTekJehk9EYFAhGL2CcWgCHCH5u75jUBey+sND7ImB8seM4taEv/n4gzno XFJC5JMXfYaOIXtfPf9dTCXz0QkhrSqx8S+i3dJ/H6D1GsPejcITds4YCyqM4SeAgkRO SaJ81NdTEA08iRl2k3fNHfEW/v7hD+5mKSyP1ysPoAU+YL2cCg1fsXXzyjNpJdXgIi+U RhXJoqZTrnYVRsepSe6/6asZE/nhTgKIjFMdnpx0FlI264AnYmcIia4Gt3o1gy6IxlVo TnlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=F36JFRR2; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ec11si5097535ejb.540.2020.09.27.00.53.57; Sun, 27 Sep 2020 00:54:21 -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=@gmail.com header.s=20161025 header.b=F36JFRR2; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730548AbgI0HvN (ORCPT + 99 others); Sun, 27 Sep 2020 03:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730439AbgI0HvG (ORCPT ); Sun, 27 Sep 2020 03:51:06 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29C97C0613CE; Sun, 27 Sep 2020 00:51:06 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id p15so4103735ejm.7; Sun, 27 Sep 2020 00:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=xiszwSzHIPu42VE8ycq9IrzTJRg5eh3Qelq5ghdg0ls=; b=F36JFRR2gw4ZLJ4VQJsJYSQOIEhyhd+ZMKXffeDvfDTakEIRy3DWcaZVJOhPcmAzes zl+fh9At5nHsvyvnr+1/xp1hsTpvH9AWkxilc+L+7uTryxgc5mDNl9THb9Y02yR+wy0h fEepZ2B7QS370fdsvaPwvPmQ9qJ1sLReeD7uUOqtBmm0ixp7WwuPiCm0SyJ56K/BI6VF gyiD8h4zDX0u8mgWQ1iYRvkksiKIDcqejWKWKu5PWse/Xj8YhhCeZCsQxAHT0pl/RSeh sInY2x52eF+F5nsyneFvZNAQuJk57IqGjueS6wUZpndYlSwGh3LMSRTnlIRqxpuSkEsy HwnQ== 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:content-transfer-encoding; bh=xiszwSzHIPu42VE8ycq9IrzTJRg5eh3Qelq5ghdg0ls=; b=QbR0JczV6fdCrho3+cH9LWWwhlL2cFUHbiuCul7BObpkinTJG4x09rA/+KrWMJ06PJ 5TH2Joov65fXmv1wC1VQ07hHnalaId2rIJZAWcoq4Vq5S7S3hyKwvVw4rP6lGbDyKiCU NorWM9vO35XNldf1q6eNa8WCFEL2tB2E7mWhZkPTuuD/nh2zHZD+SOe2V7IEjeQfj8Sr tE0nTpL5hXoRdDfLarWTHviwSvJk07zqaoChs5utGj5J5cvYv5E2bt2+6UpYF7hjrdc4 Z/WeY11ZeJ6tcdaHTM1p6HHRlWKhrYSk4BLmpSLtmsVjeE8NKW1RsxCQDMOQsVhlr3Hb tUEg== X-Gm-Message-State: AOAM533/V1eQZuvG4pd8GndOZkEauJxr3su6T0l75XbsYGtwbNatcIvw ANiK+NlxnHS2wR3zoW4YgfHPGO0uZY3LIwnrKAM= X-Received: by 2002:a17:906:8682:: with SMTP id g2mr10436779ejx.110.1601193064793; Sun, 27 Sep 2020 00:51:04 -0700 (PDT) MIME-Version: 1.0 References: <20200924074715.GT9675@piout.net> <20200924105256.18162-1-u.kleine-koenig@pengutronix.de> <20200924105256.18162-2-u.kleine-koenig@pengutronix.de> In-Reply-To: <20200924105256.18162-2-u.kleine-koenig@pengutronix.de> From: Bruno Thomsen Date: Sun, 27 Sep 2020 09:50:48 +0200 Message-ID: Subject: Re: [PATCH 1/2] rtc: pcf2127: move watchdog initialisation to a separate function To: =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= Cc: Alexandre Belloni , Qiang Zhao , linux-rtc@vger.kernel.org, Alessandro Zummo , linux-watchdog@vger.kernel.org, "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , open list , Rob Herring , Sascha Hauer , Wim Van Sebroeck , Guenter Roeck Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Den tor. 24. sep. 2020 kl. 12.53 skrev Uwe Kleine-K=C3=B6nig : > > The obvious advantages are: > > - The linker can drop the watchdog functions if CONFIG_WATCHDOG is off. > - All watchdog stuff grouped together with only a single function call > left in generic code. > - Watchdog register is only read when it is actually used. > - Less #ifdefery > > Signed-off-by: Uwe Kleine-K=C3=B6nig > --- > drivers/rtc/rtc-pcf2127.c | 56 ++++++++++++++++++++++----------------- > 1 file changed, 31 insertions(+), 25 deletions(-) > > diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c > index ed6316992cbb..5b1f1949b5e5 100644 > --- a/drivers/rtc/rtc-pcf2127.c > +++ b/drivers/rtc/rtc-pcf2127.c > @@ -335,6 +335,36 @@ static const struct watchdog_ops pcf2127_watchdog_op= s =3D { > .set_timeout =3D pcf2127_wdt_set_timeout, > }; > > +static int pcf2127_watchdog_init(struct device *dev, struct pcf2127 *pcf= 2127) > +{ > + u32 wdd_timeout; > + int ret; > + > + if (!IS_ENABLED(CONFIG_WATCHDOG)) > + return 0; > + > + pcf2127->wdd.parent =3D dev; > + pcf2127->wdd.info =3D &pcf2127_wdt_info; > + pcf2127->wdd.ops =3D &pcf2127_watchdog_ops; > + pcf2127->wdd.min_timeout =3D PCF2127_WD_VAL_MIN; > + pcf2127->wdd.max_timeout =3D PCF2127_WD_VAL_MAX; > + pcf2127->wdd.timeout =3D PCF2127_WD_VAL_DEFAULT; > + pcf2127->wdd.min_hw_heartbeat_ms =3D 500; > + pcf2127->wdd.status =3D WATCHDOG_NOWAYOUT_INIT_STATUS; > + > + watchdog_set_drvdata(&pcf2127->wdd, pcf2127); > + > + /* Test if watchdog timer is started by bootloader */ > + ret =3D regmap_read(pcf2127->regmap, PCF2127_REG_WD_VAL, &wdd_tim= eout); > + if (ret) > + return ret; > + > + if (wdd_timeout) > + set_bit(WDOG_HW_RUNNING, &pcf2127->wdd.status); > + > + return devm_watchdog_register_device(dev, &pcf2127->wdd); > +} > + > /* Alarm */ > static int pcf2127_rtc_read_alarm(struct device *dev, struct rtc_wkalrm = *alrm) > { > @@ -536,7 +566,6 @@ static int pcf2127_probe(struct device *dev, struct r= egmap *regmap, > int alarm_irq, const char *name, bool has_nvmem) > { > struct pcf2127 *pcf2127; > - u32 wdd_timeout; > int ret =3D 0; > > dev_dbg(dev, "%s\n", __func__); > @@ -575,17 +604,6 @@ static int pcf2127_probe(struct device *dev, struct = regmap *regmap, > pcf2127->rtc->ops =3D &pcf2127_rtc_alrm_ops; > } > > - pcf2127->wdd.parent =3D dev; > - pcf2127->wdd.info =3D &pcf2127_wdt_info; > - pcf2127->wdd.ops =3D &pcf2127_watchdog_ops; > - pcf2127->wdd.min_timeout =3D PCF2127_WD_VAL_MIN; > - pcf2127->wdd.max_timeout =3D PCF2127_WD_VAL_MAX; > - pcf2127->wdd.timeout =3D PCF2127_WD_VAL_DEFAULT; > - pcf2127->wdd.min_hw_heartbeat_ms =3D 500; > - pcf2127->wdd.status =3D WATCHDOG_NOWAYOUT_INIT_STATUS; > - > - watchdog_set_drvdata(&pcf2127->wdd, pcf2127); > - > if (has_nvmem) { > struct nvmem_config nvmem_cfg =3D { > .priv =3D pcf2127, > @@ -615,19 +633,7 @@ static int pcf2127_probe(struct device *dev, struct = regmap *regmap, > return ret; > } > > - /* Test if watchdog timer is started by bootloader */ > - ret =3D regmap_read(pcf2127->regmap, PCF2127_REG_WD_VAL, &wdd_tim= eout); > - if (ret) > - return ret; > - > - if (wdd_timeout) > - set_bit(WDOG_HW_RUNNING, &pcf2127->wdd.status); > - > -#ifdef CONFIG_WATCHDOG > - ret =3D devm_watchdog_register_device(dev, &pcf2127->wdd); > - if (ret) > - return ret; > -#endif /* CONFIG_WATCHDOG */ > + pcf2127_watchdog_init(dev, pcf2127); The code refactoring seems like a good idea Uwe, but the new pcf2127_watchdog_init() is not a void function. If the return value is not handled, it will change driver behavior. Correct handling should look like this: ret =3D pcf2127_watchdog_init(dev, pcf2127); if (ret) return ret; /Bruno > /* > * Disable battery low/switch-over timestamp and interrupts. > -- > 2.28.0 >