linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2 -mm] mm: brk: fix unsigned compare against 0 issue
@ 2018-10-04 21:14 Yang Shi
  2018-10-04 21:14 ` [PATCH 2/2 -mm] mm: mremap: " Yang Shi
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Shi @ 2018-10-04 21:14 UTC (permalink / raw)
  To: vbabka, kirill.shutemov, mhocko, willy, ldufour, colin.king, akpm
  Cc: yang.shi, linux-mm, linux-kernel

Static analysis reported unsigned compare against 0 issue according to
Colin Ian King.

Defined an int temp variable to check the return value of __do_munmap().

Reported-by: Colin Ian King <colin.king@canonical.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
---
Andrew, this should be able to be folded into the original patch.

 mm/mmap.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 68dc4fb..c78f7e9 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -242,17 +242,18 @@ static int do_brk_flags(unsigned long addr, unsigned long request, unsigned long
 	 * __do_munmap() may downgrade mmap_sem to read.
 	 */
 	if (brk <= mm->brk) {
+		int ret;
 		/*
 		 * mm->brk need to be protected by write mmap_sem, update it
 		 * before downgrading mmap_sem.
 		 * When __do_munmap fail, it will be restored from origbrk.
 		 */
 		mm->brk = brk;
-		retval = __do_munmap(mm, newbrk, oldbrk-newbrk, &uf, true);
-		if (retval < 0) {
+		ret = __do_munmap(mm, newbrk, oldbrk-newbrk, &uf, true);
+		if (ret < 0) {
 			mm->brk = origbrk;
 			goto out;
-		} else if (retval == 1)
+		} else if (ret == 1)
 			downgraded = true;
 		goto success;
 	}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2 -mm] mm: mremap: fix unsigned compare against 0 issue
  2018-10-04 21:14 [PATCH 1/2 -mm] mm: brk: fix unsigned compare against 0 issue Yang Shi
@ 2018-10-04 21:14 ` Yang Shi
  0 siblings, 0 replies; 2+ messages in thread
From: Yang Shi @ 2018-10-04 21:14 UTC (permalink / raw)
  To: vbabka, kirill.shutemov, mhocko, willy, ldufour, colin.king, akpm
  Cc: yang.shi, linux-mm, linux-kernel

Static analysis reported unsigned compare against 0 issue according to
Colin Ian King.

Defined an int temp variable to check the return value of __do_munmap().

Reported-by: Colin Ian King <colin.king@canonical.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
---
Andrew, this should be able to be folded into the original patch.

 mm/mremap.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/mm/mremap.c b/mm/mremap.c
index 3524d16..f9d5d1f 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -566,12 +566,14 @@ static int vma_expandable(struct vm_area_struct *vma, unsigned long delta)
 	 * downgrade mmap_sem to read.
 	 */
 	if (old_len >= new_len) {
-		ret = __do_munmap(mm, addr+new_len, old_len - new_len,
+		int retval;
+		retval = __do_munmap(mm, addr+new_len, old_len - new_len,
 				  &uf_unmap, true);
-		if (ret < 0 && old_len != new_len)
+		if (retval < 0 && old_len != new_len) {
+			ret = retval;
 			goto out;
 		/* Returning 1 indicates mmap_sem is downgraded to read. */
-		else if (ret == 1)
+		} else if (retval == 1)
 			downgraded = true;
 		ret = addr;
 		goto out;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-04 21:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-04 21:14 [PATCH 1/2 -mm] mm: brk: fix unsigned compare against 0 issue Yang Shi
2018-10-04 21:14 ` [PATCH 2/2 -mm] mm: mremap: " Yang Shi

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).