git: b165ec5e21cf - stable/14 - LinuxKPI: firmware: remove `enoentok` logic in `*firmware_request(..)`

From: Enji Cooper <ngie_at_FreeBSD.org>
Date: Sun, 01 Nov 2026 01:23:05 UTC
The branch stable/14 has been updated by ngie:

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

commit b165ec5e21cf8ee53921eb6c0614c0f61eafab66
Author:     Enji Cooper <ngie@FreeBSD.org>
AuthorDate: 2026-10-07 18:22:00 +0000
Commit:     Enji Cooper <ngie@FreeBSD.org>
CommitDate: 2026-11-01 01:22:56 +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
    
    (cherry picked from commit ef947bb97302d8862545cd0a5f38b24fa1bae2f6)
---
 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 f514f05ea67b..7c35320b34fa 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;
@@ -123,12 +123,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",
@@ -158,8 +154,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.
@@ -199,8 +195,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
@@ -208,7 +203,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));
 }