From: Chen Wandun <chenwandun@huawei.com>
To: <hughd@google.com>, <akpm@linux-foundation.org>,
<linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
<willy@infradead.org>, <david@redhat.com>,
<wangkefeng.wang@huawei.com>
Subject: [PATCH v2 2/3] mm/shmem: return error code directly for invalid addr
Date: Sun, 5 Jun 2022 11:55:56 +0800 [thread overview]
Message-ID: <20220605035557.3957759-3-chenwandun@huawei.com> (raw)
In-Reply-To: <20220605035557.3957759-1-chenwandun@huawei.com>
Return error code directly for addr is not PAGE_SIZE aligned or
beyond TASK_SIZE, no need to check these cases in caller.
Signed-off-by: Chen Wandun <chenwandun@huawei.com>
---
mm/shmem.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mm/shmem.c b/mm/shmem.c
index 17f8297ece29..5e61692f2d8e 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2142,10 +2142,10 @@ unsigned long shmem_get_unmapped_area(struct file *file,
return addr;
if (IS_ERR_VALUE(addr))
return addr;
- if (addr & ~PAGE_MASK)
- return addr;
+ if (offset_in_page(addr))
+ return -EINVAL;
if (addr > TASK_SIZE - len)
- return addr;
+ return -ENOMEM;
if (shmem_huge == SHMEM_HUGE_DENY)
return addr;
@@ -2196,7 +2196,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
inflated_addr = get_area(NULL, uaddr, inflated_len, 0, flags);
if (IS_ERR_VALUE(inflated_addr))
return addr;
- if (inflated_addr & ~PAGE_MASK)
+ if (offset_in_page(inflated_addr))
return addr;
inflated_offset = inflated_addr & (HPAGE_PMD_SIZE-1);
--
2.25.1
next prev parent reply other threads:[~2022-06-05 3:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-05 3:55 [PATCH v2 0/3] a few cleanup and bugfixes about shmem Chen Wandun
2022-06-05 3:55 ` [PATCH v2 1/3] mm/shmem: check return value of shmem_init_inodecache Chen Wandun
2022-06-05 11:49 ` Matthew Wilcox
2022-06-06 1:34 ` Chen Wandun
2022-06-06 2:08 ` Matthew Wilcox
2022-06-06 2:58 ` Chen Wandun
2022-06-05 3:55 ` Chen Wandun [this message]
2022-06-05 3:55 ` [PATCH v2 3/3] mm/shmem: rework calculation of inflated_addr in shmem_get_unmapped_area Chen Wandun
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=20220605035557.3957759-3-chenwandun@huawei.com \
--to=chenwandun@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=wangkefeng.wang@huawei.com \
--cc=willy@infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).