From nobody Mon Jun 8 23:59:15 2026 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 E5A9B383333; Mon, 25 May 2026 13:11:06 +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=1779714667; cv=none; b=NAiiEcJVWsqRU0vPa4s2maSMLTdfaKBWMNVd3ETmOI1FEynZ6I6VduoobG1HLWFObBBvU3SbIe0g9WdeaAuWH8z0jPyKMbZvgFnYg2EOMjAidJf9qrIHfz1VumKbRbQ6pTPHDep1ktKDR2gIukqHyrpX8Ipdmv/sfSdsBEhF2bM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779714667; c=relaxed/simple; bh=gJANdD9WR/rwlZqdxsUyvXHtL/APVzUZ/BRP6GSj70E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=jilmI6uj3OsJbT8ILsuORZFtAZNImSyifdpqODy2WeDGQRAD0HcaEMrQcdjKubTAYcbfZgPTtwzGVGLl9MIIQymkkGwqo6Wg+OC8KBvThViRtMDPspPsbLHvmjtHkzjW+9ZwxBMDSqQ4mV5i/gVfsN7GABBDtBD3Y8ncPqlkwWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nPSwMGGI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nPSwMGGI" Received: by smtp.kernel.org (Postfix) with ESMTPS id 79A46C2BCB3; Mon, 25 May 2026 13:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779714666; bh=gJANdD9WR/rwlZqdxsUyvXHtL/APVzUZ/BRP6GSj70E=; h=From:Date:Subject:To:Cc:Reply-To:From; b=nPSwMGGIsREma719TJA2EZFDAyb0rfjfADB8MttgtWnho3snTSKEMuG7Es5ExXe5L F/ENqiqs8QQQAXAuCbgGL2CWjni2uFKqG/d/axxwpBe+yc/v0l7tCQhZjcHxwVM4Ir KEOvXlHgydqL7HbKqPawRnPKRI5K8SkybEwLqZpppoaZ9Hdb48QWWusuozIjxFPTOP vFOcFLITVEgS8Vm0xurjVISgOXkmw/iOjp9qriqRJLS1ChLewpoRnKGcvUoR6WvsuK 4m3g0dK+8yBMtjYou+8e3454m+7sSM5ecpdxPEWOByW5NM6+LGEEEY3/IT8333U+cZ ce+hccCZ/cP2Q== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FF51CD5BC9; Mon, 25 May 2026 13:11:06 +0000 (UTC) From: Maurice Hieronymus via B4 Relay Date: Mon, 25 May 2026 15:11:02 +0200 Subject: [PATCH RESEND] 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: <20260525-pwm-th1520-fix-v1-1-814e537c6812@mailbox.org> 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-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779714665; l=2775; i=mhi@mailbox.org; s=20260525; h=from:subject:message-id; bh=pPwMlhdLEIKx7tKQw28S2ur5hibHwE9OvuL0BMwNJFI=; b=2CY1YOoHuBr6u2vNL2LHaCbZfS8c/Z4MpUQbK76cVxR4pFQ7J6JKYPOmCZp6RzS5uoV/ehCKe ehBfc6H4FxyCb4WyrRuUDfbLeENx3YhhB4ifWpzHxSRGYx63rQBQft2 X-Developer-Key: i=mhi@mailbox.org; a=ed25519; pk=AHlEkGG3hpXZHntlEzF42Ip/LFyXWOgsNUvaHqAnV80= X-Endpoint-Received: by B4 Relay for mhi@mailbox.org/20260525 with auth_id=790 X-Original-From: Maurice Hieronymus Reply-To: mhi@mailbox.org From: Maurice Hieronymus 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 Reviewed-by: Michal Wilczynski --- Note: Resending v1 because my mail server (mailbox.org) was unable to deliver the original submission to @kernerl.org recipients. Going through the b4 web submission endpoint this time. No changes to the patch content. --- 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