linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: fix null pointer deference when kzalloc returns null
@ 2015-07-17 10:37 Colin King
  2015-08-19  0:58 ` Brian Norris
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2015-07-17 10:37 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, Aaron Sierra, Ard Biesheuvel,
	Fabian Frederick, Joe Schultz, linux-mtd
  Cc: linux-kernel

From: Colin Ian King <colin.king@canonical.com>

static analysis by smatch caught the following error:

drivers/mtd/maps/physmap_of.c:135 of_get_probes()
   error: potential null dereference 'res'.  (kzalloc returns null)

Check for failed kzalloc and return -ENOMEM in of_flash_probe if
this occurs.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/mtd/maps/physmap_of.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index 774b32f..3e614e9 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -130,6 +130,8 @@ static const char * const *of_get_probes(struct device_node *dp)
 			count++;
 
 	res = kzalloc((count + 1)*sizeof(*res), GFP_KERNEL);
+	if (!res)
+		return NULL;
 	count = 0;
 	while (cplen > 0) {
 		res[count] = cp;
@@ -311,6 +313,10 @@ static int of_flash_probe(struct platform_device *dev)
 
 	ppdata.of_node = dp;
 	part_probe_types = of_get_probes(dp);
+	if (!part_probe_types) {
+		err = -ENOMEM;
+		goto err_out;
+	}
 	mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata,
 			NULL, 0);
 	of_free_probes(part_probe_types);
-- 
2.1.4


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

* Re: [PATCH] mtd: fix null pointer deference when kzalloc returns null
  2015-07-17 10:37 [PATCH] mtd: fix null pointer deference when kzalloc returns null Colin King
@ 2015-08-19  0:58 ` Brian Norris
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Norris @ 2015-08-19  0:58 UTC (permalink / raw)
  To: Colin King
  Cc: David Woodhouse, Aaron Sierra, Ard Biesheuvel, Fabian Frederick,
	Joe Schultz, linux-mtd, linux-kernel

On Fri, Jul 17, 2015 at 11:37:52AM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> static analysis by smatch caught the following error:
> 
> drivers/mtd/maps/physmap_of.c:135 of_get_probes()
>    error: potential null dereference 'res'.  (kzalloc returns null)
> 
> Check for failed kzalloc and return -ENOMEM in of_flash_probe if
> this occurs.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Pushed to l2-mtd.git

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

end of thread, other threads:[~2015-08-19  0:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-17 10:37 [PATCH] mtd: fix null pointer deference when kzalloc returns null Colin King
2015-08-19  0:58 ` Brian Norris

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