Skip to content

Commit 11fa977

Browse files
Hugh Dickinstorvalds
authored andcommitted
generic_file_aio_read() cleanups
As akpm points out, there's really no need for generic_file_aio_read to make a special case of count 0: just loop through nr_segs doing nothing. And as Harvey Harrison points out, there's no need to reset retval to 0 where it's already 0. Setting count (or ocount) to 0 before calling generic_segment_checks is unnecessary too; but reluctantly I'll leave that removal to someone with a wider range of gcc versions to hand - 4.1.2 and 4.2.1 don't warn about it, but perhaps others do - I forget which are the warniest versions. Signed-off-by: Hugh Dickins <hugh@veritas.com> Tested-by: Lawrence Greenfield <leg@google.com> Cc: Christoph Rohland <hans-christoph.rohland@sap.com> Cc: Badari Pulavarty <pbadari@us.ibm.com> Cc: Zach Brown <zach.brown@oracle.com> Cc: Nick Piggin <nickpiggin@yahoo.com.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a858f7b commit 11fa977

1 file changed

Lines changed: 19 additions & 23 deletions

File tree

‎mm/filemap.c‎

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,6 @@ generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
11971197

11981198
mapping = filp->f_mapping;
11991199
inode = mapping->host;
1200-
retval = 0;
12011200
if (!count)
12021201
goto out; /* skip atime */
12031202
size = i_size_read(inode);
@@ -1209,33 +1208,30 @@ generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
12091208
}
12101209
if (retval > 0)
12111210
*ppos = pos + retval;
1212-
}
1213-
if (likely(retval != 0)) {
1214-
file_accessed(filp);
1215-
goto out;
1211+
if (retval) {
1212+
file_accessed(filp);
1213+
goto out;
1214+
}
12161215
}
12171216
}
12181217

1219-
retval = 0;
1220-
if (count) {
1221-
for (seg = 0; seg < nr_segs; seg++) {
1222-
read_descriptor_t desc;
1218+
for (seg = 0; seg < nr_segs; seg++) {
1219+
read_descriptor_t desc;
12231220

1224-
desc.written = 0;
1225-
desc.arg.buf = iov[seg].iov_base;
1226-
desc.count = iov[seg].iov_len;
1227-
if (desc.count == 0)
1228-
continue;
1229-
desc.error = 0;
1230-
do_generic_file_read(filp,ppos,&desc,file_read_actor);
1231-
retval += desc.written;
1232-
if (desc.error) {
1233-
retval = retval ?: desc.error;
1234-
break;
1235-
}
1236-
if (desc.count > 0)
1237-
break;
1221+
desc.written = 0;
1222+
desc.arg.buf = iov[seg].iov_base;
1223+
desc.count = iov[seg].iov_len;
1224+
if (desc.count == 0)
1225+
continue;
1226+
desc.error = 0;
1227+
do_generic_file_read(filp, ppos, &desc, file_read_actor);
1228+
retval += desc.written;
1229+
if (desc.error) {
1230+
retval = retval ?: desc.error;
1231+
break;
12381232
}
1233+
if (desc.count > 0)
1234+
break;
12391235
}
12401236
out:
12411237
return retval;

0 commit comments

Comments
 (0)