aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWHR <whr@rivoreo.one>2024-09-03 05:12:20 +0000
committerXin LI <delphij@FreeBSD.org>2024-09-10 04:30:51 +0000
commitb10e93220e5221147483ef17f015863138e31583 (patch)
tree047ca08450e7095db6b1f06d3d0b8d430614f8c9
parent5297156047f29274c9b6e68a514e72a858059890 (diff)
downloadsrc-b10e93220e5221147483ef17f015863138e31583.tar.gz
src-b10e93220e5221147483ef17f015863138e31583.zip
mfiutil: Handle potential ioctl(2) failures in mfi_flash.c
The return value of function 'mfi_dcmd_command' should always be checked for the potential ioctl(2) failure. PR: 281158 Pull Request: https://github.com/freebsd/freebsd-src/pull/1403 (cherry picked from commit bac98f86c98421f6153c749b6c77995ef778e2fb)
-rw-r--r--usr.sbin/mfiutil/mfi_flash.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/usr.sbin/mfiutil/mfi_flash.c b/usr.sbin/mfiutil/mfi_flash.c
index 2fbfc978edac..4d1930af4941 100644
--- a/usr.sbin/mfiutil/mfi_flash.c
+++ b/usr.sbin/mfiutil/mfi_flash.c
@@ -129,9 +129,15 @@ flash_adapter(int ac, char **av)
/* First, ask the firmware to allocate space for the flash file. */
mbox_store_word(mbox, sb.st_size);
- mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_OPEN, NULL, 0, mbox, 4, &status);
+ if (mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_OPEN, NULL, 0, mbox, 4,
+ &status) < 0) {
+ error = errno;
+ warn("Failed to allocate flash memory");
+ goto error;
+ }
if (status != MFI_STAT_OK) {
- warnx("Failed to alloc flash memory: %s", mfi_status(status));
+ warnx("Failed to allocate flash memory: %s",
+ mfi_status(status));
error = EIO;
goto error;
}
@@ -148,19 +154,26 @@ flash_adapter(int ac, char **av)
nread = read(flash, buf, FLASH_BUF_SIZE);
if (nread <= 0 || nread % 1024 != 0) {
warnx("Bad read from flash file");
- mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_CLOSE, NULL, 0,
- NULL, 0, NULL);
+ if (mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_CLOSE,
+ NULL, 0, NULL, 0, NULL) < 0) {
+ warn("Failed to discard flash memory");
+ }
error = ENXIO;
goto error;
}
mbox_store_word(mbox, offset);
- mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_DOWNLOAD, buf, nread,
- mbox, 4, &status);
+ if (mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_DOWNLOAD, buf, nread,
+ mbox, 4, &status) < 0) {
+ error = errno;
+ warn("Failed to download firmware");
+ goto error;
+ }
if (status != MFI_STAT_OK) {
- warnx("Flash download failed: %s", mfi_status(status));
- mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_CLOSE, NULL, 0,
- NULL, 0, NULL);
+ warnx("Failed to download firmware: %s",
+ mfi_status(status));
+ mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_CLOSE, NULL,
+ 0, NULL, 0, NULL);
error = ENXIO;
goto error;
}
@@ -171,8 +184,12 @@ flash_adapter(int ac, char **av)
/* Kick off the flash. */
printf("WARNING: Firmware flash in progress, do not reboot machine... ");
fflush(stdout);
- mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_FLASH, &dummy, sizeof(dummy),
- NULL, 0, &status);
+ if (mfi_dcmd_command(fd, MFI_DCMD_FLASH_FW_FLASH, &dummy, sizeof(dummy),
+ NULL, 0, &status) < 0) {
+ error = errno;
+ printf("failed:\n\t%s\n", strerror(error));
+ goto error;
+ }
if (status != MFI_STAT_OK) {
printf("failed:\n\t%s\n", mfi_status(status));
error = ENXIO;