We should release folios if the first entry was populated, but
loop failed before sg advanced (st->nents == 1 && sg == st->sgl).

Fixes: 957ad9a02be6 ("drm/i915/gem: Avoid iterating an empty list")
Cc: [email protected]
Assisted-by: GitHub Copilot:claude-opus-5
Signed-off-by: Krzysztof Karas <[email protected]>
---
v6:
 * added missing subject version prefix;
 * added fixes tag and CC to stable kernel;
 * extended commit message to contain exact failing condition;
 * ran final checks with Claude Opus and added a tag.

 drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c 
b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
index 8e5f2a7d5f6b..a84c804726d8 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
@@ -209,7 +209,7 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, 
struct sg_table *st,
        return 0;
 err_sg:
        sg_mark_end(sg);
-       if (sg != st->sgl) {
+       if (st->nents) {
                shmem_sg_free_table(st, mapping, false, false);
        } else {
                mapping_clear_unevictable(mapping);
-- 
2.34.1

Reply via email to