Skip to content

Commit 3ac1d42

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
iomap: remove the length variable in iomap_seek_data
The length variable is rather pointless given that it can be trivially deduced from offset and size. Also the initial calculation can lead to KASAN warnings. Signed-off-by: Christoph Hellwig <[email protected]> Reported-by: Leizhen (ThunderTown) <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Matthew Wilcox (Oracle) <[email protected]>
1 parent e73f0f0 commit 3ac1d42

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

fs/iomap/seek.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,23 @@ loff_t
8383
iomap_seek_data(struct inode *inode, loff_t offset, const struct iomap_ops *ops)
8484
{
8585
loff_t size = i_size_read(inode);
86-
loff_t length = size - offset;
8786
loff_t ret;
8887

8988
/* Nothing to be found before or beyond the end of the file. */
9089
if (offset < 0 || offset >= size)
9190
return -ENXIO;
9291

93-
while (length > 0) {
94-
ret = iomap_apply(inode, offset, length, IOMAP_REPORT, ops,
95-
&offset, iomap_seek_data_actor);
92+
while (offset < size) {
93+
ret = iomap_apply(inode, offset, size - offset, IOMAP_REPORT,
94+
ops, &offset, iomap_seek_data_actor);
9695
if (ret < 0)
9796
return ret;
9897
if (ret == 0)
99-
break;
100-
98+
return offset;
10199
offset += ret;
102-
length -= ret;
103100
}
104101

105-
if (length <= 0)
106-
return -ENXIO;
107-
return offset;
102+
/* We've reached the end of the file without finding data */
103+
return -ENXIO;
108104
}
109105
EXPORT_SYMBOL_GPL(iomap_seek_data);

0 commit comments

Comments
 (0)