public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tile: add null check for kzalloc in tile/kernel/setup.c
@ 2013-08-22  1:48 Wang Sheng-Hui
  2013-08-29 18:02 ` Chris Metcalf
  0 siblings, 1 reply; 2+ messages in thread
From: Wang Sheng-Hui @ 2013-08-22  1:48 UTC (permalink / raw)
  To: Chris Metcalf, Andrew Morton, Paul Gortmaker, linux-kernel


Should check the return value of kzalloc first to avoid the null pointer.
Then can dereference the non-null pointer to access the fields of struct resource.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
---
 arch/tile/kernel/setup.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c
index eceb834..7d4138c 100644
--- a/arch/tile/kernel/setup.c
+++ b/arch/tile/kernel/setup.c
@@ -1548,6 +1548,8 @@ insert_non_bus_resource(void)
 {
 	struct resource *res =
 		kzalloc(sizeof(struct resource), GFP_ATOMIC);
+	if (!res)
+		return NULL;
 	res->name = "Non-Bus Physical Address Space";
 	res->start = (1ULL << 32);
 	res->end = -1LL;
@@ -1565,6 +1567,8 @@ insert_ram_resource(u64 start_pfn, u64 end_pfn)
 {
 	struct resource *res =
 		kzalloc(sizeof(struct resource), GFP_ATOMIC);
+	if (!res)
+		return NULL;
 	res->name = "System RAM";
 	res->start = start_pfn << PAGE_SHIFT;
 	res->end = (end_pfn << PAGE_SHIFT) - 1;
-- 
1.7.10.4

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

* Re: [PATCH] tile: add null check for kzalloc in tile/kernel/setup.c
  2013-08-22  1:48 [PATCH] tile: add null check for kzalloc in tile/kernel/setup.c Wang Sheng-Hui
@ 2013-08-29 18:02 ` Chris Metcalf
  0 siblings, 0 replies; 2+ messages in thread
From: Chris Metcalf @ 2013-08-29 18:02 UTC (permalink / raw)
  To: Wang Sheng-Hui; +Cc: Andrew Morton, Paul Gortmaker, linux-kernel

On 8/21/2013 9:49 PM, Wang Sheng-Hui wrote:
> Should check the return value of kzalloc first to avoid the null pointer.
> Then can dereference the non-null pointer to access the fields of struct resource.
> 
> Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
> ---
>  arch/tile/kernel/setup.c |    4 ++++
>  1 file changed, 4 insertions(+)

Thanks.  Taken into the tile tree.
-- 
Chris Metcalf, Tilera Corp.
http://www.tilera.com

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

end of thread, other threads:[~2013-08-29 18:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-22  1:48 [PATCH] tile: add null check for kzalloc in tile/kernel/setup.c Wang Sheng-Hui
2013-08-29 18:02 ` Chris Metcalf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox