git: aa85e7aa36bb - stable/15 - ix(4): Sanitize negative error codes

From: Krzysztof Galazka <kgalazka_at_FreeBSD.org>
Date: Tue, 01 Sep 2026 09:04:10 UTC
The branch stable/15 has been updated by kgalazka:

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

commit aa85e7aa36bb9651130ea6f25e830235db4e5f5c
Author:     Sobczyk, Pawel <pawel.sobczyk@intel.com>
AuthorDate: 2026-08-18 08:10:54 +0000
Commit:     Krzysztof Galazka <kgalazka@FreeBSD.org>
CommitDate: 2026-09-01 09:03:21 +0000

    ix(4): Sanitize negative error codes
    
    Due to development history FreeBSD driver error codes are reported
    the same way as in Linux (as negatives) which is inconsistent
    with FreeBSD standard. It may cause unexpected behavior when driver
    errors are interpreted by a kernel as syscall handler return values.
    This patch converts error codes from negative to positive values for
    NVM access functions.
    
    Signed-off-by: Pawel Sobczyk <pawel.sobczyk@intel.com>
    
    Reviewed by:    kbowling, erj, milosz.linkiewicz_intel.com
    Tested by:      Mateusz Moga <mateusz.moga@intel.com>
    Sponsored by:   Intel Corporation
    Differential Revision:  https://reviews.freebsd.org/D57642
    
    (cherry picked from commit 33e2eac3e3e738daa95a06f42d6c661b87ad9aac)
---
 sys/dev/ixgbe/if_ix.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/sys/dev/ixgbe/if_ix.c b/sys/dev/ixgbe/if_ix.c
index f08405059677..abe226a5e11a 100644
--- a/sys/dev/ixgbe/if_ix.c
+++ b/sys/dev/ixgbe/if_ix.c
@@ -1592,8 +1592,9 @@ ixgbe_nvm_access_ioctl(struct ixgbe_softc *sc, struct ifdrv *ifd)
 	size_t ifd_len = ifd->ifd_len;
 	size_t malloc_len;
 	device_t dev = sc->dev;
+	s32 status;
 	u8 *nvm_buffer;
-	s32 error = 0;
+	int error = 0;
 
 	/*
 	 * ifioctl forwards SIOCxDRVSPEC to iflib without conducting
@@ -1642,10 +1643,10 @@ ixgbe_nvm_access_ioctl(struct ixgbe_softc *sc, struct ifdrv *ifd)
 	    (nvm_buffer + sizeof(struct ixgbe_nvm_access_cmd));
 
 	/* Handle the NVM access request */
-	error = ixgbe_handle_nvm_access(hw, cmd, data);
-	if (error) {
+	status = ixgbe_handle_nvm_access(hw, cmd, data);
+	if (status) {
 		device_printf(dev, "%s: NVM access request failed, error %d\n",
-		    __func__, error);
+		    __func__, status);
 	}
 
 	/* Copy the possibly modified contents of the handled request out */
@@ -1657,6 +1658,20 @@ ixgbe_nvm_access_ioctl(struct ixgbe_softc *sc, struct ifdrv *ifd)
 		goto cleanup_free_nvm_buffer;
 	}
 
+	/* Convert private status to an error code for proper ioctl response */
+	switch (status) {
+	case IXGBE_SUCCESS:
+		error = 0;
+		break;
+	case IXGBE_ERR_OUT_OF_RANGE:
+		error = ENOTTY;
+		break;
+	case IXGBE_ERR_PARAM:
+	default:
+		error = EINVAL;
+		break;
+	}
+
 cleanup_free_nvm_buffer:
 	free(nvm_buffer, M_IXGBE);
 	return (error);