Re: [PATCH 5/7] fs: Calculate new position before validtiy check in lseek()

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

 



On Tue, Jan 22, 2019 at 05:13:36PM -0800, Andrey Smirnov wrote:
> Calculate new position before validtiy check in lseek() to simplify
> code a bit as well as make following commit simpler. This should be
> harmless thing to do, since we don't actually use calculated value
> unless it passes the validity check.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>
> ---
>  fs/fs.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/fs.c b/fs/fs.c
> index 6a62fb98b..9372b9981 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -421,21 +421,21 @@ loff_t lseek(int fildes, loff_t offset, int whence)
>  
>  	switch (whence) {
>  	case SEEK_SET:
> +		pos = offset;
>  		if (f->size != FILE_SIZE_STREAM && offset > f->size)
>  			goto out;
>  		if (IS_ERR_VALUE(offset))
>  			goto out;

This test looks quite unnecessary. Can we remove it? git blame points to
me of course, but I can't make any sense of it.

> -		pos = offset;
>  		break;
>  	case SEEK_CUR:
> -		if (f->size != FILE_SIZE_STREAM && offset + f->pos > f->size)
> -			goto out;
>  		pos = f->pos + offset;
> +		if (f->size != FILE_SIZE_STREAM && pos > f->size)
> +			goto out;
>  		break;
>  	case SEEK_END:
> +		pos = f->size + offset;
>  		if (offset > 0)
>  			goto out;
> -		pos = f->size + offset;

When starting to shift the validity checks around, can't we just do them
after the switch/case instead of in each branch?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux