[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAHCN7x+_8YSORcvXLgo_i=7WCUUEAdeJWjC5xoUPT-OVCdSftQ@mail.gmail.com>
Date: Fri, 10 Jan 2025 18:07:06 -0600
From: Adam Ford <aford173@...il.com>
To: Geert Uytterhoeven <geert@...ux-m68k.org>
Cc: Pei Xiao <xiaopei01@...inos.cn>,
Dominique Martinet <dominique.martinet@...ark-techno.com>, aford@...conembedded.com,
arnd@...db.de, frieder.schrempf@...tron.de, kishon@...nel.org,
l.stach@...gutronix.de, linux-kernel@...r.kernel.org,
linux-phy@...ts.infradead.org, m.felsch@...gutronix.de, sandor.yu@....com,
u.kleine-koenig@...libre.com, vkoul@...nel.org
Subject: Re: [PATCH] phy: freescale: fsl-samsung-hdmi: fix build error in fsl_samsung_hdmi_phy_configure_pll_lock_det
On Fri, Jan 10, 2025 at 4:04 AM Geert Uytterhoeven <geert@...ux-m68k.org> wrote:
>
> Hi Adam,
>
> On Thu, Jan 9, 2025 at 4:03 PM Adam Ford <aford173@...il.com> wrote:
> > On Thu, Jan 9, 2025 at 2:45 AM Pei Xiao <xiaopei01@...inos.cn> wrote:
> > > 在 2025/1/3 09:34, Pei Xiao 写道:
> > > > 在 2025/1/2 23:04, Adam Ford 写道:
> > > >> On Thu, Jan 2, 2025 at 6:15 AM Dominique Martinet
> > > >> <dominique.martinet@...ark-techno.com> wrote:
> > > >>> 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.
> > > >> Maybe we use the MAX function to set div = max(div,3);
> > > > do you mean:
> > > > writeb(FIELD_PREP(REG12_CK_DIV_MASK, min(div, 3)), phy->regs + PHY_REG(12));
> > >
> > > Does anyone have any suggestions?
> >
> > Sorry for the delayed responses, I was traveling for the last week.
> >
> > What about replacing the for loop with a do-while loop where the
> > criteria is int_pllclk < (50 * MHZ) && div <= 3. Might that work?
>
> Such a loop might never complete, although in practice that does not
> seem to be possible (until someone modifies the tables in the driver
> and adds a too-large cfg->pixclk?).
>
> Probably the safest solution is to change the return type of
> fsl_samsung_hdmi_phy_configure_pll_lock_det() from void to int, and
> let it return an error code:
>
> if (div == 4)
> return -EINVAL;
>
> and propagate that. Its sole caller already returns an error code.
That works for me.
Pei,
Do you want me to submit a patch, or did you want to do it? I don't
know how to replicate the compiler error, so I can't verify if this
would fix it or not.
adam
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
Powered by blists - more mailing lists