Re: [PATCH v2 5/5] checks: Add a sanity check for #.*-cells property value

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



On Mon, Oct 11, 2021 at 02:12:45PM -0500, Rob Herring wrote:
> While in theory any value of number of cells is allowed for a #.*-cells
> property, for all practical purposes the number of cells is never more than
> a few cells. Add a check that the value is less than 255. This will catch
> cases like this which will currently pass:
> 
>   #foo-cells = "bar";
> 
> Signed-off-by: Rob Herring <robh@xxxxxxxxxx>

Hmm.  So the original idea was that this helper could be used for any
1-cell property, not just for #foo-cells.  In practice we're only
using it for #foo-cells so far.

The change would be ok if we updated the names to make it clearer that
this is specifically for #foo-cells properties, not anything else.

> ---
>  checks.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/checks.c b/checks.c
> index 903083bfc423..467442250eda 100644
> --- a/checks.c
> +++ b/checks.c
> @@ -260,8 +260,14 @@ static void check_is_cell(struct check *c, struct dt_info *dti,
>  	if (!prop)
>  		return; /* Not present, assumed ok */
>  
> -	if (prop->val.len != sizeof(cell_t))
> +	if (prop->val.len != sizeof(cell_t)) {
>  		FAIL_PROP(c, dti, node, prop, "property is not a single cell");
> +		return;
> +	}
> +
> +	/* Sanity test for reasonable number of cells */
> +	if (propval_cell(prop) > 255)
> +		FAIL_PROP(c, dti, node, prop, "cell size out of range (>255)");
>  }
>  #define WARNING_IF_NOT_CELL(nm, propname) \
>  	WARNING(nm, check_is_cell, (propname))

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

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