Skip to content

Commit 0cc380d

Browse files
Fushuai Wangsmfrench
authored andcommitted
cifs: Fix copy_to_iter return value check
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: d08089f ("cifs: Change the I/O paths to use an iterator rather than a page list") Acked-by: Tom Talpey <[email protected]> Reviewed-by: David Howells <[email protected]> Signed-off-by: Fushuai Wang <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 68d2e2c commit 0cc380d

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

fs/smb/client/smb2ops.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4736,7 +4736,7 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
47364736
unsigned int pad_len;
47374737
struct cifs_io_subrequest *rdata = mid->callback_data;
47384738
struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4739-
int length;
4739+
size_t copied;
47404740
bool use_rdma_mr = false;
47414741

47424742
if (shdr->Command != SMB2_READ) {
@@ -4849,10 +4849,10 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
48494849
} else if (buf_len >= data_offset + data_len) {
48504850
/* read response payload is in buf */
48514851
WARN_ONCE(buffer, "read data can be either in buf or in buffer");
4852-
length = copy_to_iter(buf + data_offset, data_len, &rdata->subreq.io_iter);
4853-
if (length < 0)
4854-
return length;
4855-
rdata->got_bytes = data_len;
4852+
copied = copy_to_iter(buf + data_offset, data_len, &rdata->subreq.io_iter);
4853+
if (copied == 0)
4854+
return -EIO;
4855+
rdata->got_bytes = copied;
48564856
} else {
48574857
/* read response payload cannot be in both buf and pages */
48584858
WARN_ONCE(1, "buf can not contain only a part of read data");

0 commit comments

Comments
 (0)