From patchwork Fri Jul 12 02:06:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?546L5a6H6Iiq?= X-Patchwork-Id: 258678 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 94E772C0339 for ; Fri, 12 Jul 2013 12:07:55 +1000 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UxSlV-0000Th-1L; Fri, 12 Jul 2013 02:07:21 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UxSlT-0006O0-4f; Fri, 12 Jul 2013 02:07:19 +0000 Received: from mail-ob0-x22e.google.com ([2607:f8b0:4003:c01::22e]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UxSlM-0006NI-LY for linux-mtd@lists.infradead.org; Fri, 12 Jul 2013 02:07:13 +0000 Received: by mail-ob0-f174.google.com with SMTP id wd20so10709881obb.5 for ; Thu, 11 Jul 2013 19:06:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=KFctJMGH6AL6EM0cMP52srDFGGLNqimLG38J6uZSjR0=; b=AkCEkIFyD/ZtSej3J8CVCrA9a81C51ti6LIloQdJ6MELT8f4VUsLmW5UaDsR/T8jQW plDhct8lXgDtcMA9p9mMRsIuzijaCMXouUJKz+2FdXNhtVIwSk3+qsJCl+1dLVNyqG2j 7kbr6MfIyFpUk2k6d6I9KQFh7T17/TCesmKBePBxbQ/vLYrTtNiIT9xexVktFxXFHRf+ 3khCPqAS+nCbcSvV57DG4mH4HYdVrBnaHqy26HKOAVIPRgZiuqKF95ORsQZVurIt5N6q 3FIW00zuDXqg8RzfTOuO/zKpM8G1zuxBTLL/l1H3/4J0CGPgXSmAvE0b58HNSyHfgyHA 32Aw== MIME-Version: 1.0 X-Received: by 10.60.125.100 with SMTP id mp4mr34155795oeb.60.1373594810927; Thu, 11 Jul 2013 19:06:50 -0700 (PDT) Received: by 10.182.73.170 with HTTP; Thu, 11 Jul 2013 19:06:50 -0700 (PDT) Date: Fri, 12 Jul 2013 10:06:50 +0800 Message-ID: Subject: M25p80 little bug From: yuhang wang To: artem.bityutskiy@linux.intel.com, marex@denx.de, wfp5p@virginia.edu, swarren@nvidia.com, linux-mtd@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130711_220712_772603_EADA3D27 X-CRM114-Status: GOOD ( 11.58 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (wangyuhang2014[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (wangyuhang2014[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Hi, There seems two bugs in m25p80 driver. 1: The position to kmalloc flash->command seems incorrect. Because flash->fast_read is not set. 2: There is no place to free flash if error occur in probe. From 4c9c1fc03b5a953b0a95f543de1fbdfc62f28b42 Mon Sep 17 00:00:00 2001 From: wangyuhang Date: Wed, 10 Jul 2013 16:58:17 +0800 Subject: [PATCH] m25p80 bug Signed-off-by: wangyuhang Signed-off-by: wangyuhang --- drivers/mtd/devices/m25p80.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) -- 1.7.9.5 diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 5b6b072..6bb9e2b 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -901,7 +901,7 @@ static int m25p_probe(struct spi_device *spi) struct flash_platform_data *data; struct m25p *flash; struct flash_info *info; - unsigned i; + unsigned i,ret; struct mtd_part_parser_data ppdata; struct device_node __maybe_unused *np = spi->dev.of_node; @@ -958,13 +958,7 @@ static int m25p_probe(struct spi_device *spi) flash = kzalloc(sizeof *flash, GFP_KERNEL); if (!flash) return -ENOMEM; - flash->command = kmalloc(MAX_CMD_SIZE + (flash->fast_read ? 1 : 0), - GFP_KERNEL); - if (!flash->command) { - kfree(flash); - return -ENOMEM; - } - + flash->spi = spi; mutex_init(&flash->lock); dev_set_drvdata(&spi->dev, flash); @@ -1031,7 +1025,12 @@ static int m25p_probe(struct spi_device *spi) #ifdef CONFIG_M25PXX_USE_FAST_READ flash->fast_read = true; #endif - + flash->command = kmalloc(MAX_CMD_SIZE + (flash->fast_read ? 1 : 0), + GFP_KERNEL); + if (!flash->command) { + kfree(flash); + return -ENOMEM; + } if (info->addr_width) flash->addr_width = info->addr_width; else { @@ -1067,9 +1066,14 @@ static int m25p_probe(struct spi_device *spi) /* partitions should match sector boundaries; and it may be good to * use readonly partitions for writeprotected sectors (BP2..BP0). */ - return mtd_device_parse_register(&flash->mtd, NULL, &ppdata, + ret = mtd_device_parse_register(&flash->mtd, NULL, &ppdata, data ? data->parts : NULL, data ? data->nr_parts : 0); + if (ret) { + kfree(flash->command); + kfree(flash); + } + return ret; }