Re: [PATCH v7 11/24] mm: Move end_index check out of readahead loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/21/20 7:35 AM, Matthew Wilcox wrote:
On Thu, Feb 20, 2020 at 07:50:39PM -0800, John Hubbard wrote:
This tiny patch made me pause, because I wasn't sure at first of the exact
intent of the lines above. Once I worked it out, it seemed like it might
be helpful (or overkill??) to add a few hints for the reader, especially since
there are no hints in the function's (minimal) documentation header. What
do you think of this?

	/*
	 * If we can't read *any* pages without going past the inodes's isize
	 * limit, give up entirely:
	 */
	if (index > end_index)
		return;

	/* Cap nr_to_read, in order to avoid overflowing the ULONG type: */
	if (index + nr_to_read < index)
		nr_to_read = ULONG_MAX - index + 1;

	/* Cap nr_to_read, to avoid reading past the inode's isize limit: */
	if (index + nr_to_read >= end_index)
		nr_to_read = end_index - index + 1;

A little verbose for my taste ... How about this?


Mine too, actually. :)  I think your version below looks good.


thanks,
--
John Hubbard
NVIDIA


         end_index = (isize - 1) >> PAGE_SHIFT;
         if (index > end_index)
                 return;
         /* Avoid wrapping to the beginning of the file */
         if (index + nr_to_read < index)
                 nr_to_read = ULONG_MAX - index + 1;
         /* Don't read past the page containing the last byte of the file */
         if (index + nr_to_read >= end_index)
                 nr_to_read = end_index - index + 1;





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux