2011-03-10 02:43:51

by Alexander Beregalov

[permalink] [raw]
Subject: [PATCH next 1/6] staging: altera-stapl: fix memory leaks

Free resources before exit.

Signed-off-by: Alexander Beregalov <[email protected]>
Cc: Igor M. Liplianin <[email protected]>
---
drivers/staging/altera-stapl/altera.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/altera-stapl/altera.c b/drivers/staging/altera-stapl/altera.c
index 05aad35..fcc7650 100644
--- a/drivers/staging/altera-stapl/altera.c
+++ b/drivers/staging/altera-stapl/altera.c
@@ -2435,11 +2435,16 @@ int altera_init(struct altera_config *config, const struct firmware *fw)
if (!key)
return -ENOMEM;
value = kzalloc(257 * sizeof(char), GFP_KERNEL);
- if (!value)
+ if (!value) {
+ kfree(key);
return -ENOMEM;
+ }
astate = kzalloc(sizeof(struct altera_state), GFP_KERNEL);
- if (!astate)
+ if (!astate) {
+ kfree(value);
+ kfree(key);
return -ENOMEM;
+ }

astate->config = config;
if (!astate->config->jtag_io) {
--
1.7.4.1


2011-03-10 02:44:08

by Alexander Beregalov

[permalink] [raw]
Subject: [PATCH next 2/6] staging: bcm: fix memory leaks

Free resources before exit.

Signed-off-by: Alexander Beregalov <[email protected]>
---
drivers/staging/bcm/Bcmchar.c | 1 +
drivers/staging/bcm/CmHost.c | 46 ++++++++++++++++++++++++++++------------
2 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c
index 867dbf1..0013315 100644
--- a/drivers/staging/bcm/Bcmchar.c
+++ b/drivers/staging/bcm/Bcmchar.c
@@ -311,6 +311,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
{
BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
(int)sRdmBuffer.Register);
+ kfree(temp_buff);
return -EINVAL;
}

diff --git a/drivers/staging/bcm/CmHost.c b/drivers/staging/bcm/CmHost.c
index 017b471..6b9d8b1 100644
--- a/drivers/staging/bcm/CmHost.c
+++ b/drivers/staging/bcm/CmHost.c
@@ -1671,6 +1671,7 @@ ULONG StoreCmControlResponseMessage(PMINI_ADAPTER Adapter,PVOID pvBuffer,UINT *p
stLocalSFDeleteRequest *pstDeletionRequest;
UINT uiSearchRuleIndex;
ULONG ulSFID;
+ ULONG ret;

pstAddIndicationAlt = (stLocalSFAddIndicationAlt *)(pvBuffer);

@@ -1709,12 +1710,16 @@ ULONG StoreCmControlResponseMessage(PMINI_ADAPTER Adapter,PVOID pvBuffer,UINT *p
/* AUTHORIZED SET */
pstAddIndication->psfAuthorizedSet = (stServiceFlowParamSI *)
GetNextTargetBufferLocation(Adapter, pstAddIndicationAlt->u16TID);
- if(!pstAddIndication->psfAuthorizedSet)
- return 0;
+ if(!pstAddIndication->psfAuthorizedSet) {
+ ret = 0
+ goto exit;
+ }

if(StoreSFParam(Adapter,(PUCHAR)&pstAddIndicationAlt->sfAuthorizedSet,
- (ULONG)pstAddIndication->psfAuthorizedSet)!= 1)
- return 0;
+ (ULONG)pstAddIndication->psfAuthorizedSet)!= 1) {
+ ret = 0;
+ goto exit;
+ }

/* this can't possibly be right */
pstAddIndication->psfAuthorizedSet = (stServiceFlowParamSI *)ntohl((ULONG)pstAddIndication->psfAuthorizedSet);
@@ -1731,7 +1736,8 @@ ULONG StoreCmControlResponseMessage(PMINI_ADAPTER Adapter,PVOID pvBuffer,UINT *p
AddRequest.psfParameterSet =pstAddIndication->psfAuthorizedSet ;
(*puBufferLength) = sizeof(stLocalSFAddRequest);
memcpy(pvBuffer,&AddRequest,sizeof(stLocalSFAddRequest));
- return 1;
+ ret = 1;
+ goto exit;
}

// Since it's not DSA_REQ, we can access all field in pstAddIndicationAlt
@@ -1748,10 +1754,14 @@ ULONG StoreCmControlResponseMessage(PMINI_ADAPTER Adapter,PVOID pvBuffer,UINT *p
/* ADMITTED SET */
pstAddIndication->psfAdmittedSet = (stServiceFlowParamSI *)
GetNextTargetBufferLocation(Adapter, pstAddIndicationAlt->u16TID);
- if(!pstAddIndication->psfAdmittedSet)
- return 0;
- if(StoreSFParam(Adapter,(PUCHAR)&pstAddIndicationAlt->sfAdmittedSet,(ULONG)pstAddIndication->psfAdmittedSet) != 1)
- return 0;
+ if(!pstAddIndication->psfAdmittedSet) {
+ ret = 0;
+ goto exit;
+ }
+ if(StoreSFParam(Adapter,(PUCHAR)&pstAddIndicationAlt->sfAdmittedSet,(ULONG)pstAddIndication->psfAdmittedSet) != 1) {
+ ret = 0;
+ goto exit;
+ }

pstAddIndication->psfAdmittedSet = (stServiceFlowParamSI *)ntohl((ULONG)pstAddIndication->psfAdmittedSet);

@@ -1759,17 +1769,25 @@ ULONG StoreCmControlResponseMessage(PMINI_ADAPTER Adapter,PVOID pvBuffer,UINT *p
/* ACTIVE SET */
pstAddIndication->psfActiveSet = (stServiceFlowParamSI *)
GetNextTargetBufferLocation(Adapter, pstAddIndicationAlt->u16TID);
- if(!pstAddIndication->psfActiveSet)
- return 0;
- if(StoreSFParam(Adapter,(PUCHAR)&pstAddIndicationAlt->sfActiveSet,(ULONG)pstAddIndication->psfActiveSet) != 1)
- return 0;
+ if(!pstAddIndication->psfActiveSet) {
+ ret = 0;
+ goto exit;
+ }
+ if(StoreSFParam(Adapter,(PUCHAR)&pstAddIndicationAlt->sfActiveSet,(ULONG)pstAddIndication->psfActiveSet) != 1) {
+ ret = 0;
+ goto exit;
+ }

pstAddIndication->psfActiveSet = (stServiceFlowParamSI *)ntohl((ULONG)pstAddIndication->psfActiveSet);

(*puBufferLength) = sizeof(stLocalSFAddIndication);
*(stLocalSFAddIndication *)pvBuffer = *pstAddIndication;
+
+ ret = 1;
+
+exit:
kfree(pstAddIndication);
- return 1;
+ return ret;
}


--
1.7.4.1

2011-03-10 02:44:11

by Alexander Beregalov

[permalink] [raw]
Subject: [PATCH next 5/6] staging: hv: fix memory leaks

Free resources before exit.

Signed-off-by: Alexander Beregalov <[email protected]>
---
drivers/staging/hv/hv_mouse.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/hv/hv_mouse.c b/drivers/staging/hv/hv_mouse.c
index 8f94f43..954164c 100644
--- a/drivers/staging/hv/hv_mouse.c
+++ b/drivers/staging/hv/hv_mouse.c
@@ -688,6 +688,7 @@ static int MousevscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)

if (ret != 0) {
pr_err("unable to open channel: %d", ret);
+ FreeInputDevice(inputDevice);
return -1;
}

@@ -699,6 +700,7 @@ static int MousevscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
pr_err("unable to connect channel: %d", ret);

vmbus_close(Device->channel);
+ FreeInputDevice(inputDevice);
return ret;
}

--
1.7.4.1

2011-03-10 02:44:13

by Alexander Beregalov

[permalink] [raw]
Subject: [PATCH next 6/6] staging: ste_rmi4: fix memory leaks

Free resources before exit.

Signed-off-by: Alexander Beregalov <[email protected]>
---
drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c b/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
index 51b4a79..d55a8e4 100644
--- a/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
+++ b/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
@@ -764,8 +764,10 @@ static int synaptics_rmi4_i2c_query_device(struct synaptics_rmi4_data *pdata)
(pdata, rfi,
&rmi_fd,
intr_count);
- if (retval < 0)
+ if (retval < 0) {
+ kfree(rfi);
return retval;
+ }
}
break;
}
--
1.7.4.1

2011-03-10 02:44:45

by Alexander Beregalov

[permalink] [raw]
Subject: [PATCH next 4/6] staging: crystalhd: fix memory leaks

Free resources before exit.

Signed-off-by: Alexander Beregalov <[email protected]>
---
drivers/staging/crystalhd/crystalhd_hw.c | 1 +
drivers/staging/crystalhd/crystalhd_lnx.c | 18 +++++++++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/crystalhd/crystalhd_hw.c b/drivers/staging/crystalhd/crystalhd_hw.c
index 153ddbf..13a514d 100644
--- a/drivers/staging/crystalhd/crystalhd_hw.c
+++ b/drivers/staging/crystalhd/crystalhd_hw.c
@@ -1965,6 +1965,7 @@ enum BC_STATUS crystalhd_hw_setup_dma_rings(struct crystalhd_hw *hw)
} else {
BCMLOG_ERR("Insufficient Memory For RX\n");
crystalhd_hw_free_dma_rings(hw);
+ kfree(rpkt);
return BC_STS_INSUFF_RES;
}
rpkt->desc_mem.pdma_desc_start = mem;
diff --git a/drivers/staging/crystalhd/crystalhd_lnx.c b/drivers/staging/crystalhd/crystalhd_lnx.c
index 719e70b..2b47ef9 100644
--- a/drivers/staging/crystalhd/crystalhd_lnx.c
+++ b/drivers/staging/crystalhd/crystalhd_lnx.c
@@ -561,7 +561,7 @@ 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",
@@ -572,7 +572,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 +588,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 +602,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 +621,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
--
1.7.4.1

2011-03-10 02:45:04

by Alexander Beregalov

[permalink] [raw]
Subject: [PATCH next 3/6] staging: brcm80211: fix memory leaks

Free resources before exit.

Signed-off-by: Alexander Beregalov <[email protected]>
---
drivers/staging/brcm80211/brcmfmac/dhd_sdio.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/brcm80211/brcmfmac/dhd_sdio.c b/drivers/staging/brcm80211/brcmfmac/dhd_sdio.c
index b74b3c6..28bc553 100644
--- a/drivers/staging/brcm80211/brcmfmac/dhd_sdio.c
+++ b/drivers/staging/brcm80211/brcmfmac/dhd_sdio.c
@@ -5649,6 +5649,10 @@ static int dhdsdio_download_code_array(struct dhd_bus *bus)
unsigned char *ularray;

ularray = kmalloc(bus->ramsize, GFP_ATOMIC);
+ if (!ularray) {
+ bcmerror = BCME_NOMEM;
+ goto err;
+ }
/* Upload image to verify downloaded contents. */
offset = 0;
memset(ularray, 0xaa, bus->ramsize);
@@ -5660,7 +5664,7 @@ static int dhdsdio_download_code_array(struct dhd_bus *bus)
DHD_ERROR(("%s: error %d on reading %d membytes"
" at 0x%08x\n",
__func__, bcmerror, MEMBLOCK, offset));
- goto err;
+ goto free;
}

offset += MEMBLOCK;
@@ -5674,7 +5678,7 @@ static int dhdsdio_download_code_array(struct dhd_bus *bus)
DHD_ERROR(("%s: error %d on reading %d membytes at 0x%08x\n",
__func__, bcmerror,
sizeof(dlarray) - offset, offset));
- goto err;
+ goto free;
}
}

@@ -5682,11 +5686,11 @@ static int dhdsdio_download_code_array(struct dhd_bus *bus)
DHD_ERROR(("%s: Downloaded image is corrupted.\n",
__func__));
ASSERT(0);
- goto err;
+ goto free;
} else
DHD_ERROR(("%s: Download/Upload/Compare succeeded.\n",
__func__));
-
+free:
kfree(ularray);
}
#endif /* DHD_DEBUG */
--
1.7.4.1

2011-03-11 22:33:29

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH next 2/6] staging: bcm: fix memory leaks

On Thu, Mar 10, 2011 at 05:43:04AM +0300, Alexander Beregalov wrote:
> Free resources before exit.

Next time, test your patches before sending them out. This one breaks
the build so I've dropped all of the patches in this series. Please fix
them, test them (by at the very _least_ building them) and then resend
them.

thanks,

greg k-h

2011-03-11 22:33:27

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH next 1/6] staging: altera-stapl: fix memory leaks

On Thu, Mar 10, 2011 at 05:43:03AM +0300, Alexander Beregalov wrote:
> Free resources before exit.
>
> Signed-off-by: Alexander Beregalov <[email protected]>
> Cc: Igor M. Liplianin <[email protected]>
> ---
> drivers/staging/altera-stapl/altera.c | 9 +++++++--

This isn't in my tree, it needs to go through Mauro's tree.

thanks,

greg k-h

2011-03-13 19:00:39

by Alexander Beregalov

[permalink] [raw]
Subject: Re: [PATCH next 2/6] staging: bcm: fix memory leaks

On 12 March 2011 01:31, Greg KH <[email protected]> wrote:
> On Thu, Mar 10, 2011 at 05:43:04AM +0300, Alexander Beregalov wrote:
>> Free resources before exit.
>
> Next time, test your patches before sending them out.  This one breaks
> the build so I've dropped all of the patches in this series.  Please fix
> them, test them (by at the very _least_ building them) and then resend
> them.

Sorry for that, I have sent them again.