linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] resource: Add NULL check in next_resource
@ 2014-09-21 15:51 Guenter Roeck
  2014-09-22 14:57 ` Vivek Goyal
  2014-09-22 14:58 ` Vivek Goyal
  0 siblings, 2 replies; 5+ messages in thread
From: Guenter Roeck @ 2014-09-21 15:51 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Mikael Starvik, Jesper Nilsson, linux-kernel, Guenter Roeck,
	Vivek Goyal

Commit 8c86e70acead ("resource: provide new functions to walk through
resources") adds a suble new requirement that iomem_resource.child must
not be NULL when walk_system_ram_range is called. This can cause a crash
if it turns out that there are no children. The crash ('Unable to handle
kernel NULL pointer dereference') is seen when trying to test a crisv32
image on kernels with this commit applied.

Fix by adding a NULL check into next_resource().

Fixes: 8c86e70acead ("resource: provide new functions to walk through resources")
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
The NULL check could be added elsewhere instead. I am open to suggestions.

 kernel/resource.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/resource.c b/kernel/resource.c
index 60c5a38..00c57ad 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -61,6 +61,9 @@ static DEFINE_SPINLOCK(bootmem_resource_lock);
 
 static struct resource *next_resource(struct resource *p, bool sibling_only)
 {
+	if (p == NULL)
+		return NULL;
+
 	/* Caller wants to traverse through siblings only */
 	if (sibling_only)
 		return p->sibling;
-- 
1.9.1


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

end of thread, other threads:[~2014-09-22 15:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-21 15:51 [PATCH] resource: Add NULL check in next_resource Guenter Roeck
2014-09-22 14:57 ` Vivek Goyal
2014-09-22 15:36   ` Guenter Roeck
2014-09-22 14:58 ` Vivek Goyal
2014-09-22 15:46   ` Guenter Roeck

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