mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH next] drm/loongson: Fix error handling in lsdc_pixel_pll_setup()
@ 2023-07-20 12:39 Harshit Mogalapalli
  2023-08-10 13:30 ` suijingfeng
  0 siblings, 1 reply; 2+ messages in thread
From: Harshit Mogalapalli @ 2023-07-20 12:39 UTC (permalink / raw)
  To: Sui Jingfeng, David Airlie, Daniel Vetter, Thomas Zimmermann,
	dri-devel, linux-kernel
  Cc: dan.carpenter, kernel-janitors, error27, harshit.m.mogalapalli

There are two problems in lsdc_pixel_pll_setup()
1. If kzalloc() fails then call iounmap() to release the resources.
2. Both kzalloc and ioremap doesnot return error pointers on failure, so
   using IS_ERR_OR_NULL() checks is a bit confusing and not very right,
   fix this by changing those to NULL checks instead.

Fixes: f39db26c5428 ("drm: Add kms driver for loongson display controller")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
This is found with static analysis with smacth and only compile tested.
---
 drivers/gpu/drm/loongson/lsdc_pixpll.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/loongson/lsdc_pixpll.c b/drivers/gpu/drm/loongson/lsdc_pixpll.c
index 04c15b4697e2..2609a2256da4 100644
--- a/drivers/gpu/drm/loongson/lsdc_pixpll.c
+++ b/drivers/gpu/drm/loongson/lsdc_pixpll.c
@@ -120,12 +120,14 @@ static int lsdc_pixel_pll_setup(struct lsdc_pixpll * const this)
 	struct lsdc_pixpll_parms *pparms;
 
 	this->mmio = ioremap(this->reg_base, this->reg_size);
-	if (IS_ERR_OR_NULL(this->mmio))
+	if (!this->mmio)
 		return -ENOMEM;
 
 	pparms = kzalloc(sizeof(*pparms), GFP_KERNEL);
-	if (IS_ERR_OR_NULL(pparms))
+	if (!pparms) {
+		iounmap(this->mmio);
 		return -ENOMEM;
+	}
 
 	pparms->ref_clock = LSDC_PLL_REF_CLK_KHZ;
 
-- 
2.39.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH next] drm/loongson: Fix error handling in lsdc_pixel_pll_setup()
  2023-07-20 12:39 [PATCH next] drm/loongson: Fix error handling in lsdc_pixel_pll_setup() Harshit Mogalapalli
@ 2023-08-10 13:30 ` suijingfeng
  0 siblings, 0 replies; 2+ messages in thread
From: suijingfeng @ 2023-08-10 13:30 UTC (permalink / raw)
  To: Harshit Mogalapalli, David Airlie, Daniel Vetter,
	Thomas Zimmermann, dri-devel, linux-kernel
  Cc: dan.carpenter, kernel-janitors, error27

Hi,


On 2023/7/20 20:39, Harshit Mogalapalli wrote:
> There are two problems in lsdc_pixel_pll_setup()
> 1. If kzalloc() fails then call iounmap() to release the resources.
> 2. Both kzalloc and ioremap doesnot return error pointers on failure, so
>     using IS_ERR_OR_NULL() checks is a bit confusing and not very right,
>     fix this by changing those to NULL checks instead.
>
> Fixes: f39db26c5428 ("drm: Add kms driver for loongson display controller")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>


Reviewed-by: Sui Jingfeng <suijingfeng@loongson.cn>


> ---
> This is found with static analysis with smacth and only compile tested.
> ---
>   drivers/gpu/drm/loongson/lsdc_pixpll.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/loongson/lsdc_pixpll.c b/drivers/gpu/drm/loongson/lsdc_pixpll.c
> index 04c15b4697e2..2609a2256da4 100644
> --- a/drivers/gpu/drm/loongson/lsdc_pixpll.c
> +++ b/drivers/gpu/drm/loongson/lsdc_pixpll.c
> @@ -120,12 +120,14 @@ static int lsdc_pixel_pll_setup(struct lsdc_pixpll * const this)
>   	struct lsdc_pixpll_parms *pparms;
>   
>   	this->mmio = ioremap(this->reg_base, this->reg_size);
> -	if (IS_ERR_OR_NULL(this->mmio))
> +	if (!this->mmio)
>   		return -ENOMEM;
>   
>   	pparms = kzalloc(sizeof(*pparms), GFP_KERNEL);
> -	if (IS_ERR_OR_NULL(pparms))
> +	if (!pparms) {
> +		iounmap(this->mmio);
>   		return -ENOMEM;
> +	}
>   
>   	pparms->ref_clock = LSDC_PLL_REF_CLK_KHZ;
>   


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-10 13:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-20 12:39 [PATCH next] drm/loongson: Fix error handling in lsdc_pixel_pll_setup() Harshit Mogalapalli
2023-08-10 13:30 ` suijingfeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®