[PATCH] soc: imx8m: Fix return value check in imx8mq_soc_revision()

Zheng Yongjun posted 1 patch 3 years, 2 months ago
There is a newer version of this series
drivers/soc/imx/soc-imx8m.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] soc: imx8m: Fix return value check in imx8mq_soc_revision()
Posted by Zheng Yongjun 3 years, 2 months ago
In case of error, the function of_clk_get_by_name()
returns ERR_PTR() and never returns NULL. The NULL test in the
return value check should be replaced with IS_ERR().

Fixes: 836fb30949d9 ("soc: imx8m: Enable OCOTP clock before reading the register")
Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
---
 drivers/soc/imx/soc-imx8m.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/imx/soc-imx8m.c b/drivers/soc/imx/soc-imx8m.c
index 28144c699b0c..32ed9dc88e45 100644
--- a/drivers/soc/imx/soc-imx8m.c
+++ b/drivers/soc/imx/soc-imx8m.c
@@ -66,8 +66,8 @@ static u32 __init imx8mq_soc_revision(void)
 	ocotp_base = of_iomap(np, 0);
 	WARN_ON(!ocotp_base);
 	clk = of_clk_get_by_name(np, NULL);
-	if (!clk) {
-		WARN_ON(!clk);
+	if (IS_ERR(clk)) {
+		WARN_ON(IS_ERR(clk));
 		return 0;
 	}

--
2.17.1
Re: [PATCH] soc: imx8m: Fix return value check in imx8mq_soc_revision()
Posted by Ahmad Fatoum 3 years, 2 months ago
Hi Zheng,

On 26.11.22 10:24, Zheng Yongjun wrote:
> In case of error, the function of_clk_get_by_name()
> returns ERR_PTR() and never returns NULL. The NULL test in the
> return value check should be replaced with IS_ERR().
> 
> Fixes: 836fb30949d9 ("soc: imx8m: Enable OCOTP clock before reading the register")
> Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
> ---
>  drivers/soc/imx/soc-imx8m.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/soc/imx/soc-imx8m.c b/drivers/soc/imx/soc-imx8m.c
> index 28144c699b0c..32ed9dc88e45 100644
> --- a/drivers/soc/imx/soc-imx8m.c
> +++ b/drivers/soc/imx/soc-imx8m.c
> @@ -66,8 +66,8 @@ static u32 __init imx8mq_soc_revision(void)
>  	ocotp_base = of_iomap(np, 0);
>  	WARN_ON(!ocotp_base);
>  	clk = of_clk_get_by_name(np, NULL);
> -	if (!clk) {
> -		WARN_ON(!clk);
> +	if (IS_ERR(clk)) {
> +		WARN_ON(IS_ERR(clk));
>  		return 0;

You could also rewrite as

if (WARN_ON(IS_ERR(clk))
	return 0;

To make it more concise. Change looks good though:

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

Cheers,
Ahmad

>  	}
> 
> --
> 2.17.1
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
答复: [PATCH] soc: imx8m: Fix return value check in imx8mq_soc_revision()
Posted by zhengyongjun 3 years, 2 months ago
Thanks for your adivice :)
       
               Zheng

-----邮件原件-----
发件人: Ahmad Fatoum [mailto:a.fatoum@pengutronix.de] 
发送时间: 2022年11月28日 15:56
收件人: zhengyongjun <zhengyongjun3@huawei.com>; shawnguo@kernel.org; s.hauer@pengutronix.de; linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org
抄送: festevam@gmail.com; linux-imx@nxp.com; kernel@pengutronix.de
主题: Re: [PATCH] soc: imx8m: Fix return value check in imx8mq_soc_revision()

Hi Zheng,

On 26.11.22 10:24, Zheng Yongjun wrote:
> In case of error, the function of_clk_get_by_name() returns ERR_PTR() 
> and never returns NULL. The NULL test in the return value check should 
> be replaced with IS_ERR().
> 
> Fixes: 836fb30949d9 ("soc: imx8m: Enable OCOTP clock before reading 
> the register")
> Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
> ---
>  drivers/soc/imx/soc-imx8m.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/soc/imx/soc-imx8m.c b/drivers/soc/imx/soc-imx8m.c 
> index 28144c699b0c..32ed9dc88e45 100644
> --- a/drivers/soc/imx/soc-imx8m.c
> +++ b/drivers/soc/imx/soc-imx8m.c
> @@ -66,8 +66,8 @@ static u32 __init imx8mq_soc_revision(void)
>  	ocotp_base = of_iomap(np, 0);
>  	WARN_ON(!ocotp_base);
>  	clk = of_clk_get_by_name(np, NULL);
> -	if (!clk) {
> -		WARN_ON(!clk);
> +	if (IS_ERR(clk)) {
> +		WARN_ON(IS_ERR(clk));
>  		return 0;

You could also rewrite as

if (WARN_ON(IS_ERR(clk))
	return 0;

To make it more concise. Change looks good though:

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

Cheers,
Ahmad

>  	}
> 
> --
> 2.17.1
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |