mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH 4/7] fs: Change error checking logic for fsdrv->lseek() call
Date: Thu, 24 Jan 2019 11:19:12 -0800	[thread overview]
Message-ID: <CAHQ1cqEnoOgLZsMXM7U7X7h55G0nHy5o3dZUn8HZ31fESK3hfQ@mail.gmail.com> (raw)
In-Reply-To: <20190124074450.f3wykwn42qqqcfrz@pengutronix.de>

On Wed, Jan 23, 2019 at 11:44 PM Sascha Hauer <s.hauer@pengutronix.de> wrote:
>
> On Tue, Jan 22, 2019 at 05:13:35PM -0800, Andrey Smirnov wrote:
> > On 32-bit systems, cheking for IS_ERR_VALUE(pos) is not
> > correct. Expanding that code we get (loff_t cast is added for clarity):
> >
> >  (loff_t)pos >= (unsigned long)-MAX_ERRNO
> >
> > given that loff_t is a 64-bit signed value, any perfectly valid seek
> > offset that is greater than 0xffffc000 will result in false
> > positive. Change the logic to check if position returned by
> > fsdrv->lseek() is what's been requested. If it is, we can assume that
> > operation was succesfull. If not, that's likely means failure and
> > return value is a negative error code.
> >
> > This should accomodate both 32-bit systems, where we /dev/mem doesn't
> > present any range problems, as well as 64-bit systems where both file
> > offset and size of /dev/mem couldn't really be correctly captured by
> > loff_t and we have to rely on 2's complement and overflow.
> >
> > Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> > ---
> >  fs/fs.c | 13 +++++--------
> >  1 file changed, 5 insertions(+), 8 deletions(-)
> >
> > diff --git a/fs/fs.c b/fs/fs.c
> > index a304bf186..6a62fb98b 100644
> > --- a/fs/fs.c
> > +++ b/fs/fs.c
> > @@ -405,8 +405,7 @@ loff_t lseek(int fildes, loff_t offset, int whence)
> >  {
> >       struct fs_driver_d *fsdrv;
> >       FILE *f;
> > -     loff_t pos;
> > -     int ret;
> > +     loff_t pos, ret;
> >
> >       if (check_fd(fildes))
> >               return -1;
> > @@ -442,13 +441,11 @@ loff_t lseek(int fildes, loff_t offset, int whence)
> >               goto out;
> >       }
> >
> > -     pos = fsdrv->lseek(&f->fsdev->dev, f, pos);
> > -     if (IS_ERR_VALUE(pos)) {
> > -             errno = -pos;
> > -             return -1;
> > -     }
> > +     ret = fsdrv->lseek(&f->fsdev->dev, f, pos);
> > +     if (ret != pos)
> > +             goto out;
>
> There's no point in returning the current position from fsdrv->lseek
> when the desired position is already an input parameter. I think we
> should change the prototype of fsdrv->lseek to just return an error code.
>

OK, sure, will do in v2.

Thanks,
Andrey Smirnov

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

  reply	other threads:[~2019-01-24 19:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-23  1:13 [PATCH 0/7] 32-bit lseek and /dev/mem fixes/improvements Andrey Smirnov
2019-01-23  1:13 ` [PATCH 1/7] commands: Move mem_parse_options() to lib/misc.c Andrey Smirnov
2019-01-23  1:13 ` [PATCH 2/7] commands: Get rid of mem_rw_buf Andrey Smirnov
2019-01-23  1:13 ` [PATCH 3/7] commands: Move /dev/mem driver to drivers/misc Andrey Smirnov
2019-01-23  1:13 ` [PATCH 4/7] fs: Change error checking logic for fsdrv->lseek() call Andrey Smirnov
2019-01-24  7:44   ` Sascha Hauer
2019-01-24 19:19     ` Andrey Smirnov [this message]
2019-01-23  1:13 ` [PATCH 5/7] fs: Calculate new position before validtiy check in lseek() Andrey Smirnov
2019-01-24  7:52   ` Sascha Hauer
2019-01-24 19:37     ` Andrey Smirnov
2019-01-23  1:13 ` [PATCH 6/7] fs: Add support for files larger than MAX_LFS_FILESIZE Andrey Smirnov
2019-01-24  8:48   ` Sascha Hauer
2019-01-24 19:43     ` Andrey Smirnov
2019-01-23  1:13 ` [PATCH 7/7] misc: mem: Set correct size for /dev/mem Andrey Smirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHQ1cqEnoOgLZsMXM7U7X7h55G0nHy5o3dZUn8HZ31fESK3hfQ@mail.gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox