Skip to contentSkip to conversation

x86/platform/uv: move kmalloc() NULL check routine

PATCH In review Austin Kim 3 participants 4 messages Sep 5, 2019 – Sep 6, 2019

Subsystems (3)
lore
Share & tools
lore

Austin Kim

author
#0 lore raw

PATCH 1/1 x86/platform/uv: move kmalloc() NULL check routine

The result of kmalloc should have been checked ahead of below statement:

	pqp = (struct bau_pq_entry *)vp;

Move BUG_ON(!vp) before above statement.

---
 arch/x86/platform/uv/tlb_uv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/platform/uv/tlb_uv.c +2 -2
index 20c389a..5f0a96bf 100644
@@ -1804,9 +1804,9 @@ static void pq_init(int node, int pnode)
 
 	plsize = (DEST_Q_SIZE + 1) * sizeof(struct bau_pq_entry);
 	vp = kmalloc_node(plsize, GFP_KERNEL, node);
-	pqp = (struct bau_pq_entry *)vp;
-	BUG_ON(!pqp);
+	BUG_ON(!vp);
 
+	pqp = (struct bau_pq_entry *)vp;
 	cp = (char *)pqp + 31;
 	pqp = (struct bau_pq_entry *)(((unsigned long)cp >> 5) << 5);
 
Signature · 1 line
2.6.2
#1 lore raw
Quoted 15 lines · Austin Kim

The result of kmalloc should have been checked ahead of below statement:

	pqp = (struct bau_pq_entry *)vp;

Move BUG_ON(!vp) before above statement.

---
 arch/x86/platform/uv/tlb_uv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/platform/uv/tlb_uv.c +0 -0
index 20c389a..5f0a96bf 100644

arch/x86/platform/uv/tlb_uv.c static void pq_init(int node, int pnode) · line 1807

Quoted 6 lines
arch/x86/platform/uv/tlb_uv.c +1 -2
@@ -1804,9 +1804,9 @@ static void pq_init(int node, int pnode)
 
 	plsize = (DEST_Q_SIZE + 1) * sizeof(struct bau_pq_entry);
 	vp = kmalloc_node(plsize, GFP_KERNEL, node);
-	pqp = (struct bau_pq_entry *)vp;
-	BUG_ON(!pqp);
+	BUG_ON(!vp);

Ick! Don't crash the whole machine if you are out of memory, that's a totally lazy and broken driver. Fix this up properly please.

But the original code is just fine (from a this is doing what I want it to do point of view), I don't see the need to change anything here, you did not modify any logic at all.

thanks,

greg k-h

#2 lore raw
Quoted 17 lines · Greg KH
Quoted 16 lines · Austin Kim

The result of kmalloc should have been checked ahead of below statement:

	pqp = (struct bau_pq_entry *)vp;

Move BUG_ON(!vp) before above statement.

---
 arch/x86/platform/uv/tlb_uv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/platform/uv/tlb_uv.c +0 -0
index 20c389a..5f0a96bf 100644
@@ -1804,9 +1804,9 @@ static void pq_init(int node, int pnode)
 
Quoted 8 lines

arch/x86/platform/uv/tlb_uv.c static void pq_init(int node, int pnode) · line 1807

Quoted 5 lines
arch/x86/platform/uv/tlb_uv.c +1 -2
 	plsize = (DEST_Q_SIZE + 1) * sizeof(struct bau_pq_entry);
 	vp = kmalloc_node(plsize, GFP_KERNEL, node);
-	pqp = (struct bau_pq_entry *)vp;
-	BUG_ON(!pqp);
+	BUG_ON(!vp);

Ick! Don't crash the whole machine if you are out of memory, that's a totally lazy and broken driver. Fix this up properly please.

This is boot time init; if memory allocation fails, we're in trouble, no way forward no way back.

It is not uncommon to have BUG_ON() for alloc failing during boot.

Quoted 3 lines

But the original code is just fine (from a this is doing what I want it to do point of view), I don't see the need to change anything here, you did not modify any logic at all.

Agreed, the patch seems entirely pointless.

#3 lore raw
Quoted 27 lines · Peter Zijlstra
Quoted 17 lines · Greg KH
Quoted 16 lines · Austin Kim

The result of kmalloc should have been checked ahead of below statement:

	pqp = (struct bau_pq_entry *)vp;

Move BUG_ON(!vp) before above statement.

---
 arch/x86/platform/uv/tlb_uv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/platform/uv/tlb_uv.c +0 -0
index 20c389a..5f0a96bf 100644
@@ -1804,9 +1804,9 @@ static void pq_init(int node, int pnode)
 
Quoted 8 lines

arch/x86/platform/uv/tlb_uv.c static void pq_init(int node, int pnode) · line 1807

Quoted 5 lines
arch/x86/platform/uv/tlb_uv.c +1 -2
 	plsize = (DEST_Q_SIZE + 1) * sizeof(struct bau_pq_entry);
 	vp = kmalloc_node(plsize, GFP_KERNEL, node);
-	pqp = (struct bau_pq_entry *)vp;
-	BUG_ON(!pqp);
+	BUG_ON(!vp);

Ick! Don't crash the whole machine if you are out of memory, that's a totally lazy and broken driver. Fix this up properly please.

Quoted 4 lines

This is boot time init; if memory allocation fails, we're in trouble, no way forward no way back.

It is not uncommon to have BUG_ON() for alloc failing during boot.

Hey, how come you get to get away with this here, and in the tty layer I had to do all sorts of foolish things just for the same "impossible" thing because syzbot found a way to emulate such lunacy?

Just you wait until the fuzzers get ahold of this code... :)

greg k-h