aboutsummaryrefslogtreecommitdiff
path: root/libflash/ipmi-hiomap.c
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-01 23:56:44 -0500
commitf271f0263475776f78f403493d7ab6ccfbe5bfc2 (patch)
tree0c17d218489bace1e000ee4c966d5de33e5ac841 /libflash/ipmi-hiomap.c
parent95f7b3b9698bf59766294ac9705d929723ffe574 (diff)
downloadskiboot-f271f0263475776f78f403493d7ab6ccfbe5bfc2.zip
skiboot-f271f0263475776f78f403493d7ab6ccfbe5bfc2.tar.gz
skiboot-f271f0263475776f78f403493d7ab6ccfbe5bfc2.tar.bz2
libflash/ipmi-hiomap: Cleanup allocation on init failure
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>
Diffstat (limited to 'libflash/ipmi-hiomap.c')
-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)