Page MenuHomeFreeBSD

linuxkpi: Fix return value of dma_map_sgtable

Authored by on Dec 6 2022, 5:23 AM.
Referenced Files
F88319629: D37611.diff
Sat, Jul 13, 7:13 PM
Unknown Object (File)
Sat, Jul 6, 10:51 AM
Unknown Object (File)
Apr 30 2024, 4:57 AM
Unknown Object (File)
Apr 27 2024, 5:37 PM
Unknown Object (File)
Apr 27 2024, 5:37 PM
Unknown Object (File)
Apr 27 2024, 4:20 PM
Unknown Object (File)
Apr 22 2024, 12:29 PM
Unknown Object (File)
Apr 22 2024, 10:38 AM



dma_map_sgtable internally uses the dma_map_sg_attrs helper. The problem is
that dma_map_sg_attrs returns the number of entries mapped, whereas
dma_map_sgtable returns nonzero on failure. This leads to dma_map_sgtable
returning non-zero-but-positive values which tricks other areas of the stack
into thinking nents is a valid pointer.

This checks if nents is valid and returns zero if so, updating the nents field
in sgt. This fixes PRIME render offload with nvidia-drm

Test Plan

PRIME rendering offload with i915kms and nvidia-drm

Diff Detail

rG FreeBSD src repository
Lint Passed
No Test Coverage
Build Status
Buildable 48620
Build 45506: arc lint + arc unit

Event Timeline

Here's the github PR handling this for older versions before we moved this function into base:

This revision is now accepted and ready to land.Dec 6 2022, 3:25 PM
bz added a subscriber: bz.

Functionally looks fine; style may be improved (or not).


Normally I'd say separate declaration:

int nents;

nents = ...

() around return values here and below.


No need for the else clause so all the {} {} can go for both.

Closing this since it was already submitted in 4085bde9fa2e