From: Roel Kluin <roel.kluin@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: wli@holomorphy.com, linux-kernel@vger.kernel.org
Subject: [PATCH v2] hugetlb: unsigned ret cannot be negative.
Date: Tue, 02 Dec 2008 23:51:06 +0100 [thread overview]
Message-ID: <4935BBDA.1020404@gmail.com> (raw)
In-Reply-To: <20081202140223.7d5f3538.akpm@linux-foundation.org>
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;
next prev parent reply other threads:[~2008-12-02 22:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Roel Kluin [this message]
2008-12-03 8:35 ` [PATCH v2] " Andrew Morton
2008-12-03 8:35 ` Andrew Morton
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=4935BBDA.1020404@gmail.com \
--to=roel.kluin@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wli@holomorphy.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.