From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388272; b=46KrfkRcuCjG+C1GY/K84f25aHS8K9D41NhloNpA/PPxUJHzwHej/E+8woXGF2cJ1u6V wYeQJ4RIY7mMuWjMbepyZeT5wWZHZbfWjoACRGYDJL2fbqMV/uT0bAP4RcIqHCPsd31/L lmlubBpeE9M+aO2xI5anpPNg3RUCZNrdEDKKuWxGPyj4N5M6TMuyCvumjC2B0fR6WzWWM h7caUG+YP3TjWSqSs/kZuPGOdS/4Fg311DQGe/dMQlNd5yB70wWo5+lQKATC8nLuO0BB3 6mzRkB6LR5AzYmG+Agx0KyTGR7tKk3X+dH0wIihHKIeRWW73e3mAe6713D+0kP8LH7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388272; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=zSNazQBW37zxqMn4tFFJ7Ekxryrzzl3bSHHx2ME7w64=; b=4tPOSVsRdf9Sx87Q9+IlO0EjJZVjOTpu14smpc8LVU/1zrj6DahkkABY6gTHvjWymxE4 CU8ayZ8RKHZzpPkaTGs7XCIUhYav3D4aA8M0cGkF3/CAm1WZeMZVvQ9kl8oiULIT2MyC8 casx9XWJ34jJGdTJQrBeaj89v4f/dEzD8WVNLRHwfalsMCJhVD/QUQYQc9/5gUvDaxIAS WdXvGZ/hAwk56LYMLwkUH7pFamUbxcajgSHwkkisEC701d8JzFZ83ni9wZBL48+oJU3Px +Y6EgqSOJd5A0O5A5KM9xvq/ePfUVwgLSKM5OIWxnz89wx1h7Dq9/+Fa+bw+qpw+mhg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tz5J2sHY; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A257F606A333; Fri, 4 Dec 2026 12:44:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tz5J2sHY Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41B6A1F00A0B; Fri, 4 Dec 2026 12:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388272; bh=zSNazQBW37zxqMn4tFFJ7Ekxryrzzl3bSHHx2ME7w64=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tz5J2sHY7BOgXLrHQ+MLiIQI7dZTzMOJ8Y5FC/NASLRvdAZms0z1K48+aJReDTdpF YxtEsZjkrmq1BDRYDjC/sp0Q2H9guMPKNLbzp8JN0I3T7BcjN31plku+8ZEocZhK5o 0eqik/nzu3JLAayoihsT2Kcq7cifSAX+QFExFCN4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Cunhao Lu <1579567540@qq.com>, Bartosz Golaszewski Subject: [PATCH 6.1 0552/1059] gpio: rockchip: Fix debounce arithmetic for GPIO v2 Date: Fri, 4 Dec 2026 19:01:23 +0900 Message-ID: <20261204100658.487842358@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cunhao Lu <1579567540@qq.com> commit 13467fd6998f5da4f5b4f172f1af3d9c48d5de8f upstream. The debounce interval calculations use unsigned long operands. On 32-bit systems, the numerator used to calculate the maximum interval overflows before division, while multiplying the requested interval by the clock rate overflows before it is assigned to a u64. A zero debounce clock rate also causes division by zero. Use 64-bit arithmetic for both calculations and reject a zero clock rate before division. At 32768 Hz, a 1 us request rounds to zero divider periods. Subtracting one then wraps the divider value to ULONG_MAX. Decrement only a nonzero rounded period count so that such requests use the smallest divider value. Fixes: 3bcbd1a85b68 ("gpio/rockchip: support next version gpio controller") Cc: stable@vger.kernel.org Signed-off-by: Cunhao Lu <1579567540@qq.com> Link: https://patch.msgid.link/20261023-fix-rockchip-gpio-v2-debounce-v1-1-f1141bd5b58f@qq.com Signed-off-by: Bartosz Golaszewski Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpio-rockchip.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -192,20 +192,25 @@ static int rockchip_gpio_set_debounce(st { struct rockchip_pin_bank *bank = gpiochip_get_data(gc); const struct rockchip_gpio_regs *reg = bank->gpio_regs; - unsigned long flags, div_reg, freq, max_debounce; + unsigned long flags, div_reg, freq; bool div_debounce_support; unsigned int cur_div_reg; - u64 div; + u64 div, max_debounce; if (bank->gpio_type == GPIO_TYPE_V2 && !IS_ERR(bank->db_clk)) { div_debounce_support = true; freq = clk_get_rate(bank->db_clk); - max_debounce = (GENMASK(23, 0) + 1) * 2 * 1000000 / freq; + if (!freq) + return -EINVAL; + + div = (u64)(GENMASK(23, 0) + 1) * 2 * USEC_PER_SEC; + max_debounce = div64_u64(div, freq); if (debounce > max_debounce) return -EINVAL; - div = debounce * freq; - div_reg = DIV_ROUND_CLOSEST_ULL(div, 2 * USEC_PER_SEC) - 1; + div = (u64)debounce * freq; + div_reg = DIV_ROUND_CLOSEST_ULL(div, 2 * USEC_PER_SEC); + div_reg = div_reg ? div_reg - 1 : 0; } else { div_debounce_support = false; }