From: "Uwe Kleine-König" <ukleinek@kernel.org>
To: george.moussalem@outlook.com
Cc: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Baruch Siach <baruch@tkos.co.il>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
linux-arm-msm@vger.kernel.org, linux-pwm@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Devi Priya <quic_devipriy@quicinc.com>,
Baruch Siach <baruch.siach@siklu.com>
Subject: Re: [PATCH v20 2/6] pwm: driver for qualcomm ipq6018 pwm block
Date: Thu, 2 Apr 2026 17:35:31 +0200 [thread overview]
Message-ID: <ac6MP-O2MNDkleZB@monoceros> (raw)
In-Reply-To: <20260204-ipq-pwm-v20-2-91733011a3d1@outlook.com>
[-- Attachment #1: Type: text/plain, Size: 2582 bytes --]
Hello,
I applied the patch and reviewed it in my editor. Here is the resulting
diff:
diff --git a/drivers/pwm/pwm-ipq.c b/drivers/pwm/pwm-ipq.c
index b944ecb456d5..4818d0170d53 100644
--- a/drivers/pwm/pwm-ipq.c
+++ b/drivers/pwm/pwm-ipq.c
@@ -97,9 +97,10 @@ static int ipq_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
if (state->polarity != PWM_POLARITY_NORMAL)
return -EINVAL;
- if (!ipq_chip->clk_rate)
- return -EINVAL;
-
+ /*
+ * XXX Why? A comment please. (Is this already covered by the checks
+ * below?)
+ */
if (state->period < DIV64_U64_ROUND_UP(NSEC_PER_SEC,
ipq_chip->clk_rate))
return -ERANGE;
@@ -107,18 +108,29 @@ static int ipq_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
period_ns = min(state->period, IPQ_PWM_MAX_PERIOD_NS);
duty_ns = min(state->duty_cycle, period_ns);
+ /*
+ * Pick the maximal value for PWM_DIV that still allows a
+ * 100% relative duty cycle. This allows a fine grained
+ * selection of duty cycles.
+ */
pwm_div = IPQ_PWM_MAX_DIV - 1;
+
+ /*
+ * XXX mul_u64_u64_div_u64 returns an u64, this might overflow the
+ * unsigned int pre_div.
+ */
pre_div = mul_u64_u64_div_u64(period_ns, ipq_chip->clk_rate,
(u64)NSEC_PER_SEC * (pwm_div + 1));
- pre_div = (pre_div > 0) ? pre_div - 1 : 0;
+
+ if (!pre_div)
+ return -ERANGE;
+
+ pre_div -= 1;
if (pre_div > IPQ_PWM_MAX_DIV)
pre_div = IPQ_PWM_MAX_DIV;
- /*
- * high duration = pwm duty * (pwm div + 1)
- * pwm duty = duty_ns / period_ns
- */
+ /* pwm duty = HI_DUR * (PRE_DIV + 1) / clk_rate */
hi_dur = mul_u64_u64_div_u64(duty_ns, ipq_chip->clk_rate,
(u64)(pre_div + 1) * NSEC_PER_SEC);
@@ -161,6 +173,10 @@ static int ipq_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
pre_div = FIELD_GET(IPQ_PWM_REG1_PRE_DIV, reg1);
effective_div = (u64)(pre_div + 1) * (pwm_div + 1);
+
+ /*
+ * effective_div <= 0x100000000, so the multiplication doesn't overflow.
+ */
state->period = DIV64_U64_ROUND_UP(effective_div * NSEC_PER_SEC,
ipq_chip->clk_rate);
@@ -210,6 +226,8 @@ static int ipq_pwm_probe(struct platform_device *pdev)
return dev_err_probe(dev, ret, "Failed to lock clock rate\n");
pwm->clk_rate = clk_get_rate(clk);
+ if (!pwm->clk_rate)
+ return dev_err_probe(dev, -EINVAL, "Failed due to clock rate being zero\n");
chip->ops = &ipq_pwm_ops;
Comments with XXX need more code adaptions (or a comment why my concern
isn't justified).
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2026-04-02 15:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-04 11:25 [PATCH v20 0/6] Add PWM support for IPQ chipsets George Moussalem via B4 Relay
2026-02-04 11:25 ` [PATCH v20 1/6] dt-bindings: pwm: add IPQ6018 binding George Moussalem via B4 Relay
2026-02-04 11:25 ` [PATCH v20 2/6] pwm: driver for qualcomm ipq6018 pwm block George Moussalem via B4 Relay
2026-04-02 15:35 ` Uwe Kleine-König [this message]
2026-04-03 10:40 ` George Moussalem
2026-04-04 21:09 ` Uwe Kleine-König
2026-04-07 5:58 ` George Moussalem
2026-02-04 11:25 ` [PATCH v20 3/6] arm64: dts: qcom: ipq6018: add pwm node George Moussalem via B4 Relay
2026-02-04 12:24 ` Konrad Dybcio
2026-02-04 11:25 ` [PATCH v20 4/6] arm64: dts: qcom: ipq5018: " George Moussalem via B4 Relay
2026-02-04 12:25 ` Konrad Dybcio
2026-02-04 11:25 ` [PATCH v20 5/6] arm64: dts: qcom: ipq5332: " George Moussalem via B4 Relay
2026-02-04 12:25 ` Konrad Dybcio
2026-02-04 11:25 ` [PATCH v20 6/6] arm64: dts: qcom: ipq9574: " George Moussalem via B4 Relay
2026-02-04 12:26 ` Konrad Dybcio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ac6MP-O2MNDkleZB@monoceros \
--to=ukleinek@kernel.org \
--cc=andersson@kernel.org \
--cc=baruch.siach@siklu.com \
--cc=baruch@tkos.co.il \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=george.moussalem@outlook.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=quic_devipriy@quicinc.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox