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=1796054618; b=oHFeXbBg+2DJ/kkvN8jH6rYwIxXs3+Dc/77rBlk26j/AoK+Pjqbg4zsj+6hGCspE2SPg Oya5/S5QTkc2RVDxrcRrfmN5QFkbLpqv4gdpldupKF5DyEgESdiC8TnV0F3RPI+Z74xWa ItKKx+syUKlIxqI9n7gr0s7BihGTKug6U0BqYztojIUdhbkHDizvKNKRyVgB9L0DCWuIA 91BrkzsEjVGWduIXg1z0Q8CbfTSQy4FefxHVBMRAqnPr1YvqYg+Pr7MK6R0XDn5UbvrAi 0OoM6Q3VC9Mt+yExCvX9fXuWSMZCw6qR0EXM5Z+jsOJ9LA1Xuq8Kx0CfmJhTrfvD9Ow== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796054618; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=LrWRZklbPuE4+zNz4AhYPe/RAk20HoJ6PTAWdSV7huE=; b=aEk4Jbw+YTiDx7WyJTbHmw4G+YoA0sGn773I71foS6mjmYEjvlYRJukhnrfJaNknn+s5 uEs9VOEnUkTgCYQJr1rrEg2Cr8WuhPYt+hC/3Omx58MVqegLQ3DTncWz8CZAipmTDYebH k4TVuKIc8yo8ldiF9t8MKLGACbCXjvVpcm3lKvFIF6BV5990R87guLQzkivjHT5yKmiv9 6Tdkm7juVcev8P7u7ZxrWm2dmuez6swaHQr3wsoLzfUmYRH6Uu0D6xbZ7rP/Nvq57m3Nl q3/A6bMTVtUTAe0TirslIlivFylkmhHzIsSpE/UcsWJWYRve+GiovOJqMlOOJVwL1jQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gIpYX4IM; 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 UTF8SMTPS id 3A991606A325; Mon, 30 Nov 2026 16:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gIpYX4IM Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 822E21F008A0; Mon, 30 Nov 2026 16:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796054618; bh=LrWRZklbPuE4+zNz4AhYPe/RAk20HoJ6PTAWdSV7huE=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=gIpYX4IMIJO2L3YaV398UAaA2hTDABM4OLocvVtLIN7TmRbaxrMyNXciZj1prOjgb tj2HTgtj9qmxgtldafffRgGADyPTHpG+dOu1aic3Hj2k4E1rOlrLv34eNi0w5qFKSM EQ6nRdTLY5MXLC4TaUYugq1B1VZ4zNdoqUovr44D1xXypDI+QolTSiCrfI7uMfjjSD +GNcTMchP6+bndWqA+t1xq5lW2BuZA6bkMi86hAYg1mjs34ILcJsko2cQ/05fMqjyP RHIer2tHAwXKtxFxrOiOGsl9yDp1ZyYN7DG3TbAHDdgWT2A3bFIZGa8UlYVRCJ1IJz CIf60bRvo5Ywg== Date: Mon, 30 Nov 2026 17:03:35 +0100 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: keguang.zhang@gmail.com Cc: Binbin Zhou , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 3/3] pwm: loongson: Use field helpers for period validation Message-ID: References: <20260920-pwm-loongson-fix-v4-0-41b36b3c6497@gmail.com> <20260920-pwm-loongson-fix-v4-3-41b36b3c6497@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="4vbqcpxfbunbemtj" Content-Disposition: inline In-Reply-To: <20260920-pwm-loongson-fix-v4-3-41b36b3c6497@gmail.com> --4vbqcpxfbunbemtj Content-Type: text/plain; protected-headers=v1; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH v4 3/3] pwm: loongson: Use field helpers for period validation MIME-Version: 1.0 On Sun, Sep 20, 2026 at 08:02:08PM +0800, Keguang Zhang via B4 Relay wrote: > From: Keguang Zhang >=20 > Use FIELD_FIT() to validate the calculated period value and FIELD_MAX() > to get the maximum value allowed by the 32-bit period field. >=20 > Signed-off-by: Keguang Zhang > --- > drivers/pwm/pwm-loongson.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/pwm/pwm-loongson.c b/drivers/pwm/pwm-loongson.c > index 977d867bdb8a..178a7a69a11c 100644 > --- a/drivers/pwm/pwm-loongson.c > +++ b/drivers/pwm/pwm-loongson.c > @@ -22,6 +22,7 @@ > */ > =20 > #include > +#include > #include > #include > #include > @@ -37,6 +38,8 @@ > #define LOONGSON_PWM_REG_PERIOD 0x8 /* Pulse Period Buffer Register */ > #define LOONGSON_PWM_REG_CTRL 0xc /* Control Register */ > =20 > +#define LOONGSON_PWM_PERIOD_MASK GENMASK(31, 0) > + > /* Control register bits */ > #define LOONGSON_PWM_CTRL_REG_EN BIT(0) /* Counter Enable Bit */ > #define LOONGSON_PWM_CTRL_REG_OE BIT(3) /* Pulse Output Enable Control = Bit, Valid Low */ > @@ -133,8 +136,8 @@ static int pwm_loongson_config(struct pwm_chip *chip,= struct pwm_device *pwm, > =20 > /* period =3D period_ns * ddata->clk_rate / NSEC_PER_SEC */ > period =3D mul_u64_u64_div_u64(period_ns, ddata->clk_rate, NSEC_PER_SEC= ); > - if (period > U32_MAX) > - period =3D U32_MAX; > + if (!FIELD_FIT(LOONGSON_PWM_PERIOD_MASK, period)) > + period =3D FIELD_MAX(LOONGSON_PWM_PERIOD_MASK); I'm not sure I consider that an improvement. If only a part of LOONGSON_PWM_REG_PERIOD was available for the period, I'd agree (and request to rename LOONGSON_PWM_PERIOD_MASK to LOONGSON_PWM_REG_PERIOD_PERIOD or similar). While studying the reference manual I also found "Before writing a new number to the pulse width register, you should clear the EN bit in the control register and then set the EN bit to 1 after writing the new number." which the driver doesn't honor. Also I wonder if the RST bit should be used when modifying the period (or how the hardware behaves if the internal counter is already higher than the newly configured period). Best regards Uwe --4vbqcpxfbunbemtj Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEP4GsaTp6HlmJrf7Tj4D7WH0S/k4FAmsNnlUACgkQj4D7WH0S /k6MjggAmMHGbGmW+Wq9tA74d/X53ON4F2QGfovCiRW9xKYT5dss8SxRpX1PuLSe hePKjRHki5PQSB3IQs2RYUNncpv9ASWjfVAwj9fmy+0rSIX4tun86+Sa869GI8mJ gQykgTNXy0iKEM7sO3XttqKLqGRAyWilsCeBcx5vADNsDuDn+J58wLgrWHxphPhM TrbHQ9mpmJDlBBF9nvMJQMH7XDgMfxPpV3O0gglF4TElS7m/ITjxk61C5iC2PHLW dafWd7q77p+WGEa8WNVCoD22gIZI19i0zOIl8UxFTkdT8v0/tVjCQGhtV6bQEsnv 7yWJNGfPxZl8Zf6mLqh918azPsrU0Q== =8mV/ -----END PGP SIGNATURE----- --4vbqcpxfbunbemtj--