mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chen Wandun <chenwandun@huawei.com>
To: <hughd@google.com>, <akpm@linux-foundation.org>,
	<linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>
Cc: <chenwandun@huawei.com>
Subject: [PATCH 4/4] mm/shmem: rework calculation of inflated_addr in shmem_get_unmapped_area
Date: Wed, 1 Jun 2022 20:44:17 +0800	[thread overview]
Message-ID: <20220601124417.2872001-5-chenwandun@huawei.com> (raw)
In-Reply-To: <20220601124417.2872001-1-chenwandun@huawei.com>

In function shmem_get_unmapped_area, inflated_offset and offset
are unsigned long, it will result in underflow when offset below
inflated_offset, a little confusing, no functional change.

Signed-off-by: Chen Wandun <chenwandun@huawei.com>
---
 mm/shmem.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index ca04f3975a8a..f12163bd0f69 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2201,9 +2201,12 @@ unsigned long shmem_get_unmapped_area(struct file *file,
 		return addr;
 
 	inflated_offset = inflated_addr & (HPAGE_PMD_SIZE-1);
-	inflated_addr += offset - inflated_offset;
-	if (inflated_offset > offset)
+	if (offset > inflated_offset)
+		inflated_addr += offset - inflated_offset;
+	else if (offset < inflated_offset) {
+		inflated_addr -= inflated_offset - offset;
 		inflated_addr += HPAGE_PMD_SIZE;
+	}
 
 	if (inflated_addr > TASK_SIZE - len)
 		return addr;
-- 
2.25.1


      parent reply	other threads:[~2022-06-01 12:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01 12:44 [PATCH 0/4] a few cleanup and bugfixes about shmem Chen Wandun
2022-06-01 12:44 ` [PATCH 1/4] mm/shmem: check return value of shmem_init_inodecache Chen Wandun
2022-06-01 12:54   ` Matthew Wilcox
2022-06-01 13:34     ` Kefeng Wang
2022-06-01 12:44 ` [PATCH 2/4] mm/shmem: return -EINVAL for addr not PAGE_SIZE aligned Chen Wandun
2022-06-01 13:37   ` David Hildenbrand
2022-06-01 14:14     ` David Hildenbrand
2022-06-05  2:05       ` Chen Wandun
2022-06-01 12:44 ` [PATCH 3/4] mm/shmem: return error code directly Chen Wandun
2022-06-01 12:44 ` Chen Wandun [this message]

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=20220601124417.2872001-5-chenwandun@huawei.com \
    --to=chenwandun@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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

all inboxes | Powered by JetHome®