]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cifs: Fix copy_to_iter return value check
authorFushuai Wang <wangfushuai@baidu.com>
Tue, 7 Oct 2025 08:26:03 +0000 (16:26 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 19 Oct 2025 14:33:43 +0000 (16:33 +0200)
[ Upstream commit 0cc380d0e1d36b8f2703379890e90f896f68e9e8 ]

The return value of copy_to_iter() function will never be negative,
it is the number of bytes copied, or zero if nothing was copied.
Update the check to treat 0 as an error, and return -1 in that case.

Fixes: d08089f649a0 ("cifs: Change the I/O paths to use an iterator rather than a page list")
Acked-by: Tom Talpey <tom@talpey.com>
Reviewed-by: David Howells <dhowells@redhat.com>
Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/smb/client/smb2ops.c

index c946c3a09245c66f1dd2459013e74ee8998e7684..1b30035d02bc51aac917194232b9edf151003399 100644 (file)
@@ -4657,7 +4657,7 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
        unsigned int pad_len;
        struct cifs_io_subrequest *rdata = mid->callback_data;
        struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
-       int length;
+       size_t copied;
        bool use_rdma_mr = false;
 
        if (shdr->Command != SMB2_READ) {
@@ -4770,10 +4770,10 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
        } else if (buf_len >= data_offset + data_len) {
                /* read response payload is in buf */
                WARN_ONCE(buffer, "read data can be either in buf or in buffer");
-               length = copy_to_iter(buf + data_offset, data_len, &rdata->subreq.io_iter);
-               if (length < 0)
-                       return length;
-               rdata->got_bytes = data_len;
+               copied = copy_to_iter(buf + data_offset, data_len, &rdata->subreq.io_iter);
+               if (copied == 0)
+                       return -EIO;
+               rdata->got_bytes = copied;
        } else {
                /* read response payload cannot be in both buf and pages */
                WARN_ONCE(1, "buf can not contain only a part of read data");