[Skiboot] [PATCH] FSP/SYSPARAM: Fix memory leak in error path

Vasant Hegde hegdevasant at linux.vnet.ibm.com
Fri Mar 20 19:05:59 AEDT 2015


Signed-off-by: Vasant Hegde <hegdevasant at linux.vnet.ibm.com>
---
 hw/fsp/fsp-sysparam.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/hw/fsp/fsp-sysparam.c b/hw/fsp/fsp-sysparam.c
index 083c465..bd77a1f 100644
--- a/hw/fsp/fsp-sysparam.c
+++ b/hw/fsp/fsp-sysparam.c
@@ -152,11 +152,11 @@ int fsp_get_sys_param(uint32_t param_id, void *buffer, uint32_t length,
 	 * possible, so if this is going to be used a lot at runtime,
 	 * we probably want to pre-allocate a pool of these
 	 */
+	if (length > 4096)
+		return -EINVAL;
 	r = zalloc(sizeof(struct sysparam_req));
 	if (!r)
 		return -ENOMEM;
-	if (length > 4096)
-		return -EINVAL;
 	r->completion = async_complete;
 	r->comp_data = comp_data;
 	r->done = false;
@@ -174,6 +174,9 @@ int fsp_get_sys_param(uint32_t param_id, void *buffer, uint32_t length,
 		    param_id, length, tce_token);
 	rc = fsp_queue_msg(&r->msg, fsp_sysparam_get_complete);
 
+	if (rc)
+		free(r);
+
 	/* Asynchronous operation or queueing failure, return */
 	if (rc || async_complete)
 		return rc;
@@ -324,8 +327,10 @@ static int64_t fsp_opal_set_param(uint64_t async_token, uint32_t param_id,
 	}
 
 	comp_data = zalloc(sizeof(struct sysparam_comp_data));
-	if (!comp_data)
+	if (!comp_data) {
+		fsp_freemsg(msg);
 		return OPAL_NO_MEM;
+	}
 
 	comp_data->param_len = length;
 	comp_data->async_token = async_token;



More information about the Skiboot mailing list