public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dominique Martinet <dominique.martinet@atmark-techno.com>
To: Adam Ford <aford173@gmail.com>
Cc: Pei Xiao <xiaopei01@kylinos.cn>,
	geert@linux-m68k.org, aford@beaconembedded.com, arnd@arndb.de,
	frieder.schrempf@kontron.de, kishon@kernel.org,
	l.stach@pengutronix.de, linux-kernel@vger.kernel.org,
	linux-phy@lists.infradead.org, m.felsch@pengutronix.de,
	sandor.yu@nxp.com, u.kleine-koenig@baylibre.com,
	vkoul@kernel.org
Subject: Re: [PATCH] phy: freescale: fsl-samsung-hdmi: fix build error in fsl_samsung_hdmi_phy_configure_pll_lock_det
Date: Thu, 2 Jan 2025 21:15:15 +0900	[thread overview]
Message-ID: <Z3aDU_dhfgEHlL4u@atmark-techno.com> (raw)
In-Reply-To: <CAHCN7x+UzXQz+2zs+qvvWfWCmhsxsZoxP+2WHpfdZGnzwDPNQg@mail.gmail.com>

Adam Ford wrote on Mon, Dec 30, 2024 at 08:11:16PM -0600:
> > index 5eac70a1e858..3e4d1a5160ea 100644
> > --- a/drivers/phy/freescale/phy-fsl-samsung-hdmi.c
> > +++ b/drivers/phy/freescale/phy-fsl-samsung-hdmi.c
> > @@ -341,7 +341,7 @@ fsl_samsung_hdmi_phy_configure_pll_lock_det(struct fsl_samsung_hdmi_phy *phy,
> >                         break;
> >         }
> >
> > -       writeb(FIELD_PREP(REG12_CK_DIV_MASK, div), phy->regs + PHY_REG(12));
> > +       writeb(FIELD_PREP(REG12_CK_DIV_MASK, div == 4 ? div - 1 : div), phy->regs + PHY_REG(12));
> 
> The for-loop above this line states:   for (div = 0; div < 4; div++)
> How could this ever reach 4?  If it did reach 4, the calculation for
> int_pllclk would need to be recalculated since int_pllclk = pclk / (1
> << div);

But... for (div = 0; div < 4; div++) does reach 4, if the break
condition didn't match, which is something the compiler cannot ensure
here.

The old code would just fall out of any of the switch cases and fallback
to div = 1 if pixclk > 297000000, which is likely incorrect, so in that
sense just padding this through `& 3` and pretending it will never
happen is probably acceptable, but this ought to have a better comment
than what Pei just sent.
(this was correct with the old lookup tables, I'm not sure if we can't
compute any higher frequencies now?)

My preference would be to actually check and handle this somehow since I
don't think this part of the code is that performance critical that we
can't afford an extra instruction, e.g. something like that:
if (WARN_ONCE(div == 4, "pixclk %u out of range", pclk))
	(appropriate fallback or return?)

but I haven't spent the time to actually check so will leave that up to
you.

Thank you both,
-- 
Dominique

  parent reply	other threads:[~2025-01-02 12:24 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-26 13:19 [PATCH V2 1/3] phy: freescale: fsl-samsung-hdmi: Expand Integer divider range Adam Ford
2024-10-26 13:19 ` [PATCH V2 2/3] phy: freescale: fsl-samsung-hdmi: Stop searching when exact match is found Adam Ford
2024-10-26 13:19 ` [PATCH V2 3/3] phy: freescale: fsl-samsung-hdmi: Clean up fld_tg_code calculation Adam Ford
2024-12-13 14:13   ` Geert Uytterhoeven
2024-12-13 14:57     ` Adam Ford
2024-12-13 15:16       ` Geert Uytterhoeven
2024-12-30  2:11         ` [PATCH] phy: freescale: fsl-samsung-hdmi: fix build error in fsl_samsung_hdmi_phy_configure_pll_lock_det Pei Xiao
2024-12-31  2:11           ` Adam Ford
2024-12-31  2:19             ` Pei Xiao
2024-12-31 17:02               ` Adam Ford
2025-01-02  2:14                 ` Pei Xiao
2025-01-02  2:32                   ` Pei Xiao
2025-01-02 12:15             ` Dominique Martinet [this message]
2025-01-02 15:04               ` Adam Ford
2025-01-03  1:34                 ` Pei Xiao
2025-01-09  8:45                   ` Pei Xiao
2025-01-09 15:03                     ` Adam Ford
2025-01-10 10:04                       ` Geert Uytterhoeven
2025-01-11  0:07                         ` Adam Ford
2024-11-07 17:33 ` [PATCH V2 1/3] phy: freescale: fsl-samsung-hdmi: Expand Integer divider range Adam Ford
2024-12-04 14:21 ` Adam Ford
2024-12-08 17:03 ` Vinod Koul

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=Z3aDU_dhfgEHlL4u@atmark-techno.com \
    --to=dominique.martinet@atmark-techno.com \
    --cc=aford173@gmail.com \
    --cc=aford@beaconembedded.com \
    --cc=arnd@arndb.de \
    --cc=frieder.schrempf@kontron.de \
    --cc=geert@linux-m68k.org \
    --cc=kishon@kernel.org \
    --cc=l.stach@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=m.felsch@pengutronix.de \
    --cc=sandor.yu@nxp.com \
    --cc=u.kleine-koenig@baylibre.com \
    --cc=vkoul@kernel.org \
    --cc=xiaopei01@kylinos.cn \
    /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