staging: crystalhd: fix memory leaks
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / staging / crystalhd / crystalhd_lnx.c
index 719e70b..7e0c199 100644 (file)
@@ -393,8 +393,7 @@ static int __devinit chd_dec_init_chdev(struct crystalhd_adp *adp)
 
        /* Allocate general purpose ioctl pool. */
        for (i = 0; i < CHD_IODATA_POOL_SZ; i++) {
-               /* FIXME: jarod: why atomic? */
-               temp = kzalloc(sizeof(struct crystalhd_ioctl_data), GFP_ATOMIC);
+               temp = kzalloc(sizeof(struct crystalhd_ioctl_data), GFP_KERNEL);
                if (!temp) {
                        BCMLOG_ERR("ioctl data pool kzalloc failed\n");
                        rc = -ENOMEM;
@@ -549,8 +548,7 @@ static int __devinit chd_dec_pci_probe(struct pci_dev *pdev,
               pdev->vendor, pdev->device, pdev->subsystem_vendor,
               pdev->subsystem_device);
 
-       /* FIXME: jarod: why atomic? */
-       pinfo = kzalloc(sizeof(struct crystalhd_adp), GFP_ATOMIC);
+       pinfo = kzalloc(sizeof(struct crystalhd_adp), GFP_KERNEL);
        if (!pinfo) {
                BCMLOG_ERR("Failed to allocate memory\n");
                return -ENOMEM;
@@ -561,10 +559,10 @@ static int __devinit chd_dec_pci_probe(struct pci_dev *pdev,
        rc = pci_enable_device(pdev);
        if (rc) {
                BCMLOG_ERR("Failed to enable PCI device\n");
-               return rc;
+               goto err;
        }
 
-       snprintf(pinfo->name, 31, "crystalhd_pci_e:%d:%d:%d",
+       snprintf(pinfo->name, sizeof(pinfo->name), "crystalhd_pci_e:%d:%d:%d",
                 pdev->bus->number, PCI_SLOT(pdev->devfn),
                 PCI_FUNC(pdev->devfn));
 
@@ -572,7 +570,8 @@ static int __devinit chd_dec_pci_probe(struct pci_dev *pdev,
        if (rc) {
                BCMLOG_ERR("Failed to setup memory regions.\n");
                pci_disable_device(pdev);
-               return -ENOMEM;
+               rc = -ENOMEM;
+               goto err;
        }
 
        pinfo->present  = 1;
@@ -587,7 +586,8 @@ static int __devinit chd_dec_pci_probe(struct pci_dev *pdev,
        if (rc) {
                BCMLOG_ERR("_enable_int err:%d\n", rc);
                pci_disable_device(pdev);
-               return -ENODEV;
+               rc = -ENODEV;
+               goto err;
        }
 
        /* Set dma mask... */
@@ -600,14 +600,16 @@ static int __devinit chd_dec_pci_probe(struct pci_dev *pdev,
        } else {
                BCMLOG_ERR("Unabled to setup DMA %d\n", rc);
                pci_disable_device(pdev);
-               return -ENODEV;
+               rc = -ENODEV;
+               goto err;
        }
 
        sts = crystalhd_setup_cmd_context(&pinfo->cmds, pinfo);
        if (sts != BC_STS_SUCCESS) {
                BCMLOG_ERR("cmd setup :%d\n", sts);
                pci_disable_device(pdev);
-               return -ENODEV;
+               rc = -ENODEV;
+               goto err;
        }
 
        pci_set_master(pdev);
@@ -617,6 +619,10 @@ static int __devinit chd_dec_pci_probe(struct pci_dev *pdev,
        g_adp_info = pinfo;
 
        return 0;
+
+err:
+       kfree(pinfo);
+       return rc;
 }
 
 #ifdef CONFIG_PM