From patchwork Wed Aug 24 11:26:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Hui X-Patchwork-Id: 3650 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 30C6623F4D for ; Wed, 24 Aug 2011 11:24:40 +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 0D1ADA18011 for ; Wed, 24 Aug 2011 11:24:40 +0000 (UTC) Received: by bkbzs2 with SMTP id zs2so1241142bkb.11 for ; Wed, 24 Aug 2011 04:24:39 -0700 (PDT) Received: by 10.204.133.215 with SMTP id g23mr2290508bkt.70.1314185079622; Wed, 24 Aug 2011 04:24:39 -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 n11cs9744bke; Wed, 24 Aug 2011 04:24:39 -0700 (PDT) Received: by 10.52.188.68 with SMTP id fy4mr5110676vdc.91.1314185078140; Wed, 24 Aug 2011 04:24:38 -0700 (PDT) Received: from TX2EHSOBE001.bigfish.com (tx2ehsobe001.messaging.microsoft.com [65.55.88.11]) by mx.google.com with ESMTPS id f15si789798vcw.129.2011.08.24.04.24.37 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Aug 2011 04:24:38 -0700 (PDT) Received-SPF: neutral (google.com: 65.55.88.11 is neither permitted nor denied by best guess record for domain of jason.hui@linaro.org) client-ip=65.55.88.11; Authentication-Results: mx.google.com; spf=neutral (google.com: 65.55.88.11 is neither permitted nor denied by best guess record for domain of jason.hui@linaro.org) smtp.mail=jason.hui@linaro.org Received: from mail14-tx2-R.bigfish.com (10.9.14.252) by TX2EHSOBE001.bigfish.com (10.9.40.21) with Microsoft SMTP Server id 14.1.225.22; Wed, 24 Aug 2011 11:24:37 +0000 Received: from mail14-tx2 (localhost.localdomain [127.0.0.1]) by mail14-tx2-R.bigfish.com (Postfix) with ESMTP id 16B24628298; Wed, 24 Aug 2011 11:24:37 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bh8275dhz2dh87h2a8h668h839h64h) X-Spam-TCS-SCL: 3: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 mail14-tx2 (localhost.localdomain [127.0.0.1]) by mail14-tx2 (MessageSwitch) id 1314185038862990_28377; Wed, 24 Aug 2011 11:23:58 +0000 (UTC) Received: from TX2EHSMHS031.bigfish.com (unknown [10.9.14.246]) by mail14-tx2.bigfish.com (Postfix) with ESMTP id E610DDB8064; Wed, 24 Aug 2011 11:21:27 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS031.bigfish.com (10.9.99.131) with Microsoft SMTP Server (TLS) id 14.1.225.22; Wed, 24 Aug 2011 11:21:16 +0000 Received: from az33smr02.freescale.net (10.64.34.200) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server id 14.1.323.2; Wed, 24 Aug 2011 06:21:16 -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 p7OBLDIk028472; Wed, 24 Aug 2011 06:21:14 -0500 (CDT) From: Jason Liu To: CC: , , , , Subject: [[PATCH v2] mtd: check parts pointer before using it Date: Wed, 24 Aug 2011 19:26:28 +0800 Message-ID: <1314185188-6151-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. and we also need check the real_parts to make sure kmemdup allocation sucessfully. Signed-off-by: Jason Liu Cc: Dmitry Eremin-Solenikov Cc: Artem Bityutskiy --- V2: Fix one error condition check and add real_parts check too. --- This patch is based on git://git.infradead.org/users/dedekind/l2-mtd-2.6.git --- drivers/mtd/mtdcore.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 09bdbac..b01993e 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -465,12 +465,13 @@ 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) + if (!real_parts) err = -ENOMEM; + else + err = nr_parts; } if (err > 0) {