Skip to contentSkip to conversation

mm: brk: fix unsigned compare against 0 issue

PATCH New Yang Shi 1 participant 2 messages Oct 4, 2018

Subsystems (2)
lore
Share & tools
lore

Yang Shi

author
#0 lore raw

PATCH 1/2 mm: brk: fix unsigned compare against 0 issue

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

Cc Vlastimil Babka <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Laurent Dufour <[email protected]>
Cc Andrew Morton <[email protected]>

---
Andrew, this should be able to be folded into the original patch.

 mm/mmap.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
mm/mmap.c +4 -3
index 68dc4fb..c78f7e9 100644
@@ -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;
 	}
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/2 mm: mremap: fix unsigned compare against 0 issue

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

Cc Vlastimil Babka <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Laurent Dufour <[email protected]>
Cc Andrew Morton <[email protected]>

---
Andrew, this should be able to be folded into the original patch.

 mm/mremap.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
mm/mremap.c +5 -3
index 3524d16..f9d5d1f 100644
@@ -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;
Signature · 1 line
1.8.3.1