mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
ID: 50 - ipmi_hpmfwupg needs a clean up
HpmfwupgGetBuffersFromFile() - simplify function in order to kill unnecessary indent. Also, notify user about malloc failure and exit early.
This commit is contained in:
parent
ada4b48baf
commit
29af592773
@ -1534,33 +1534,32 @@ HpmfwupgGetBufferFromFile(char *imageFilename,
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
FILE *pImageFile = fopen(imageFilename, "rb");
|
FILE *pImageFile = fopen(imageFilename, "rb");
|
||||||
if (pImageFile == NULL) {
|
if (pImageFile == NULL) {
|
||||||
lprintf(LOG_NOTICE, "Cannot open image file %s",
|
lprintf(LOG_ERR, "Cannot open image file '%s'",
|
||||||
imageFilename);
|
imageFilename);
|
||||||
|
return HPMFWUPG_ERROR;
|
||||||
|
}
|
||||||
|
/* Get the raw data in file */
|
||||||
|
fseek(pImageFile, 0, SEEK_END);
|
||||||
|
pFwupgCtx->imageSize = ftell(pImageFile);
|
||||||
|
pFwupgCtx->pImageData = malloc(sizeof(unsigned char)*pFwupgCtx->imageSize);
|
||||||
|
if (pFwupgCtx->pImageData == NULL) {
|
||||||
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
|
fclose(pImageFile);
|
||||||
|
return HPMFWUPG_ERROR;
|
||||||
|
}
|
||||||
|
rewind(pImageFile);
|
||||||
|
ret = fread(pFwupgCtx->pImageData,
|
||||||
|
sizeof(unsigned char),
|
||||||
|
pFwupgCtx->imageSize,
|
||||||
|
pImageFile);
|
||||||
|
if (ret != pFwupgCtx->imageSize) {
|
||||||
|
lprintf(LOG_ERR,
|
||||||
|
"Failed to read file %s size %d",
|
||||||
|
imageFilename,
|
||||||
|
pFwupgCtx->imageSize);
|
||||||
rc = HPMFWUPG_ERROR;
|
rc = HPMFWUPG_ERROR;
|
||||||
}
|
}
|
||||||
if (rc == HPMFWUPG_SUCCESS) {
|
fclose(pImageFile);
|
||||||
/* Get the raw data in file */
|
|
||||||
fseek(pImageFile, 0, SEEK_END);
|
|
||||||
pFwupgCtx->imageSize = ftell(pImageFile);
|
|
||||||
pFwupgCtx->pImageData = malloc(sizeof(unsigned char)*pFwupgCtx->imageSize);
|
|
||||||
rewind(pImageFile);
|
|
||||||
if (pFwupgCtx->pImageData != NULL) {
|
|
||||||
ret = fread(pFwupgCtx->pImageData,
|
|
||||||
sizeof(unsigned char),
|
|
||||||
pFwupgCtx->imageSize,
|
|
||||||
pImageFile);
|
|
||||||
if (ret != pFwupgCtx->imageSize) {
|
|
||||||
lprintf(LOG_ERROR,
|
|
||||||
"Failed to read file %s size %d",
|
|
||||||
imageFilename,
|
|
||||||
pFwupgCtx->imageSize);
|
|
||||||
rc = HPMFWUPG_ERROR;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
rc = HPMFWUPG_ERROR;
|
|
||||||
}
|
|
||||||
fclose(pImageFile);
|
|
||||||
}
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user