[{"id":3688365,"web_url":"http://patchwork.ozlabs.org/comment/3688365/","msgid":"<6cf43fb7-f39a-437e-bcdb-23a4d20d2b10@mailbox.org>","list_archive_url":null,"date":"2026-05-08T11:49:28","subject":"Re: [PATCH RESEND] watchdog: sbsa_gwdt: clamp WOR value to hw max","submitter":{"id":69987,"url":"http://patchwork.ozlabs.org/api/people/69987/","name":"Stefan Roese","email":"stefan.roese@mailbox.org"},"content":"On 5/4/26 11:34, Juuso Rinta wrote:\n> The WOR register is 32 bits, so any tick count exceeding U32_MAX is\n> truncated by writel(). A large requested timeout can wrap to a small\n> value causing the watchdog to fire sooner than requested.\n> \n> Clamp the calculated value to U32_MAX prior to writing the register so\n> over-large requests will be set to the maximum timeout value.\n> \n> Found by code review.\n> \n> Signed-off-by: Juuso Rinta <juuso.rinta@nokia.com>\n\nReviewed-by: Stefan Roese <stefan.roese@mailbox.org>\n\nThanks,\nStefan\n\n\n> ---\n>   drivers/watchdog/sbsa_gwdt.c | 10 ++++++++--\n>   1 file changed, 8 insertions(+), 2 deletions(-)\n> \n> diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c\n> index 807884c5bc7..3a924cb2b9a 100644\n> --- a/drivers/watchdog/sbsa_gwdt.c\n> +++ b/drivers/watchdog/sbsa_gwdt.c\n> @@ -50,6 +50,7 @@ static int sbsa_gwdt_start(struct udevice *dev, u64 timeout, ulong flags)\n>   {\n>   \tstruct sbsa_gwdt_priv *priv = dev_get_priv(dev);\n>   \tu32 clk;\n> +\tu64 tout_wdog;\n>   \n>   \t/*\n>   \t * it work in the single stage mode in u-boot,\n> @@ -58,8 +59,13 @@ static int sbsa_gwdt_start(struct udevice *dev, u64 timeout, ulong flags)\n>   \t * to half value of timeout.\n>   \t */\n>   \tclk = get_tbclk();\n> -\twritel(clk / (2 * 1000) * timeout,\n> -\t       priv->reg_control + SBSA_GWDT_WOR);\n> +\n> +\t/* if requested timeout overflows, clamp it to u32_max */\n> +\ttout_wdog = ((u64)clk * timeout) / (2 * 1000);\n> +\tif (tout_wdog > U32_MAX)\n> +\t\ttout_wdog = U32_MAX;\n> +\n> +\twritel(tout_wdog, priv->reg_control + SBSA_GWDT_WOR);\n>   \n>   \t/* writing WCS will cause an explicit watchdog refresh */\n>   \twritel(SBSA_GWDT_WCS_EN, priv->reg_control + SBSA_GWDT_WCS);\n> \n> ---\n> base-commit: 4433253ecf2041f9362a763bb6cb79960921ac7e\n> change-id: 20260428-fix-sbsa-timeout-overflow-20cf84fa8a6b\n> \n> Best regards,\n> --\n> Juuso Rinta <juuso.rinta@nokia.com>","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256\n header.s=mail20150812 header.b=q6Trd1C/;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org)","phobos.denx.de;\n dmarc=pass (p=reject dis=none) header.from=mailbox.org","phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de","phobos.denx.de;\n\tdkim=pass (2048-bit key;\n secure) header.d=mailbox.org header.i=@mailbox.org header.b=\"q6Trd1C/\";\n\tdkim-atps=neutral","phobos.denx.de;\n dmarc=pass (p=reject dis=none) header.from=mailbox.org","phobos.denx.de;\n spf=pass smtp.mailfrom=stefan.roese@mailbox.org"],"Received":["from phobos.denx.de (phobos.denx.de\n [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4gBnTw1kMVz1yJq\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 08 May 2026 21:49:39 +1000 (AEST)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 1FA0184BBD;\n\tFri,  8 May 2026 13:49:36 +0200 (CEST)","by phobos.denx.de (Postfix, from userid 109)\n id C85C484BD1; Fri,  8 May 2026 13:49:34 +0200 (CEST)","from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id D40B384A5A\n for <u-boot@lists.denx.de>; Fri,  8 May 2026 13:49:32 +0200 (CEST)","from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4gBnTl1FCsz9t9P;\n Fri,  8 May 2026 13:49:31 +0200 (CEST)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,\n DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,\n SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org;\n s=mail20150812; t=1778240971;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=HZY4MY+Z4JHfba2dzRnk3PRJrpf1VRZvsic43olzL+w=;\n b=q6Trd1C/pHPgGkbGOHf1w+bJHXKf9yFNQstk9owgmSCjEBUGJ2k5lfr65dTDYnUBUvrV1+\n 50kKlN+O4QTkVCP1sA4pU+GwZaGtXfALPM5rpnpqScYnMXk42CEYDXBuHVGHsSbce6YOxQ\n k/fFeIjTAPFvQKXTljudzWwS/qGYlk0880CK0CUOkWYtOqX1MvjxqSjH/SdSvmj5UnQWVU\n XgBuJRNBlRWbNaiU2C49pl2yxvebY/IfmBX8KX/5BUJVxSYapaBYlAG1ocuDwVG3kaUuYB\n Pjg5Zw4Db22jK8j2WAQm7jhdpup0hPXtLAYu6djuaRjRkjzO6e3KBZ4m1kk5WA==","Message-ID":"<6cf43fb7-f39a-437e-bcdb-23a4d20d2b10@mailbox.org>","Date":"Fri, 8 May 2026 13:49:28 +0200","MIME-Version":"1.0","Subject":"Re: [PATCH RESEND] watchdog: sbsa_gwdt: clamp WOR value to hw max","To":"Juuso Rinta <juuso.rinta@nokia.com>, u-boot@lists.denx.de","Cc":"Peng Fan <peng.fan@nxp.com>, Tom Rini <trini@konsulko.com>,\n Patrice Chotard <patrice.chotard@foss.st.com>, Yao Zi <me@ziyao.cc>","References":"<20260504-fix-sbsa-timeout-overflow-v1-1-87de9b44112f@nokia.com>","Content-Language":"en-US","From":"Stefan Roese <stefan.roese@mailbox.org>","In-Reply-To":"<20260504-fix-sbsa-timeout-overflow-v1-1-87de9b44112f@nokia.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","X-MBO-RS-ID":"172e935dc0778df76ca","X-MBO-RS-META":"yigzn94myf4os4udaaig5qmm3c87cw74","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.39","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<https://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=subscribe>","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>","X-Virus-Scanned":"clamav-milter 0.103.8 at phobos.denx.de","X-Virus-Status":"Clean"}}]