Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] phy: amlogic: broken rate and submode check in
  meson_hdmi_phy_validate()
--

commit 0bf49ea77c864cdcf7af96e59e1ffba5194d9636
Author: Ronald Claveau <[email protected]>

phy: amlogic: Add Meson HDMI TX PHY driver

This commit adds a generic PHY driver for the HDMI TX PHY on Amlogic GXBB,
GXL, GXM, and G12A SoCs, along with a legacy helper for device trees
lacking a "phys" property.

> diff --git a/drivers/phy/amlogic/phy-meson-hdmi-tx.c 
> b/drivers/phy/amlogic/phy-meson-hdmi-tx.c
> new file mode 100644
> index 0000000000000..69833a080dc35
> --- /dev/null
> +++ b/drivers/phy/amlogic/phy-meson-hdmi-tx.c
[ ... ]
> +/* GXBB */
> +static const struct meson_hdmi_phy_rate gxbb_rates[] = {
> +     /* 5.94Gbps, 3.7125Gbps */
> +     { 371250000, 0x33353245, 0x2100115b },
> +     /* 2.97Gbps */
> +     { 297000000, 0x33634283, 0xb000115b },
> +     /* 1.485Gbps, and below */
> +     { 0,         0x33632122, 0x2000115b },
> +};
[ ... ]
> +static const struct meson_hdmi_phy_rate *
> +meson_hdmi_phy_find_rate(const struct meson_hdmi_phy_data *data, u64 rate)
> +{
> +     unsigned int i;
> +
> +     for (i = 0; i < data->num_rates; i++)
> +             if (rate >= data->rates[i].min_rate)
> +                     return &data->rates[i];
> +
> +     return NULL;
> +}
[ ... ]
> +static int meson_hdmi_phy_validate(struct phy *phy, enum phy_mode mode,
> +                                int submode, union phy_configure_opts *opts)
> +{
> +     struct meson_hdmi_phy *priv = phy_get_drvdata(phy);
> +
> +     if (mode != PHY_MODE_HDMI)
> +             return -EINVAL;
> +
> +     if (opts->hdmi.bpc != 8)
> +             return -EINVAL;
> +
> +     if (!meson_hdmi_phy_find_rate(priv->data, opts->hdmi.tmds_char_rate))
> +             return -EINVAL;
> +
> +     return 0;
> +}

[Severity: Medium]
Can meson_hdmi_phy_find_rate() ever return NULL here?

Every per-SoC rate table ends with an entry where min_rate is 0, and rate
is an unsigned u64, so rate >= data->rates[i].min_rate is always true on
the final entry.  That makes the NULL return and the callers' NULL checks
in meson_hdmi_phy_validate() and meson_hdmi_phy_configure() dead code, and
meson_hdmi_phy_validate() accepts any tmds_char_rate value (including 0 Hz
or rates above the 594 MHz hardware limit).

In addition, meson_hdmi_phy_validate() does not check that submode is
PHY_HDMI_MODE_TMDS before reading opts->hdmi.tmds_char_rate, which shares
an anonymous union with opts->hdmi.frl when submode is PHY_HDMI_MODE_FRL.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=4

Reply via email to