hpm: Adhere to centralized exiting

Replace `return`s with `goto`s to appropriate labels
(with or without closing the file).
This commit is contained in:
Josef Moellers 2019-01-24 09:35:02 +01:00 committed by Alexander Amelkin
parent 4631d3f942
commit 7941806a9b

View File

@ -1385,28 +1385,26 @@ int
HpmfwupgGetBufferFromFile(char *imageFilename,
struct HpmfwupgUpgradeCtx *pFwupgCtx)
{
int rc = HPMFWUPG_SUCCESS;
int rc = HPMFWUPG_ERROR;
int ret = 0;
FILE *pImageFile = fopen(imageFilename, "rb");
if (!pImageFile) {
lprintf(LOG_ERR, "Cannot open image file '%s'",
imageFilename);
return HPMFWUPG_ERROR;
goto ret_no_close;
}
/* Get the raw data in file */
ret = fseek(pImageFile, 0, SEEK_END);
if (ret != 0) {
lprintf(LOG_ERR, "Failed to seek in the image file '%s'",
imageFilename);
fclose(pImageFile);
return HPMFWUPG_ERROR;
goto ret_close;
}
pFwupgCtx->imageSize = ftell(pImageFile);
pFwupgCtx->pImageData = malloc(sizeof(unsigned char)*pFwupgCtx->imageSize);
if (!pFwupgCtx->pImageData) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
fclose(pImageFile);
return HPMFWUPG_ERROR;
goto ret_close;
}
rewind(pImageFile);
ret = fread(pFwupgCtx->pImageData,
@ -1418,9 +1416,14 @@ HpmfwupgGetBufferFromFile(char *imageFilename,
"Failed to read file %s size %d",
imageFilename,
pFwupgCtx->imageSize);
rc = HPMFWUPG_ERROR;
goto ret_close;
}
rc = HPMFWUPG_SUCCESS;
ret_close:
fclose(pImageFile);
ret_no_close:
return rc;
}