From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Reding Subject: Re: [PATCH] drm/bridge: analogix-anx78xx: Fix drm_dp_link helper removal Date: Mon, 2 Dec 2019 15:53:05 +0100 Message-ID: <20191202145305.GA56608@ulmo> References: <20191130145155.86B0F68BE1@verein.lst.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0599943519==" Return-path: Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by gabe.freedesktop.org (Postfix) with ESMTPS id 61EE86E0AB for ; Mon, 2 Dec 2019 14:53:10 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id u8so42494wmu.0 for ; Mon, 02 Dec 2019 06:53:10 -0800 (PST) In-Reply-To: <20191130145155.86B0F68BE1@verein.lst.de> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: Torsten Duwe Cc: dri-devel@lists.freedesktop.org, Maxime Ripard List-Id: dri-devel@lists.freedesktop.org --===============0599943519== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ZGiS0Q5IWpPtfppv" Content-Disposition: inline --ZGiS0Q5IWpPtfppv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Nov 30, 2019 at 03:51:55PM +0100, Torsten Duwe wrote: > drm_dp_link_rate_to_bw_code and ...bw_code_to_link_rate simply divide by > and multiply with 27000, respectively. Avoid an overflow in the u8 dpcd[0] > and the multiply+divide alltogether. This was supposed to be a 1:1 conversion of what the helpers did, but then I tried to be clever and reuse variables rather than add an intermediate one and failed to realize that dpcd[0] was u8 and would therefore overflow with the multiplication. Personally I think it's slightly nicer to go through the multiply/divide for consistency with how these helpers are used. MAX_LINK_RATE is a bit of an exception in that the field occupies the whole register, but most other registers need to have the fields extracted properly. In this case it doesn't really matter, so the below is probably good enough. Good catch! Reviewed-by: Thierry Reding > fixes: ff1e8fb68ea06027 ("analogix-anx78xx: Avoid drm_dp_link helpers") > Signed-off-by: Torsten Duwe > --- > Has anybody actually tested ff1e8fb68ea06027 ? I copied that code in good > faith for the anx6345 and changed a few other things simultaneously, and > spent some time wondering why the panel stayed dark. >=20 > --- > diff --git a/drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c b/drivers= /gpu/drm/bridge/analogix/analogix-anx78xx.c > index 41867be03751..864423f59d66 100644 > --- a/drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c > +++ b/drivers/gpu/drm/bridge/analogix/analogix-anx78xx.c > @@ -722,10 +722,9 @@ static int anx78xx_dp_link_training(struct anx78xx *= anx78xx) > if (err) > return err; > =20 > - dpcd[0] =3D drm_dp_max_link_rate(anx78xx->dpcd); > - dpcd[0] =3D drm_dp_link_rate_to_bw_code(dpcd[0]); > err =3D regmap_write(anx78xx->map[I2C_IDX_TX_P0], > - SP_DP_MAIN_LINK_BW_SET_REG, dpcd[0]); > + SP_DP_MAIN_LINK_BW_SET_REG, > + anx78xx->dpcd[DP_MAX_LINK_RATE]); > if (err) > return err; > =20 --ZGiS0Q5IWpPtfppv Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEiOrDCAFJzPfAjcif3SOs138+s6EFAl3lJU8ACgkQ3SOs138+ s6ESyxAAsH3lHwAcvFDOveRKXMNwNMz1zUqjIvSUJBPaF6mdj1WfLsQt9s91DMGz WTPVTEDM+I0whk3svW4kqtxrbtoge6A35j89dCk8EuqkhYSxNym6nUbLlBmFeTR/ Z1voKA/16p650+ONpEhdWXGToW1SUy7KsIW7zuv0kTe2+CyY25F8oFL11n3/12sM SpIqBRHZBr7EK15hI1HywUkgrnCUjH0Br3vW5taqOZ6zB3WXei7HcL+9CRSdc3zJ ncQVjvx87Outr0KMKpEkFwiVk75G0BtOoBsiXtp1Je+k+UKwZAIRD/B4NarLV6nZ YfDWCdcOSlbXX+cioSozXgZtb6VtbCIMGxrqxQ13/k0QNTvYtjNCxhanG+BNJaoL C2AgI/Qb84tk0XO8M/wnajfMvg4ZuKxdeX6V3T+HQxgQk0tr3OXOZ8osN/IpWu9S uNVxIBlaEYU6h2/Y3QN+ggeyp9k3mgDBPWxEtCc+Ka/7kJaPo4yUL9lPNGZO8NRx 3ZzMDVk77kHBAQe2C8vkaF3iQ0yYUK6oaTPsoSU33i0cX0fXxqsALVcOqv3xZ6wb FBHFdCrniSwprTx81e5Iy64G7p0LOhIuOT8FVDodAZOrFNfPIhqwH+l8XpgpxKUd 05pAyNGeKEvQd0G59T10lGaDUlllvOYDk4oo1ke59w+GQUwr/zw= =+amW -----END PGP SIGNATURE----- --ZGiS0Q5IWpPtfppv-- --===============0599943519== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZHJpLWRldmVs IG1haWxpbmcgbGlzdApkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHBzOi8vbGlz dHMuZnJlZWRlc2t0b3Aub3JnL21haWxtYW4vbGlzdGluZm8vZHJpLWRldmVs --===============0599943519==--