From nobody Tue Sep 03 05:48:22 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WyZRW0Tsjz5W07G; Tue, 03 Sep 2024 05:48:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WyZRW013qz4LZN; Tue, 3 Sep 2024 05:48:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725342503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RM30ponjqAxqwmj9jj30h35EnI5FMSAc4ycJB6DKZx4=; b=DEpBiaDu2NBWgnOZDrmqUKteQ8uTT415g4G9OkSbL5bVnBHl7LoN83MPOUpWgrCM0nTVTF L8ov+eSStJ6OfPHyG3JcFU/0QMlFLfvtuO5iFPJIOqPk72qr3p4487BIDJ+B0YpCEXCjOW HzG+tPvycfliZX5a9DeRtZ6eYVCY0KJjCQzTuDmgRKlnFS1KZFAUPJNpojWMYtqX9i9N8H sHrxHmec0wAoPf7KTBloFPVxX011DQnzp0T4kOFFMh2FjUaNKS88QiPK/HGMKniVryJwSu M1OaTABYQYahbcLr8jX6NbeVSI+72UdH5ShiJXooEXRYlgl4jwV7rJO7Fdi67A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725342503; a=rsa-sha256; cv=none; b=eAOK8bVN3IeZgnu5V1W251H3Kz8N1VKX7BllqgzWPwNhBHMYZOdhZ7v+Q+l5ljWyc2gxv8 NU2qOY0uuA0IOgo/YmMn+lm76C5JSROWGTE9MMSj9DyE8dfVD4HZ18AnW5AD1sIYdYCSA+ zknRkJclvPF9C0AlHCTyqcNIQFbH0PHm+OlC6MjRb9fIhBXRfg91FpFaicETim0cVTA8JX n6v8KlCZmYnmm9KE2UQ+lvE4i14PgIrN9sGQv79xpnzRbbybVkc8cej4VHMILuAnfGYsGa 8V42TyPGNmUaJsY9+2bKwcZy40hc8Xpwh0sNggugBGAUfl9XoGYCYHCMLmlyow== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725342503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RM30ponjqAxqwmj9jj30h35EnI5FMSAc4ycJB6DKZx4=; b=bOxJ6x0fo75fvnRu+FxdHoNSdUr9N2bm+46vsXL/BNBgJUwvBgyoUNH/qeLspDwjptvhDi AFqbFI4hwBEWywxhNipSZdUgYiw0zVss1c6xXNL+Asmcz/glGsEZ2dPy6GDcEt1233EGdM tN8HQg6FMLmNzczBo3A+r767GVwjAoJYBF1DfiMPhtBSyBx1ZuG5UccQGO6wYkFRTq+nza X28G0TyrRcpXB+YLH9AKGuk37hMUar9rZc45yLbSJySRvz2VholuMeku31faKvTMfNuRkU L83bMNX5/QtyKsbqPews4JeMBtawCov69vntzv+yYqZW+yerBUauXL58ud7UHw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WyZRV6c60zS80; Tue, 3 Sep 2024 05:48:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4835mMWx033076; Tue, 3 Sep 2024 05:48:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4835mMPs033073; Tue, 3 Sep 2024 05:48:22 GMT (envelope-from git) Date: Tue, 3 Sep 2024 05:48:22 GMT Message-Id: <202409030548.4835mMPs033073@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Xin LI Subject: git: bac98f86c984 - main - mfiutil: Handle potential ioctl(2) failures in mfi_flash.c List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: delphij X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bac98f86c98421f6153c749b6c77995ef778e2fb Auto-Submitted: auto-generated The branch main has been updated by delphij: URL: https://cgit.FreeBSD.org/src/commit/?id=bac98f86c98421f6153c749b6c77995ef778e2fb commit bac98f86c98421f6153c749b6c77995ef778e2fb Author: WHR AuthorDate: 2024-09-03 05:12:20 +0000 Commit: Xin LI CommitDate: 2024-09-03 05:46:51 +0000 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 MFC after: 1 week Pull Request: https://github.com/freebsd/freebsd-src/pull/1403 --- usr.sbin/mfiutil/mfi_flash.c | 39 ++++++++++++++++++++++++++++----------- 1 file 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;