# Re: \[PATCH 10/11\] soc: ti: knav\_qmss\_queue: use of\_property\_read\_bool

- From: Robin Murphy \<hidden\>
- Date: 2016-08-05 12:47:30 
- List: linux-devicetree
- Page: https://ratatoskr.run/linux-devicetree/2016/08/4808766
- Thread: https://ratatoskr.run/kernel-janitors/2016/08/4808654/t.md

```text
Hi Julia,

On 05/08/16 09:56, Julia Lawall wrote:
> Use of_property_read_bool to check for the existence of a property.

This caught my eye since Rob told me off for doing the same recently[1].

> The semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @@
> expression e1,e2;
> statement S2,S1;
> @@
> -       if (of_get_property(e1,e2,NULL))
> +       if (of_property_read_bool(e1,e2))
>         S1 else S2
> // </smpl>
> 
> Signed-off-by: Julia Lawall <redacted>
> 
> ---
>  drivers/soc/ti/knav_qmss_queue.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c
> index b73e353..56b5d7c 100644
> --- a/drivers/soc/ti/knav_qmss_queue.c
> +++ b/drivers/soc/ti/knav_qmss_queue.c
> @@ -1240,7 +1240,7 @@ static int knav_setup_queue_range(struct knav_device *kdev,
>  	if (of_get_property(node, "qalloc-by-id", NULL))

According to the binding, "qalloc-by-id" _is_ a boolean property, so
this one really does deserve to be of_property_read_bool()...

>  		range->flags |= RANGE_RESERVED;
>  
> -	if (of_get_property(node, "accumulator", NULL)) {
> +	if (of_property_read_bool(node, "accumulator")) {

...whereas "accumulator" must have a value, so this isn't technically
appropriate. In general, most of these "if the property exists, read the
property and do stuff" checks are probably a sign of code that could be
simplified by refactoring the "do stuff" step to just specifically
handle the "read the property" step returning -EINVAL when it's not present.

Robin.

[1]:https://www.mail-archive.com/iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org/msg13375.html

>  		ret = knav_init_acc_range(kdev, node, range);
>  		if (ret < 0) {
>  			devm_kfree(dev, range);
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
```
