From: Andi Shyti <andi.shyti@kernel.org>
To: intel-gfx <intel-gfx@lists.freedesktop.org>
Cc: Andi Shyti <andi.shyti@linux.intel.com>,
Taotao Chen <chentaotao@didiglobal.com>
Subject: [CI 2/2] drm/i915: Fix incorrect error handling in shmem_pwrite()
Date: Tue, 16 Sep 2025 15:09:56 +0200 [thread overview]
Message-ID: <20250916130956.3913547-3-andi.shyti@kernel.org> (raw)
In-Reply-To: <20250916130956.3913547-1-andi.shyti@kernel.org>
From: Taotao Chen <chentaotao@didiglobal.com>
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>
Link: https://lore.kernel.org/r/20250822030651.28099-2-chentaotao@didiglobal.com
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
---
drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
index b9dae15c1d16..26dda55a07ff 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
@@ -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;
}
--
2.50.1
next prev parent reply other threads:[~2025-09-16 13:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-16 13:09 [CI 0/2] Some shmem fixes Andi Shyti
2025-09-16 13:09 ` [CI 1/2] drm/i915: set O_LARGEFILE in __create_shmem() Andi Shyti
2025-09-16 13:09 ` Andi Shyti [this message]
2025-09-16 14:25 ` ✓ i915.CI.BAT: success for Some shmem fixes Patchwork
2025-09-16 18:33 ` ✗ i915.CI.Full: failure " Patchwork
2025-09-16 23:20 ` ✗ i915.CI.BAT: failure for Some shmem fixes (rev2) Patchwork
2025-09-17 12:46 ` ✓ i915.CI.BAT: success for Some shmem fixes (rev3) Patchwork
2025-09-17 14:02 ` ✗ i915.CI.Full: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250916130956.3913547-3-andi.shyti@kernel.org \
--to=andi.shyti@kernel.org \
--cc=andi.shyti@linux.intel.com \
--cc=chentaotao@didiglobal.com \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox