* [PATCH] hugetlb: unsigned ret cannot be negative. @ 2008-11-29 11:36 roel kluin 2008-12-02 22:02 ` Andrew Morton 0 siblings, 1 reply; 4+ messages in thread From: roel kluin @ 2008-11-29 11:36 UTC (permalink / raw) To: wli; +Cc: linux-kernel unsigned long ret cannot be negative, but ret can get -EFAULT. Signed-off-by: Roel Kluin <roel.kluin@gmail.com> --- hugetlbfs_read_actor() returns int, see vi fs/hugetlbfs/inode.c +187 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 61edc70..0af64e4 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -252,6 +252,7 @@ static ssize_t hugetlbfs_read(struct file *filp, char __user *buf, for (;;) { struct page *page; unsigned long nr, ret; + int ra; /* nr is the maximum number of bytes to copy from this page */ nr = huge_page_size(h); @@ -279,15 +280,16 @@ static ssize_t hugetlbfs_read(struct file *filp, char __user *buf, /* * We have the page, copy it to user space buffer. */ - ret = hugetlbfs_read_actor(page, offset, buf, len, nr); + ra = hugetlbfs_read_actor(page, offset, buf, len, nr); } - if (ret < 0) { + if (ra < 0) { if (retval == 0) - retval = ret; + retval = ra; if (page) page_cache_release(page); goto out; } + ret = ra; offset += ret; retval += ret; ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hugetlb: unsigned ret cannot be negative. 2008-11-29 11:36 [PATCH] hugetlb: unsigned ret cannot be negative roel kluin @ 2008-12-02 22:02 ` Andrew Morton 2008-12-02 22:51 ` [PATCH v2] " Roel Kluin 0 siblings, 1 reply; 4+ messages in thread From: Andrew Morton @ 2008-12-02 22:02 UTC (permalink / raw) To: roel kluin; +Cc: wli, linux-kernel On Sat, 29 Nov 2008 06:36:59 -0500 roel kluin <roel.kluin@gmail.com> wrote: > unsigned long ret cannot be negative, but ret can get -EFAULT. > > Signed-off-by: Roel Kluin <roel.kluin@gmail.com> > --- > hugetlbfs_read_actor() returns int, > see > vi fs/hugetlbfs/inode.c +187 > > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > index 61edc70..0af64e4 100644 > --- a/fs/hugetlbfs/inode.c > +++ b/fs/hugetlbfs/inode.c > @@ -252,6 +252,7 @@ static ssize_t hugetlbfs_read(struct file *filp, char __user *buf, > for (;;) { > struct page *page; > unsigned long nr, ret; > + int ra; > > /* nr is the maximum number of bytes to copy from this page */ > nr = huge_page_size(h); > @@ -279,15 +280,16 @@ static ssize_t hugetlbfs_read(struct file *filp, char __user *buf, > /* > * We have the page, copy it to user space buffer. > */ > - ret = hugetlbfs_read_actor(page, offset, buf, len, nr); > + ra = hugetlbfs_read_actor(page, offset, buf, len, nr); > } > - if (ret < 0) { > + if (ra < 0) { > if (retval == 0) > - retval = ret; > + retval = ra; > if (page) > page_cache_release(page); > goto out; > } > + ret = ra; > > offset += ret; > retval += ret; `ra' can obviously be used uninitialised here. The compiler reports this, too. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] hugetlb: unsigned ret cannot be negative. 2008-12-02 22:02 ` Andrew Morton @ 2008-12-02 22:51 ` Roel Kluin 2008-12-03 8:35 ` Andrew Morton 0 siblings, 1 reply; 4+ messages in thread From: Roel Kluin @ 2008-12-02 22:51 UTC (permalink / raw) To: Andrew Morton; +Cc: wli, linux-kernel Andrew Morton wrote: > On Sat, 29 Nov 2008 06:36:59 -0500 > roel kluin <roel.kluin@gmail.com> wrote: > >> unsigned long ret cannot be negative, but ret can get -EFAULT. >> >> Signed-off-by: Roel Kluin <roel.kluin@gmail.com> >> --- >> hugetlbfs_read_actor() returns int, >> see >> vi fs/hugetlbfs/inode.c +187 >> >> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c >> index 61edc70..0af64e4 100644 >> --- a/fs/hugetlbfs/inode.c >> +++ b/fs/hugetlbfs/inode.c >> @@ -252,6 +252,7 @@ static ssize_t hugetlbfs_read(struct file *filp, char __user *buf, >> for (;;) { >> struct page *page; >> unsigned long nr, ret; >> + int ra; >> >> /* nr is the maximum number of bytes to copy from this page */ >> nr = huge_page_size(h); >> @@ -279,15 +280,16 @@ static ssize_t hugetlbfs_read(struct file *filp, char __user *buf, >> /* >> * We have the page, copy it to user space buffer. >> */ >> - ret = hugetlbfs_read_actor(page, offset, buf, len, nr); >> + ra = hugetlbfs_read_actor(page, offset, buf, len, nr); >> } >> - if (ret < 0) { >> + if (ra < 0) { > `ra' can obviously be used uninitialised here. The compiler reports > this, too. Yes, it was incomplete as well, sorry. This should be OK. (checkpatch tested) --------------->8----------------8<--------------------- unsigned long ret cannot be negative, but ret can get -EFAULT. Signed-off-by: Roel Kluin <roel.kluin@gmail.com> --- diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 61edc70..07fa7e3 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -252,6 +252,7 @@ static ssize_t hugetlbfs_read(struct file *filp, char __user *buf, for (;;) { struct page *page; unsigned long nr, ret; + int ra; /* nr is the maximum number of bytes to copy from this page */ nr = huge_page_size(h); @@ -274,16 +275,19 @@ static ssize_t hugetlbfs_read(struct file *filp, char __user *buf, */ ret = len < nr ? len : nr; if (clear_user(buf, ret)) - ret = -EFAULT; + ra = -EFAULT; + else + ra = 0; } else { /* * We have the page, copy it to user space buffer. */ - ret = hugetlbfs_read_actor(page, offset, buf, len, nr); + ra = hugetlbfs_read_actor(page, offset, buf, len, nr); + ret = ra; } - if (ret < 0) { + if (ra < 0) { if (retval == 0) - retval = ret; + retval = ra; if (page) page_cache_release(page); goto out; ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] hugetlb: unsigned ret cannot be negative. 2008-12-02 22:51 ` [PATCH v2] " Roel Kluin @ 2008-12-03 8:35 ` Andrew Morton 0 siblings, 0 replies; 4+ messages in thread From: Andrew Morton @ 2008-12-03 8:35 UTC (permalink / raw) To: Roel Kluin; +Cc: wli, linux-kernel, linux-mm On Tue, 02 Dec 2008 23:51:06 +0100 Roel Kluin <roel.kluin@gmail.com> wrote: > Andrew Morton wrote: > > On Sat, 29 Nov 2008 06:36:59 -0500 > > roel kluin <roel.kluin@gmail.com> wrote: > > > >> unsigned long ret cannot be negative, but ret can get -EFAULT. > >> > >> Signed-off-by: Roel Kluin <roel.kluin@gmail.com> > >> --- > >> hugetlbfs_read_actor() returns int, > >> see > >> vi fs/hugetlbfs/inode.c +187 > >> > >> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > >> index 61edc70..0af64e4 100644 > >> --- a/fs/hugetlbfs/inode.c > >> +++ b/fs/hugetlbfs/inode.c > >> @@ -252,6 +252,7 @@ static ssize_t hugetlbfs_read(struct file *filp, char __user *buf, > >> for (;;) { > >> struct page *page; > >> unsigned long nr, ret; > >> + int ra; > >> > >> /* nr is the maximum number of bytes to copy from this page */ > >> nr = huge_page_size(h); > >> @@ -279,15 +280,16 @@ static ssize_t hugetlbfs_read(struct file *filp, char __user *buf, > >> /* > >> * We have the page, copy it to user space buffer. > >> */ > >> - ret = hugetlbfs_read_actor(page, offset, buf, len, nr); > >> + ra = hugetlbfs_read_actor(page, offset, buf, len, nr); > >> } > >> - if (ret < 0) { > >> + if (ra < 0) { > > > `ra' can obviously be used uninitialised here. The compiler reports > > this, too. > > Yes, it was incomplete as well, sorry. This should be OK. > (checkpatch tested) > --------------->8----------------8<--------------------- > unsigned long ret cannot be negative, but ret can get -EFAULT. > > Signed-off-by: Roel Kluin <roel.kluin@gmail.com> > --- > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > index 61edc70..07fa7e3 100644 > --- a/fs/hugetlbfs/inode.c > +++ b/fs/hugetlbfs/inode.c > @@ -252,6 +252,7 @@ static ssize_t hugetlbfs_read(struct file *filp, char __user *buf, > for (;;) { > struct page *page; > unsigned long nr, ret; > + int ra; > > /* nr is the maximum number of bytes to copy from this page */ > nr = huge_page_size(h); > @@ -274,16 +275,19 @@ static ssize_t hugetlbfs_read(struct file *filp, char __user *buf, > */ > ret = len < nr ? len : nr; > if (clear_user(buf, ret)) > - ret = -EFAULT; > + ra = -EFAULT; > + else > + ra = 0; > } else { > /* > * We have the page, copy it to user space buffer. > */ > - ret = hugetlbfs_read_actor(page, offset, buf, len, nr); > + ra = hugetlbfs_read_actor(page, offset, buf, len, nr); > + ret = ra; > } > - if (ret < 0) { > + if (ra < 0) { > if (retval == 0) > - retval = ret; > + retval = ra; > if (page) > page_cache_release(page); > goto out; Looks like it'll work, I think. That function is pretty sad-looking now. It has `ra', `ret' and `retval', all rather confusingly. After being renamed to something useful, `ret' should have type size_t, hugetlbfs_read_actor() should return size_t and the whole logic around these three things needs a can of drano tipped down it. Oh well. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-12-03 8:35 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-11-29 11:36 [PATCH] hugetlb: unsigned ret cannot be negative roel kluin 2008-12-02 22:02 ` Andrew Morton 2008-12-02 22:51 ` [PATCH v2] " Roel Kluin 2008-12-03 8:35 ` Andrew Morton
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox