git: ef947bb97302 - main - LinuxKPI: firmware: remove `enoentok` logic in `*firmware_request(..)`

From: Enji Cooper <ngie_at_FreeBSD.org>
Date: Wed, 07 Oct 2026 18:24:50 UTC
The branch main has been updated by ngie:

URL: https://cgit.FreeBSD.org/src/commit/?id=ef947bb97302d8862545cd0a5f38b24fa1bae2f6

commit ef947bb97302d8862545cd0a5f38b24fa1bae2f6
Author:     Enji Cooper <ngie@FreeBSD.org>
AuthorDate: 2026-10-07 18:22:00 +0000
Commit:     Enji Cooper <ngie@FreeBSD.org>
CommitDate: 2026-10-07 18:22:12 +0000

    LinuxKPI: firmware: remove `enoentok` logic in `*firmware_request(..)`
    
    Prior to this change, in the event that a firmware module could not be
    loaded, the linux_firmware driver would return a partially initialized
    structure with uninitialized/zeroed out values for certain fields. Linux
    does not do this, however, so some drivers that use
    `request_firmware_nowait` expecting Linux behavior, like `if_bcrmfmac`,
    would crash trying to dereference a NULL pointer.
    
    This doesn't address the load/unload situation completely as the driver
    remains loaded after the "firmware crashes", but it makes a completely
    unusable situation (a kernel panic) into a slightly more usable situation
    (driver does not unload).
    
    As a sidenote: the raw free(9) call was replaced with a call to
    `linuxkpi_release_firmware` because the latter call [better] ensures
    that all resources allocated earlier on in the function are cleaned up.
    
    MFC after:      1 weeks
    Reviewed by:    bz
    Differential Revision:  https://reviews.freebsd.org/D58451
---
 sys/compat/linuxkpi/common/src/linux_firmware.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_firmware.c b/sys/compat/linuxkpi/common/src/linux_firmware.c
index 0915b317c01e..0d8f9b770d70 100644
--- a/sys/compat/linuxkpi/common/src/linux_firmware.c
+++ b/sys/compat/linuxkpi/common/src/linux_firmware.c
@@ -57,7 +57,7 @@ struct lkpi_fw_task {
 
 static int
 _linuxkpi_request_firmware(const char *fw_name, const struct linuxkpi_firmware **fw,
-    struct device *dev, gfp_t gfp __unused, bool enoentok, bool warn)
+    struct device *dev, gfp_t gfp __unused, bool warn)
 {
 	const struct firmware *fbdfw;
 	struct linuxkpi_firmware *lfw;
@@ -124,12 +124,8 @@ _linuxkpi_request_firmware(const char *fw_name, const struct linuxkpi_firmware *
 		}
 	}
 	if (fbdfw == NULL) {
-		if (enoentok)
-			*fw = lfw;
-		else {
-			free(lfw, M_LKPI_FW);
-			*fw = NULL;
-		}
+		linuxkpi_release_firmware(lfw);
+		*fw = NULL;
 		if (warn)
 			device_printf(dev->bsddev,
 			    "could not load firmware image '%s'\n",
@@ -159,8 +155,8 @@ lkpi_fw_task(void *ctx, int pending)
 	if (lfwt->cont == NULL)
 		goto out;
 
-	_linuxkpi_request_firmware(lfwt->fw_name, &fw, lfwt->dev,
-	    lfwt->gfp, true, true);
+	_linuxkpi_request_firmware(lfwt->fw_name, &fw, lfwt->dev, lfwt->gfp,
+	    true);
 
 	/*
 	 * Linux seems to run the callback if it cannot find the firmware.
@@ -200,8 +196,7 @@ linuxkpi_request_firmware(const struct linuxkpi_firmware **fw,
     const char *fw_name, struct device *dev)
 {
 
-	return (_linuxkpi_request_firmware(fw_name, fw, dev, GFP_KERNEL, false,
-	    true));
+	return (_linuxkpi_request_firmware(fw_name, fw, dev, GFP_KERNEL, true));
 }
 
 int
@@ -209,7 +204,7 @@ linuxkpi_firmware_request_nowarn(const struct linuxkpi_firmware **fw,
     const char *fw_name, struct device *dev)
 {
 
-	return (_linuxkpi_request_firmware(fw_name, fw, dev, GFP_KERNEL, false,
+	return (_linuxkpi_request_firmware(fw_name, fw, dev, GFP_KERNEL,
 	    false));
 }