Re: [PATCH] overlay: ensure that existing phandles are not overwritten

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hello,

On Wed, Apr 26, 2023 at 12:02:31PM +0200, Uwe Kleine-König wrote:
> -static int overlay_adjust_node_phandles(void *fdto, int node,
> -					uint32_t delta)
> +static int overlay_adjust_node_phandles(void *fdto, int nodeo,
> +					uint32_t delta, void *fdtbase, int basenode, uint32_t *phandlemap)
>  {
> -	int child;
> +	int childo;
>  	int ret;
> +	const fdt32_t *phandlebase;
> +	int phandlebaselen;
>  
> -	ret = overlay_phandle_add_offset(fdto, node, "phandle", delta);
> -	if (ret && ret != -FDT_ERR_NOTFOUND)
> -		return ret;
> +	/*
> +	 * If the base fdt has a phandle already reuse the value to not break
> +	 * references that already exist in the base fdt.
> +	 */
> +	if (fdtbase) {
> +		phandlebase = fdt_getprop(fdtbase, basenode, "phandle", &phandlebaselen);
> +		if (!phandlebase && phandlebaselen != -FDT_ERR_NOTFOUND)
> +			return phandlebaselen;
> +		if (!phandlebase) {
> +			phandlebase = fdt_getprop(fdtbase, basenode, "linux,phandle", &phandlebaselen);
> +			if (!phandlebase && phandlebaselen != -FDT_ERR_NOTFOUND)
> +				return phandlebaselen;
> +		}
> +		if (phandlebase && phandlebaselen != sizeof(*phandlebase))
> +			return -FDT_ERR_BADPHANDLE;
> +	}
>  
> -	ret = overlay_phandle_add_offset(fdto, node, "linux,phandle", delta);
> -	if (ret && ret != -FDT_ERR_NOTFOUND)
> -		return ret;
> +	if (fdtbase && phandlebase) {
> +		ret = overlay_phandle_set(fdto, nodeo, "phandle", fdt32_to_cpu(*phandlebase), phandlemap);

Compiling that on Ubuntu stable emits a warning here that phandlebase
might be uninitialized (see
https://github.com/ukleinek/dtc/actions/runs/4831386302/jobs/8608771064).

While looking into that, I think the code is correct, but can be
simplified by using fdt_get_phandle() instead of open coding it. I'll
rework the code and test a bit more. So please don't apply this version
of the patch.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux