From nobody Tue Sep 10 04:31:04 2024 X-Original-To: dev-commits-src-all@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 4X2rP43Vw3z5Wcmm; Tue, 10 Sep 2024 04:31:04 +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 4X2rP433Vlz51RS; Tue, 10 Sep 2024 04:31:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725942664; 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=0FM3wmW1a+KgywbR9MEV2ARTAyoqs3fITm8uG9TMvkU=; b=ymSCHt2tL6OsVthQzKV/kZ5mMDgs2No9kBM5Mc8T8CrEZZXaqnrekpppkSCh8oeT5UOS+0 NMqTO0V0EeLLvfYKldxRK+54MPNQ49Mb+j/yj1MMK38eS4Dmqi+OgL85ZP4MBPwx/AN+py rPdb3Pir/1FKVMdoiLGmlUEYm/Yu1lYE6w3L4rrYPTP1AQP0DiWIDlDarXSkKvmXecKGXk zX1ePZngMIt+y7fj6M9KRZbTQ3YqusSGwadDu8XN1sJyXLqzZRw50r51ntVt4rMlHVEgza JKmaP9FDvg3uQSD+vRv0ilfm14mZkW9/gNdbi2ycPiCnc6yCDUdKwiny+RjOJw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725942664; a=rsa-sha256; cv=none; b=f9sqZsKaPMyLAji0MbtZ2KqXDHY3S24RNx8uMg+T5WOeWKWdVlfdcFQOR33V4BfY0X/1Ws p961dAXtwcoQQMzbpw3vJeV+rdM8AILA4c2gbd6zHekOd6yPX9UwtxNJ346BV2hrJYyj3E D3CT5Z468HPvi3JtV9tzSVZW16K/3RreOBL61uLLl+KfXnPwK8O7/Kqbj59CC3QeLjOhlG J/bHq6SKBsQKF5j789OoNxv7r7BsDIjazPkWckA7+uAppWgfIpHiayxOYUhjKJPd9JGp/Q U7GufY3HSDWnSyBcvLwWKIBNWBVJtHz6wwO8y0iyhjMdVy1He0sFDR+RH33tGQ== 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=1725942664; 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=0FM3wmW1a+KgywbR9MEV2ARTAyoqs3fITm8uG9TMvkU=; b=Lv907peN4Y87sxAhDONl61UHvonlJQL3QblNPE5wPgUOWlsgCor1RwjE6gLUVaEoDFYO0Y g9ySFk0WVEIXqhN3GwDm+8/C535Al5qV+MgyC9lyxa4jTMlUF9IVq9hw3V6h/G4dsB4Q8Z 4jKKDDtIDoFOyRB1y3h2vXIrVXAVgzQwg4M6+V4Xow/BTdGNK/Cjc392XMM0R1f+y/+chJ xkIAFWEePA7XA+/hWyfa3jk3A7ukGUq7fQtNXcv+e1CCYNb4jxCs9FSGdwO+mq8rf0HZT4 yo0X3CjD49KDxzsECcWY0fWqHTFiDwHyDuwj5DSqVBARRtPlmN74TMy1SOrr7A== 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 4X2rP42fgyzYW5; Tue, 10 Sep 2024 04:31:04 +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 48A4V4Ma015938; Tue, 10 Sep 2024 04:31:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48A4V4rt015935; Tue, 10 Sep 2024 04:31:04 GMT (envelope-from git) Date: Tue, 10 Sep 2024 04:31:04 GMT Message-Id: <202409100431.48A4V4rt015935@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Xin LI Subject: git: b10e93220e52 - stable/14 - mfiutil: Handle potential ioctl(2) failures in mfi_flash.c List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/14 X-Git-Reftype: branch X-Git-Commit: b10e93220e5221147483ef17f015863138e31583 Auto-Submitted: auto-generated The branch stable/14 has been updated by delphij: URL: https://cgit.FreeBSD.org/src/commit/?id=b10e93220e5221147483ef17f015863138e31583 commit b10e93220e5221147483ef17f015863138e31583 Author: WHR AuthorDate: 2024-09-03 05:12:20 +0000 Commit: Xin LI CommitDate: 2024-09-10 04:30: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 Pull Request: https://github.com/freebsd/freebsd-src/pull/1403 (cherry picked from commit bac98f86c98421f6153c749b6c77995ef778e2fb) --- 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;