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 Liu X-Patchwork-Id: 111305 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 04C7DB6F65 for ; Wed, 24 Aug 2011 20:48:53 +1000 (EST) Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QwB0O-0005Se-QZ; Wed, 24 Aug 2011 10:48:21 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QwB0O-0001Iw-2k; Wed, 24 Aug 2011 10:48:20 +0000 Received: from ch1ehsobe002.messaging.microsoft.com ([216.32.181.182] helo=ch1outboundpool.messaging.microsoft.com) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QwB03-0001Fv-87; Wed, 24 Aug 2011 10:47:59 +0000 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: 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 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110824_064759_351821_256CD08A X-CRM114-Status: GOOD ( 14.70 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [216.32.181.182 listed in list.dnswl.org] Cc: dedekind1@gmail.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, patches@linaro.org, David.Woodhouse@intel.com X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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) {