Skip to content

Commit 6fa6c7a

Browse files
Taotao ChenAndi Shyti
authored andcommitted
drm/i915: Fix incorrect error handling in shmem_pwrite()
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
1 parent e296a22 commit 6fa6c7a

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

drivers/gpu/drm/i915/gem/i915_gem_shmem.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,20 @@ shmem_pwrite(struct drm_i915_gem_object *obj,
441441
written = file->f_op->write_iter(&kiocb, &iter);
442442
BUG_ON(written == -EIOCBQUEUED);
443443

444-
if (written != size)
445-
return -EIO;
446-
444+
/*
445+
* First, check if write_iter returned a negative error.
446+
* If the write failed, return the real error code immediately.
447+
* This prevents it from being overwritten by the short write check below.
448+
*/
447449
if (written < 0)
448450
return written;
451+
/*
452+
* Check for a short write (written bytes != requested size).
453+
* Even if some data was written, return -EIO to indicate that the
454+
* write was not fully completed.
455+
*/
456+
if (written != size)
457+
return -EIO;
449458

450459
return 0;
451460
}

0 commit comments

Comments
 (0)