gma500: clean up error handling in init
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 3 Dec 2020 08:40:48 +0000 (11:40 +0300)
committerPatrik Jakobsson <patrik.r.jakobsson@gmail.com>
Thu, 3 Dec 2020 09:50:57 +0000 (10:50 +0100)
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>
Signed-off-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/X8ikkAqZfnDO2lu6@mwanda
drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c

index e281070611480694006a6fe3e2d629524dbb422f..fc9a34ed58bd136f298a1cffb23ec2f88b8f2d70 100644 (file)
@@ -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;
 }