]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/i915: Fix incorrect error handling in shmem_pwrite()
authorTaotao Chen <chentaotao@didiglobal.com>
Fri, 22 Aug 2025 03:07:04 +0000 (03:07 +0000)
committerAndi Shyti <andi.shyti@linux.intel.com>
Thu, 18 Sep 2025 10:57:07 +0000 (12:57 +0200)
shmem_pwrite() currently checks for short writes before negative error
codes, which can overwrite real errors (e.g., -EFBIG) with -EIO.
Reorder the checks to return negative errors first, then handle short
writes.

Signed-off-by: Taotao Chen <chentaotao@didiglobal.com>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
Link: https://lore.kernel.org/r/20250822030651.28099-2-chentaotao@didiglobal.com
drivers/gpu/drm/i915/gem/i915_gem_shmem.c

index b9dae15c1d16679a83ee17cdfe8a98204a045536..26dda55a07ff41b610794486d3af6deec73874a5 100644 (file)
@@ -441,11 +441,20 @@ shmem_pwrite(struct drm_i915_gem_object *obj,
        written = file->f_op->write_iter(&kiocb, &iter);
        BUG_ON(written == -EIOCBQUEUED);
 
-       if (written != size)
-               return -EIO;
-
+       /*
+        * First, check if write_iter returned a negative error.
+        * If the write failed, return the real error code immediately.
+        * This prevents it from being overwritten by the short write check below.
+        */
        if (written < 0)
                return written;
+       /*
+        * Check for a short write (written bytes != requested size).
+        * Even if some data was written, return -EIO to indicate that the
+        * write was not fully completed.
+        */
+       if (written != size)
+               return -EIO;
 
        return 0;
 }