From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D97DF18A6C4; Tue, 26 Aug 2025 13:24:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756214643; cv=none; b=kH/0TRcRTk2FtMZ0MsW8ZccoV6XBn+RFwgwiJ7ZJ/mDnfpM3Q1RQeO1CvBAEf5ir1651s1AiyzaNCogGyUW4nweU/lfbZ/1ZwXbhjgYDgT9IEMwEM/HOqBSrV9H5F9tHSZ0nXk6CrsiHpGc7R2+RMVsRisxhu08AURhYp8pgq4w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756214643; c=relaxed/simple; bh=iB/7C072X8c58BDA1B437rJokB3uTQjY/+hznbs41ec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=npCtoHUNtUsjvsWngSQIE0ntr5dHLEY1bi1GRe4x80CMcKIXj8bJW5/w34R5vAT2PtUn6xiaQjKgeYh3P/cJXCiK1aBjjVLQRcEjtH+Y049AvKjjmO9NXNQKTS12WRSk1yYJ66VDKBdfQ1O7WEuMhCQJEFzOJU9uJAlTlwlWewk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LJwpHdwG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="LJwpHdwG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D2CDC4CEF1; Tue, 26 Aug 2025 13:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756214643; bh=iB/7C072X8c58BDA1B437rJokB3uTQjY/+hznbs41ec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LJwpHdwGBrFrSI4kK7gXKMvB8c9cqNFz+mJG8FjdUo8kf1wAEkRnjm3G1uNZ0iJ9f f4f0jegj78nDQVawO5F0Ha9nzUYL1zwh/NVxSlMUNb4y3t1FVSygdzOo3ze/ciN4ME rKJEDwQ6wXpuQ2NIqi/s4nWxF+y2AFMZrQh2A7Gs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ziyan Fu , Guenter Roeck , Wim Van Sebroeck , Sasha Levin Subject: [PATCH 6.1 184/482] watchdog: iTCO_wdt: Report error if timeout configuration fails Date: Tue, 26 Aug 2025 13:07:17 +0200 Message-ID: <20250826110935.352437584@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250826110930.769259449@linuxfoundation.org> References: <20250826110930.769259449@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ziyan Fu [ Upstream commit 40efc43eb7ffb5a4e2f998c13b8cfb555e671b92 ] The driver probes with the invalid timeout value when 'iTCO_wdt_set_timeout()' fails, as its return value is not checked. In this case, when executing "wdctl", we may get: Device: /dev/watchdog0 Timeout: 30 seconds Timeleft: 613 seconds The timeout value is the value of "heartbeat" or "WATCHDOG_TIMEOUT", and the timeleft value is calculated from the register value we actually read (0xffff) by masking with 0x3ff and converting ticks to seconds (* 6 / 10). Add error handling to return the failure code if 'iTCO_wdt_set_timeout()' fails, ensuring the driver probe fails and prevents invalid operation. Signed-off-by: Ziyan Fu Reviewed-by: Guenter Roeck Link: https://lore.kernel.org/r/20250704073518.7838-1-13281011316@163.com Signed-off-by: Guenter Roeck Signed-off-by: Wim Van Sebroeck Signed-off-by: Sasha Levin --- drivers/watchdog/iTCO_wdt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c index 35ae40b35f55..75fb7cf7325b 100644 --- a/drivers/watchdog/iTCO_wdt.c +++ b/drivers/watchdog/iTCO_wdt.c @@ -601,7 +601,11 @@ static int iTCO_wdt_probe(struct platform_device *pdev) /* Check that the heartbeat value is within it's range; if not reset to the default */ if (iTCO_wdt_set_timeout(&p->wddev, heartbeat)) { - iTCO_wdt_set_timeout(&p->wddev, WATCHDOG_TIMEOUT); + ret = iTCO_wdt_set_timeout(&p->wddev, WATCHDOG_TIMEOUT); + if (ret != 0) { + dev_err(dev, "Failed to set watchdog timeout (%d)\n", WATCHDOG_TIMEOUT); + return ret; + } dev_info(dev, "timeout value out of range, using %d\n", WATCHDOG_TIMEOUT); } -- 2.39.5