[RFC V3 3/3] phy: freescale: fsl-samsung-hdmi: Support dynamic integer
Dominique Martinet
dominique.martinet at atmark-techno.com
Mon Sep 2 17:47:06 PDT 2024
Adam Ford wrote on Mon, Sep 02, 2024 at 04:20:11PM -0500:
> > - const struct phy_config *cur_cfg;
> > + struct phy_config cur_cfg;
>
> Wouldn't converting this from a pointer require me to do a memcpy
> later? It seems like that's more work than just pointing it to an
> address.
>
> > - phy->cur_cfg = &phy_pll_cfg[i];
> > + phy->cur_cfg = phy_pll_cfg[i];
>
> I think this is would have to be a memcpy instead of just an equal
> statement since phy->cur_cfg would no longer be a pointer.
C allows copying structs like this, it's fine to write it as just an
equal.
It's not 100% equivalent, iiuc simple assignment is undefined behaviour
if the elements aren't aligned but memcpy will work even in that case,
but for us this is not a proble mand the generated code should be
identical... Also note I'm only suggesting that because the struct is
tiny (1*u32+7*u8 is less than two u64), but this code isn't meant to run
very often anyway so we should prioritize readability -- if you think
it's harder to understand than an extra pointer somewhere I have no
strong opinion; as said in the previous mail if parallel uses are
possible it'd be better kept on the stack anyway...
--
Dominique
More information about the linux-phy
mailing list