kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gma500: clean up error handling in init
@ 2020-12-03  8:40 Dan Carpenter
  2020-12-03  9:45 ` Patrik Jakobsson
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2020-12-03  8:40 UTC (permalink / raw)
  To: Patrik Jakobsson
  Cc: David Airlie, kernel-janitors, dri-devel, Dave Airlie, Alan Cox

The main problem with this error handling was that it didn't clean up if
i2c_add_numbered_adapter() failed.  This code is pretty old, and doesn't
match with today's checkpatch.pl standards so I took the opportunity to
tidy it up a bit.  I changed the NULL comparison, and removed the
WARNING message if kzalloc() fails and updated the label names.

Fixes: 1b082ccf5901 ("gma500: Add Oaktrail support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c b/drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c
index e28107061148..fc9a34ed58bd 100644
--- a/drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c
+++ b/drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c
@@ -279,11 +279,8 @@ int oaktrail_hdmi_i2c_init(struct pci_dev *dev)
 	hdmi_dev = pci_get_drvdata(dev);
 
 	i2c_dev = kzalloc(sizeof(struct hdmi_i2c_dev), GFP_KERNEL);
-	if (i2c_dev = NULL) {
-		DRM_ERROR("Can't allocate interface\n");
-		ret = -ENOMEM;
-		goto exit;
-	}
+	if (!i2c_dev)
+		return -ENOMEM;
 
 	i2c_dev->adap = &oaktrail_hdmi_i2c_adapter;
 	i2c_dev->status = I2C_STAT_INIT;
@@ -300,16 +297,23 @@ int oaktrail_hdmi_i2c_init(struct pci_dev *dev)
 			  oaktrail_hdmi_i2c_adapter.name, hdmi_dev);
 	if (ret) {
 		DRM_ERROR("Failed to request IRQ for I2C controller\n");
-		goto err;
+		goto free_dev;
 	}
 
 	/* Adapter registration */
 	ret = i2c_add_numbered_adapter(&oaktrail_hdmi_i2c_adapter);
-	return ret;
+	if (ret) {
+		DRM_ERROR("Failed to add I2C adapter\n");
+		goto free_irq;
+	}
 
-err:
+	return 0;
+
+free_irq:
+	free_irq(dev->irq, hdmi_dev);
+free_dev:
 	kfree(i2c_dev);
-exit:
+
 	return ret;
 }
 
-- 
2.29.2

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

* Re: [PATCH] gma500: clean up error handling in init
  2020-12-03  8:40 [PATCH] gma500: clean up error handling in init Dan Carpenter
@ 2020-12-03  9:45 ` Patrik Jakobsson
  0 siblings, 0 replies; 2+ messages in thread
From: Patrik Jakobsson @ 2020-12-03  9:45 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: David Airlie, kernel-janitors, dri-devel, Dave Airlie, Alan Cox

On Thu, Dec 3, 2020 at 9:41 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> The main problem with this error handling was that it didn't clean up if
> i2c_add_numbered_adapter() failed.  This code is pretty old, and doesn't
> match with today's checkpatch.pl standards so I took the opportunity to
> tidy it up a bit.  I changed the NULL comparison, and removed the
> WARNING message if kzalloc() fails and updated the label names.

Thanks! Looks good.

I'll apply this to drm-misc-next

-Patrik

>
> Fixes: 1b082ccf5901 ("gma500: Add Oaktrail support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c | 22 +++++++++++++---------
>  1 file changed, 13 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c b/drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c
> index e28107061148..fc9a34ed58bd 100644
> --- a/drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c
> +++ b/drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c
> @@ -279,11 +279,8 @@ int oaktrail_hdmi_i2c_init(struct pci_dev *dev)
>         hdmi_dev = pci_get_drvdata(dev);
>
>         i2c_dev = kzalloc(sizeof(struct hdmi_i2c_dev), GFP_KERNEL);
> -       if (i2c_dev = NULL) {
> -               DRM_ERROR("Can't allocate interface\n");
> -               ret = -ENOMEM;
> -               goto exit;
> -       }
> +       if (!i2c_dev)
> +               return -ENOMEM;
>
>         i2c_dev->adap = &oaktrail_hdmi_i2c_adapter;
>         i2c_dev->status = I2C_STAT_INIT;
> @@ -300,16 +297,23 @@ int oaktrail_hdmi_i2c_init(struct pci_dev *dev)
>                           oaktrail_hdmi_i2c_adapter.name, hdmi_dev);
>         if (ret) {
>                 DRM_ERROR("Failed to request IRQ for I2C controller\n");
> -               goto err;
> +               goto free_dev;
>         }
>
>         /* Adapter registration */
>         ret = i2c_add_numbered_adapter(&oaktrail_hdmi_i2c_adapter);
> -       return ret;
> +       if (ret) {
> +               DRM_ERROR("Failed to add I2C adapter\n");
> +               goto free_irq;
> +       }
>
> -err:
> +       return 0;
> +
> +free_irq:
> +       free_irq(dev->irq, hdmi_dev);
> +free_dev:
>         kfree(i2c_dev);
> -exit:
> +
>         return ret;
>  }
>
> --
> 2.29.2
>

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

end of thread, other threads:[~2020-12-03  9:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03  8:40 [PATCH] gma500: clean up error handling in init Dan Carpenter
2020-12-03  9:45 ` Patrik Jakobsson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).