Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1945918AbbGQKii (ORCPT ); Fri, 17 Jul 2015 06:38:38 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:44842 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422655AbbGQKig (ORCPT ); Fri, 17 Jul 2015 06:38:36 -0400 From: Colin King To: David Woodhouse , Brian Norris , Aaron Sierra , Ard Biesheuvel , Fabian Frederick , Joe Schultz , linux-mtd@lists.infradead.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] mtd: fix null pointer deference when kzalloc returns null Date: Fri, 17 Jul 2015 11:37:52 +0100 Message-Id: <1437129472-13099-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1434 Lines: 47 From: Colin Ian King 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 --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/