Skip to contentSkip to conversation

mm: hugetlb -- get rid of redundant if operation

PATCH In review Cyrill Gorcunov 2 participants 7 messages Jan 2, 2009 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#2 lore raw

PATCH 2/3 mm: hugetlb -- get rid of redundant if operation

In reply to a message not in the archive

At this point we already know that 'addr' is not NULL so get rid of redundant 'if'. Probably gcc eliminate it by optimization pass.

---
 mm/hugetlb.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/hugetlb.c +1 -2
Index: linux-2.6.git/mm/hugetlb.c
===================================================================
@@ -991,8 +991,7 @@ __attribute__((weak)) int alloc_bootmem_
 			 * puts them into the mem_map).
 			 */
 			m = addr;
-			if (m)
-				goto found;
+			goto found;
 		}
 		hstate_next_node(h);
 		nr_nodes--;
#1 lore raw

PATCH 1/3 early_printk - use sizeof instead of hardcoded number

In reply to a message not in the archive

Impact: cleanup

---
 arch/x86/kernel/early_printk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/early_printk.c +1 -1
Index: linux-2.6.git/arch/x86/kernel/early_printk.c
===================================================================
@@ -886,7 +886,7 @@ asmlinkage void early_printk(const char 
 	va_list ap;
 
 	va_start(ap, fmt);
-	n = vscnprintf(buf, 512, fmt, ap);
+	n = vscnprintf(buf, sizeof(buf), fmt, ap);
 	early_console->write(early_console, buf, n);
 	va_end(ap);
 }
#4 lore raw

PATCH 3/3 acpi: check for pxm_to_node_map overflow

In reply to a message not in the archive

It is hardly (if ever) possible but in case of broken _PXM entry we could reach out of pxm_to_node_map array bounds in acpi_map_pxm_to_node() call. Lets check it (it's not that expensive and safe).

---
 drivers/acpi/numa.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/numa.c +1 -1
Index: linux-2.6.git/drivers/acpi/numa.c
===================================================================
@@ -278,7 +278,7 @@ int acpi_get_node(acpi_handle *handle)
 	int pxm, node = -1;
 
 	pxm = acpi_get_pxm(handle);
-	if (pxm >= 0)
+	if (pxm >= 0 && pxm < MAX_PXM_DOMAINS)
 		node = acpi_map_pxm_to_node(pxm);
 
 	return node;
Reviewed-by on v1 2/3
#3 lore raw
In reply to Cyrill Gorcunov

Andrew Cc:-ed.

patch looks correct to me.

Ingo

Quoted 26 lines · Cyrill Gorcunov

At this point we already know that 'addr' is not NULL so get rid of redundant 'if'. Probably gcc eliminate it by optimization pass.

---
 mm/hugetlb.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Index: linux-2.6.git/mm/hugetlb.c
===================================================================

mm/hugetlb.c +1 -2
@@ -991,8 +991,7 @@ __attribute__((weak)) int alloc_bootmem_
 			 * puts them into the mem_map).
 			 */
 			m = addr;
-			if (m)
-				goto found;
+			goto found;
 		}
 		hstate_next_node(h);
 		nr_nodes--;
Signature · 1 line
-- 
#5 lore raw

Re: [patch 3/3] acpi: check for pxm_to_node_map overflow

In reply to Cyrill Gorcunov
Quoted 10 lines · Cyrill Gorcunov

It is hardly (if ever) possible but in case of broken _PXM entry we could reach out of pxm_to_node_map array bounds in acpi_map_pxm_to_node() call. Lets check it (it's not that expensive and safe).

---
 drivers/acpi/numa.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

just curious - how did you find this - code review or some tool help like Sparse output or a compiler warning?

Ingo

#6 lore raw

Re: [patch 3/3] acpi: check for pxm_to_node_map overflow

[Ingo Molnar - Fri, Jan 02, 2009 at 10:23:30AM +0100]

| 
| * Cyrill Gorcunov <[email protected]> wrote:
| 
| > It is hardly (if ever) possible but in case of broken _PXM
| > entry we could reach out of pxm_to_node_map array
| > bounds in acpi_map_pxm_to_node() call. Lets check it
| > (it's not that expensive and safe).
| > 
| > Signed-off-by: Cyrill Gorcunov <[email protected]>
| > CC: Len Brown <[email protected]>
| > ---
| >  drivers/acpi/numa.c |    2 +-
| >  1 file changed, 1 insertion(+), 1 deletion(-)
| 
| just curious - how did you find this - code review or some tool help like 
| Sparse output or a compiler warning?
| 
| 	Ingo
| 

Unfortunately -- by reading the code :( I would prefer if gcc or sparse complain about it but we have indirect referring which is that hard to trace by any tool I believe (until say some emulator but even if we have such kind of tool we would need to tell it that 'there we have boundries we shouldn't cross)'. But to be fair -- I didn't try sparse here maybe it does complain :)

- Cyrill -

#7 lore raw

Re: [patch 3/3] acpi: check for pxm_to_node_map overflow

In reply to Cyrill Gorcunov

[Cyrill Gorcunov - Fri, Jan 02, 2009 at 11:27:20AM +0300]

| It is hardly (if ever) possible but in case of broken _PXM
| entry we could reach out of pxm_to_node_map array
| bounds in acpi_map_pxm_to_node() call. Lets check it
| (it's not that expensive and safe).
| 
| Signed-off-by: Cyrill Gorcunov <[email protected]>
| CC: Len Brown <[email protected]>

...

Oops, I forgot to CC Andi, sorry.

- Cyrill -