Re: [linux-safety] [PATCH] misc: hisi_hikey_usb: use PTR_ERR_OR_ZERO

"Lukas Bulwahn" <[email protected]> Tue, 27 Oct 2020 06:36:35 +0100 (CET)
Newsgroups tech.elisa.lists.linux-safety
Message-ID <alpine.DEB.2.21.2010270625520.7937@felia>

On Mon, 26 Oct 2020, Sudip Mukherjee wrote:

> Coccinelle suggested using PTR_ERR_OR_ZERO() and looking at the code,
> we can use PTR_ERR_OR_ZERO() instead of checking IS_ERR() and then
> doing 'return 0'.
> 
> Signed-off-by: Sudip Mukherjee <[email protected]>
> ---
>  drivers/misc/hisi_hikey_usb.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/misc/hisi_hikey_usb.c b/drivers/misc/hisi_hikey_usb.c
> index cc93569e601c..989d7d129469 100644
> --- a/drivers/misc/hisi_hikey_usb.c
> +++ b/drivers/misc/hisi_hikey_usb.c
> @@ -168,10 +168,7 @@ static int hisi_hikey_usb_parse_kirin970(struct platform_device *pdev,
>  
>  	hisi_hikey_usb->reset = devm_gpiod_get(&pdev->dev, "hub_reset_en_gpio",
>  					       GPIOD_OUT_HIGH);
> -	if (IS_ERR(hisi_hikey_usb->reset))
> -		return PTR_ERR(hisi_hikey_usb->reset);
> -
> -	return 0;
> +	return PTR_ERR_OR_ZERO(hisi_hikey_usb->reset);
>  }
>

(Just among us, not with the kernel maintainers...)

I think such patches should be also CCed to kernel-janitors.

For the next patch: could you include the specific coccinelle rule upon 
which you reacted?

I think in the very long-term future, it would be nice if we can somehow 
link a finding from a specific tool (with some kind of URI) in the commit 
message or so.

E.g., https://findings.kernel.org/coccinelle/somehash/ and then it shows 
the specific finding you looked at in a specific version and links to
the reported findings in other runs and versions.

(more realistically, it would probably end up in kcidb or so...)

That would be a nice tool to allow good traceability of the work at low 
additional effort.

Well just a random thought... What do you think?

Lukas

>  static int hisi_hikey_usb_probe(struct platform_device *pdev)
> -- 
> 2.11.0
> 
> 
> 
> 
> 
> 
>