[PATCH 1/3] phy: ti-pipe3: Use device API for DT parsing
Stefan Roese
stefan.roese at mailbox.org
Wed May 27 14:16:42 CEST 2026
On 5/26/26 08:39, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan at nxp.com>
>
> Replace legacy FDT parsing in get_reg() with the device API
> dev_read_phandle_with_args() which removes direct access to gd->fdt_blob
> and aligns the driver with modern U-Boot DT handling.
>
> The offset is retrieved from the phandle argument instead of manually
> parsing the property cells. Add validation for the argument
> count to avoid out-of-bounds access on malformed DTs.
>
> Also switch from devfdt_get_addr_size_index() to dev_read_addr_size_index()
> for consistency with the DM API.
>
> No functional changes.
>
> Signed-off-by: Peng Fan <peng.fan at nxp.com>
Reviewed-by: Stefan Roese <stefan.roese at mailbox.org>
Thanks,
Stefan
> ---
> drivers/phy/ti-pipe3-phy.c | 23 ++++++++++++++---------
> 1 file changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/phy/ti-pipe3-phy.c b/drivers/phy/ti-pipe3-phy.c
> index 62f6cc2bfbf..080016ba417 100644
> --- a/drivers/phy/ti-pipe3-phy.c
> +++ b/drivers/phy/ti-pipe3-phy.c
> @@ -6,6 +6,7 @@
>
> #include <dm.h>
> #include <dm/device.h>
> +#include <dm/device_compat.h>
> #include <generic-phy.h>
> #include <asm/global_data.h>
> #include <asm/io.h>
> @@ -428,10 +429,10 @@ static int pipe3_exit(struct phy *phy)
>
> static void *get_reg(struct udevice *dev, const char *name)
> {
> + struct ofnode_phandle_args phandle;
> struct udevice *syscon;
> struct regmap *regmap;
> - const fdt32_t *cell;
> - int len, err;
> + int err;
> void *base;
>
> err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
> @@ -449,10 +450,14 @@ static void *get_reg(struct udevice *dev, const char *name)
> return NULL;
> }
>
> - cell = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), name,
> - &len);
> - if (len < 2*sizeof(fdt32_t)) {
> - pr_err("offset not available for %s\n", name);
> + err = dev_read_phandle_with_args(dev, name, NULL, 0, 0, &phandle);
> + if (err) {
> + dev_err(dev, "parse %s failed: %d\n", name, err);
> + return NULL;
> + }
> +
> + if (phandle.args_count < 1) {
> + dev_err(dev, "%s: missing args\n", name);
> return NULL;
> }
>
> @@ -460,7 +465,7 @@ static void *get_reg(struct udevice *dev, const char *name)
> if (!base)
> return NULL;
>
> - return fdtdec_get_number(cell + 1, 1) + base;
> + return base + phandle.args[0];
> }
>
> static int pipe3_phy_probe(struct udevice *dev)
> @@ -471,7 +476,7 @@ static int pipe3_phy_probe(struct udevice *dev)
> struct pipe3_data *data;
>
> /* PHY_RX */
> - addr = devfdt_get_addr_size_index(dev, 0, &sz);
> + addr = dev_read_addr_size_index(dev, 0, &sz);
> if (addr == FDT_ADDR_T_NONE) {
> pr_err("missing phy_rx address\n");
> return -EINVAL;
> @@ -484,7 +489,7 @@ static int pipe3_phy_probe(struct udevice *dev)
> }
>
> /* PLLCTRL */
> - addr = devfdt_get_addr_size_index(dev, 2, &sz);
> + addr = dev_read_addr_size_index(dev, 2, &sz);
> if (addr == FDT_ADDR_T_NONE) {
> pr_err("missing pll ctrl address\n");
> return -EINVAL;
>
More information about the U-Boot
mailing list