aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2018-10-31 15:54:11 +1030
committerStewart Smith <stewart@linux.ibm.com>2018-11-02 18:16:24 +1100
commitaac9abe6ccab2206f7b5155535ea6a90bb5072d0 (patch)
treebcc85dd5a19a7eeeb0368c1228170757beac0060
parent9da1e28ed4c010870b81fd59e6a34c15dd88c722 (diff)
downloadskiboot-aac9abe6ccab2206f7b5155535ea6a90bb5072d0.zip
skiboot-aac9abe6ccab2206f7b5155535ea6a90bb5072d0.tar.gz
skiboot-aac9abe6ccab2206f7b5155535ea6a90bb5072d0.tar.bz2
libflash/ipmi-hiomap: Cleanup allocation on init failure
[ Upstream commit f271f0263475776f78f403493d7ab6ccfbe5bfc2 ] Previously we were leaking the memory pointed by ctx if an IPMI error occurred during protocol initialisation. Make sure we free the memory if an error occurs. Signed-off-by: Andrew Jeffery <andrew@aj.id.au> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
-rw-r--r--libflash/ipmi-hiomap.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/libflash/ipmi-hiomap.c b/libflash/ipmi-hiomap.c
index 95c49b3..8a7a1af 100644
--- a/libflash/ipmi-hiomap.c
+++ b/libflash/ipmi-hiomap.c
@@ -813,25 +813,28 @@ int ipmi_hiomap_init(struct blocklevel_device **bl)
rc = ipmi_sel_register(CMD_OP_HIOMAP_EVENT, hiomap_event, ctx);
if (rc < 0)
- return rc;
+ goto err;
/* Ack all pending ack-able events to avoid spurious failures */
if (!hiomap_ack(ctx, HIOMAP_E_ACK_MASK)) {
prlog(PR_DEBUG, "Failed to ack events: 0x%x\n",
HIOMAP_E_ACK_MASK);
- return FLASH_ERR_AGAIN;
+ rc = FLASH_ERR_AGAIN;
+ goto err;
}
/* Negotiate protocol behaviour */
if (!hiomap_get_info(ctx)) {
prerror("Failed to get hiomap parameters\n");
- return FLASH_ERR_DEVICE_GONE;
+ rc = FLASH_ERR_DEVICE_GONE;
+ goto err;
}
/* Grab the flash parameters */
if (!hiomap_get_flash_info(ctx)) {
prerror("Failed to get flash parameters\n");
- return FLASH_ERR_DEVICE_GONE;
+ rc = FLASH_ERR_DEVICE_GONE;
+ goto err;
}
prlog(PR_NOTICE, "Negotiated hiomap protocol v%u\n", ctx->version);
@@ -847,6 +850,11 @@ int ipmi_hiomap_init(struct blocklevel_device **bl)
*bl = &(ctx->bl);
return 0;
+
+err:
+ free(ctx);
+
+ return rc;
}
void ipmi_hiomap_exit(struct blocklevel_device *bl)