Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 D61BB4E4C54; Thu, 17 Sep 2026 17:29:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789666163; cv=none; b=A5Kg4ti/9jOiGxs2NpVhVP2OIfe+0ulkMLy8/JU8JsTrKYXfjjBhNorRM/fGq+TdHJuZg29jQrChjkMd6ujD+KVkwO5nGRLe6kJY4xnftXfqSkhhnaBiiwPGerRUX8OUFnSOY5vmRny6CjNXcaIWLVUAZOmzXDNG16sDK9kJZxI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789666163; c=relaxed/simple; bh=IhlPzyxY3G69v4K5Z1+be4Rr9IBDhLKS60UWGqRHmv4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CI6Kf/MLxwcTdIGM51mE22zNumpscEjCUe3IVu36ptvpPrKCRBYvJmq6T1IBbfUS2aq09XepFiFWrofomuzc9X29FynxE/g3n+T6+fgIkSRJec0nEi6B06F7NIMGjOM/Nl3Ab+nOVRC8aOFPg0/dZuRFBliaWWUyUP+07eREMlI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=mU1DL0FR; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="mU1DL0FR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A3631F000FF; Thu, 17 Sep 2026 17:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789666161; bh=Pygu9ypO+Tba77S+0pR9eSX/4TRqEMeQFWs5yx1T16I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mU1DL0FRwswQcYhhoYmIZ+LToMrcDoAZVKPqXuf9O5qkLG2czskuXLBdgoMNZQyuY hdTFemtdfelg3gfjUYmvJ+8J3BgYIj3nmj7vLwB7LcrpoySc36VJfoiTY82WZVx3jv LvD9tL2qGqOwBnujvMdei9hn6hNQKai15DPqXQ6M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tzung-Bi Shih , Guenter Roeck , Sasha Levin Subject: [PATCH 6.18 0896/1250] watchdog: msc313e: Fix undefined behavior Date: Thu, 17 Sep 2026 16:11:31 +0100 Message-ID: <20260917151616.272833149@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917151551.901433442@linuxfoundation.org> References: <20260917151551.901433442@linuxfoundation.org> User-Agent: quilt/0.69 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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tzung-Bi Shih [ Upstream commit ab390021b2a3bb4cc875f28a6f76d13de90d7457 ] readw() returns a u16. Left shifting a u16 by 16 bits yields undefined behavior. Cast to u32 explicitly before the shift. Fixes: ffd264bd152c ("watchdog: msc313e: Check if the WDT was running at boot") Signed-off-by: Tzung-Bi Shih Link: https://patch.msgid.link/20260828161348.13212-7-tzungbi@kernel.org Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/watchdog/msc313e_wdt.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/msc313e_wdt.c b/drivers/watchdog/msc313e_wdt.c index 9cfe059fd31a7..72620adec641a 100644 --- a/drivers/watchdog/msc313e_wdt.c +++ b/drivers/watchdog/msc313e_wdt.c @@ -32,6 +32,16 @@ struct msc313e_wdt_priv { struct clk *clk; }; +static u32 msc313e_wdt_get_hw_timeout(struct msc313e_wdt_priv *priv) +{ + u16 low, high; + + low = readw(priv->base + REG_WDT_MAX_PRD_L); + high = readw(priv->base + REG_WDT_MAX_PRD_H); + + return ((u32)high << 16) | low; +} + static void msc313e_wdt_set_hw_timeout(struct msc313e_wdt_priv *priv, unsigned int timeout) { @@ -140,7 +150,7 @@ static int msc313e_wdt_probe(struct platform_device *pdev) return ret; /* If the period is non-zero the WDT is running */ - if (readw(priv->base + REG_WDT_MAX_PRD_L) | (readw(priv->base + REG_WDT_MAX_PRD_H) << 16)) { + if (msc313e_wdt_get_hw_timeout(priv)) { set_bit(WDOG_HW_RUNNING, &priv->wdev.status); /* * Keep the clock enabled. The watchdog core will skip the next -- 2.53.0