git: 33e2eac3e3e7 - main - ix(4): Sanitize negative error codes
Krzysztof Galazka <[email protected]>
| Newsgroups | gmane.os.freebsd.devel.cvs.src,gmane.os.freebsd.current.scm |
|---|---|
| Message-ID | <[email protected]> |
The branch main has been updated by kgalazka: URL: https://cgit.FreeBSD.org/src/commit/?id=33e2eac3e3e738daa95a06f42d6c661b87ad9aac commit 33e2eac3e3e738daa95a06f42d6c661b87ad9aac Author: Sobczyk, Pawel <[email protected]> AuthorDate: 2026-08-18 08:10:54 +0000 Commit: Krzysztof Galazka <[email protected]> CommitDate: 2026-08-18 08:11:12 +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 <[email protected]> Reviewed by: kbowling, erj, milosz.linkiewicz_intel.com Tested by: Mateusz Moga <[email protected]> MFC after: 1 week Sponsored by: Intel Corporation Differential Revision: https://reviews.freebsd.org/D57642 --- 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 25e7e9bdf913..6de2b40e1aee 100644 --- a/sys/dev/ixgbe/if_ix.c +++ b/sys/dev/ixgbe/if_ix.c @@ -1603,8 +1603,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 @@ -1653,10 +1654,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 */ @@ -1668,6 +1669,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);