From nobody Sun May 24 21:40:17 2026 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (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 908E837FF54; Thu, 21 May 2026 09:54:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357276; cv=none; b=Kpu6TxmE0SDwVd/5eWiV7/SzmXg/+YGsHgSjJNjhFZv3ijKizCG/9zj8ItjnNkDuP0DJt96wNzmajFf6XVfbKQmAuFD4ahEzbSuhabzraFF1r0PGHow/FmKyxAf7i/pShwn/wt6nHRu2KfLhnVmTq2yw9bKmb+oflIu43/qAf8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779357276; c=relaxed/simple; bh=O5JSAKkDwgIWKtGeQopbZHKrSeY9OSjYeqvakGnnEwA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=G7jXbGUWi/0WoT96sI1Zt6SRe/k5gP5E38kO8YtF38nJfQxR1+E1vYZ115D4pBVCMKKuYQKE0uOrXXE1BwW8mPxDDsk9EK0iHhe4Of5W28ZzNQ4DVuQig/LxXWTpmfwfhRRva2e/lBTRcpO3OfnmKYghUvDd/VS1YnH1WIun6zQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=nSU0Lq5H; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=YiYx2wtD; arc=none smtp.client-ip=80.241.56.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="nSU0Lq5H"; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="YiYx2wtD" Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4gLkK33WwPz9t4w; Thu, 21 May 2026 11:54:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1779357271; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZBfCE1tFEw1bHwVhbXsEcGvBGEMDeaoxSgRqgJTJ9o0=; b=nSU0Lq5HyQqkFkbqIdXT9Blb6N3UNZVpqN2iMx+JHIbrRf7cbbc1oZxM7akGlRFWHUmn/8 DSICq3E7PaJJKqT293eciMZ3QB5aLZTEXg6FH/WtFQp8IBHdO0UbQGboSbQ5Qnf3/EmssM Xi0/Or1PcE9zP3/rvInQVNlTih54f5XlkHOjdpNogIMJAwxePMlCzdQXBxshmrb2zMBAck 0oDgI0Z8tLs3thJptkKRM6M7C0zn+lS2mKxWIHR3j31VQLJk8SOrwWgiHB1ZYAtwbbNrh/ VINV8uDDeYvyzSuRMf95MX9RtOQ7JgjXm0CDr2Oaiud9Qbd6GbgfPiHatAuovg== Authentication-Results: outgoing_mbo_mout; dkim=pass header.d=mailbox.org header.s=mail20150812 header.b=YiYx2wtD; spf=pass (outgoing_mbo_mout: domain of mhi@mailbox.org designates 2001:67c:2050:b231:465::2 as permitted sender) smtp.mailfrom=mhi@mailbox.org From: Maurice Hieronymus DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1779357269; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZBfCE1tFEw1bHwVhbXsEcGvBGEMDeaoxSgRqgJTJ9o0=; b=YiYx2wtDp2CyM5Y6pBWSfoab5hHzcMT97ZjKyxRkzjDhxCyALo0IFwC6Yl/Bl6/Q5UKIOw 7v6UXSIdYdoLa2z+881yGo8+yBG/VA7Jtzn4/fdV3KjpmdAAMzvkTIuDL4f2dHHBSz68RG 2sKu49Qexh2u6PCCUSJil2fAMy9MT6bQNYdW/yn2REH5uyQMnxdwQlnLxDObanAUbpCJn0 3KMllb+Ndo9YA1x+L18bs3cDVveqz0R14/2VEN68PWa7V9E7y1hyiN/afHf+QE8d5p5183 KqPLsyl4SEeynNqRdR9M25Q92+z2lgvqMvlqyiIsZi7u69Nf9KLyZQAaF7LBrQ== Date: Thu, 21 May 2026 11:53:59 +0200 Subject: [PATCH] pwm: th1520: Remove requirement for mul_u64_u64_div_u64_roundup Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-pwm-th1520-fix-v1-1-df9cd956dab4@mailbox.org> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIzMDUyND3YLyXN2SDENTIwPdtMwKXYtUE1NTU4ukpBRjQyWgpoKiVKAw2MD o2NpaAH9Rl1JgAAAA X-Change-ID: 20260521-pwm-th1520-fix-8e45558bbd31 To: Drew Fustini , Guo Ren , Fu Wei , Michal Wilczynski , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: linux-riscv@lists.infradead.org, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Maurice Hieronymus X-MBO-RS-ID: c7d68cde2b283687114 X-MBO-RS-META: u84cfcd635d5m45as961oynfre6h9ony X-Rspamd-Queue-Id: 4gLkK33WwPz9t4w The cycle register is always u32, so cycles_to_ns() can take a u32 instead of a u64. With that narrowing, cycles * NSEC_PER_SEC is at most u32::MAX * 1e9 (~4.3e18), which fits in u64 without overflow. The saturating arithmetic is therefore no longer needed, and the ceiling division can use Rust's u64::div_ceil() directly instead of the open-coded numerator/denominator form. This also drops the TODO referring to a future mul_u64_u64_div_u64_roundup kernel helper, which is no longer required. Signed-off-by: Maurice Hieronymus --- drivers/pwm/pwm_th1520.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/pwm/pwm_th1520.rs b/drivers/pwm/pwm_th1520.rs index ddd44a5ce497..933c1ec59c2a 100644 --- a/drivers/pwm/pwm_th1520.rs +++ b/drivers/pwm/pwm_th1520.rs @@ -67,16 +67,10 @@ fn ns_to_cycles(ns: u64, rate_hz: u64) -> u64 { ns.saturating_mul(rate_hz) / NSEC_PER_SEC_U64 } =20 -fn cycles_to_ns(cycles: u64, rate_hz: u64) -> u64 { +fn cycles_to_ns(cycles: u32, rate_hz: u64) -> u64 { const NSEC_PER_SEC_U64: u64 =3D time::NSEC_PER_SEC as u64; =20 - // TODO: Replace with a kernel helper like `mul_u64_u64_div_u64_roundu= p` - // once available in Rust. - let numerator =3D cycles - .saturating_mul(NSEC_PER_SEC_U64) - .saturating_add(rate_hz - 1); - - numerator / rate_hz + (u64::from(cycles) * NSEC_PER_SEC_U64).div_ceil(rate_hz) } =20 /// Hardware-specific waveform representation for TH1520. @@ -192,15 +186,15 @@ fn round_waveform_fromhw( return Ok(()); } =20 - wf.period_length_ns =3D cycles_to_ns(u64::from(wfhw.period_cycles)= , rate_hz); + wf.period_length_ns =3D cycles_to_ns(wfhw.period_cycles, rate_hz); =20 - let duty_cycles =3D u64::from(wfhw.duty_cycles); + let duty_cycles =3D wfhw.duty_cycles; =20 if (wfhw.ctrl_val & TH1520_PWM_FPOUT) !=3D 0 { wf.duty_length_ns =3D cycles_to_ns(duty_cycles, rate_hz); wf.duty_offset_ns =3D 0; } else { - let period_cycles =3D u64::from(wfhw.period_cycles); + let period_cycles =3D wfhw.period_cycles; let original_duty_cycles =3D period_cycles.saturating_sub(duty= _cycles); =20 // For an inverted signal, `duty_length_ns` is the high time (= period - low_time). --- base-commit: 3936b25815ee686a273ca7bbdc9ae19af5e608a3 change-id: 20260521-pwm-th1520-fix-8e45558bbd31 Best regards, --=20 Maurice Hieronymus