From patchwork Wed Aug 24 10:53:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Hui X-Patchwork-Id: 3648 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5196D23E54 for ; Wed, 24 Aug 2011 10:47:58 +0000 (UTC) Received: from mail-bw0-f52.google.com (mail-bw0-f52.google.com [209.85.214.52]) by fiordland.canonical.com (Postfix) with ESMTP id 3881AA1803C for ; Wed, 24 Aug 2011 10:47:58 +0000 (UTC) Received: by bkbzs2 with SMTP id zs2so1210873bkb.11 for ; Wed, 24 Aug 2011 03:47:58 -0700 (PDT) Received: by 10.204.143.82 with SMTP id t18mr2196788bku.174.1314182877772; Wed, 24 Aug 2011 03:47:57 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.204.41.75 with SMTP id n11cs8973bke; Wed, 24 Aug 2011 03:47:57 -0700 (PDT) Received: by 10.229.25.68 with SMTP id y4mr3434248qcb.24.1314182876147; Wed, 24 Aug 2011 03:47:56 -0700 (PDT) Received: from ch1outboundpool.messaging.microsoft.com (ch1ehsobe005.messaging.microsoft.com [216.32.181.185]) by mx.google.com with ESMTPS id x3si514822qcy.191.2011.08.24.03.47.55 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Aug 2011 03:47:56 -0700 (PDT) Received-SPF: neutral (google.com: 216.32.181.185 is neither permitted nor denied by best guess record for domain of jason.hui@linaro.org) client-ip=216.32.181.185; Authentication-Results: mx.google.com; spf=neutral (google.com: 216.32.181.185 is neither permitted nor denied by best guess record for domain of jason.hui@linaro.org) smtp.mail=jason.hui@linaro.org Received: from mail141-ch1-R.bigfish.com (216.32.181.172) by CH1EHSOBE015.bigfish.com (10.43.70.65) with Microsoft SMTP Server id 14.1.225.22; Wed, 24 Aug 2011 10:47:55 +0000 Received: from mail141-ch1 (localhost.localdomain [127.0.0.1]) by mail141-ch1-R.bigfish.com (Postfix) with ESMTP id 523AF16B01DB; Wed, 24 Aug 2011 10:47:55 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bh8275dhz2dh87h2a8h668h839h62h) X-Spam-TCS-SCL: 1:0 X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPVD:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-FB-DOMAIN-IP-MATCH: fail Received: from mail141-ch1 (localhost.localdomain [127.0.0.1]) by mail141-ch1 (MessageSwitch) id 131418287527535_21028; Wed, 24 Aug 2011 10:47:55 +0000 (UTC) Received: from CH1EHSMHS021.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.246]) by mail141-ch1.bigfish.com (Postfix) with ESMTP id 0206C55804B; Wed, 24 Aug 2011 10:47:55 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS021.bigfish.com (10.43.70.21) with Microsoft SMTP Server (TLS) id 14.1.225.22; Wed, 24 Aug 2011 10:47:51 +0000 Received: from az33smr02.freescale.net (10.64.34.200) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server id 14.1.323.2; Wed, 24 Aug 2011 05:47:50 -0500 Received: from r64343-desktop.ap.freescale.net (r64343-desktop.ap.freescale.net [10.192.242.36]) by az33smr02.freescale.net (8.13.1/8.13.0) with ESMTP id p7OAllsv014300; Wed, 24 Aug 2011 05:47:48 -0500 (CDT) From: Jason Liu To: CC: , , , , Subject: [PATCH] mtd: check parts pointer before using it Date: Wed, 24 Aug 2011 18:53:01 +0800 Message-ID: <1314183181-4197-1-git-send-email-jason.hui@linaro.org> X-Mailer: git-send-email 1.7.4.1 MIME-Version: 1.0 X-OriginatorOrg: sigmatel.com The code has the check for parts but it called after kmemdup, kmemdup(parts, sizeof(*parts) * nr_parts,...) if (!parts) return -ENOMEM In fact, we need check parts before safely using it. Signed-off-by: Jason Liu Cc: Dmitry Eremin-Solenikov Cc: Artem Bityutskiy --- This patch is based on git://git.infradead.org/users/dedekind/l2-mtd-2.6.git --- drivers/mtd/mtdcore.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 09bdbac..ce59ff5 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -465,12 +465,10 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char **types, struct mtd_partition *real_parts; err = parse_mtd_partitions(mtd, types, &real_parts, parser_data); - if (err <= 0 && nr_parts) { + if (err <= 0 && nr_parts && !parts) { real_parts = kmemdup(parts, sizeof(*parts) * nr_parts, GFP_KERNEL); err = nr_parts; - if (!parts) - err = -ENOMEM; } if (err > 0) {