From patchwork Tue Jul 16 06:20:56 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: 259356 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (casper.infradead.org [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 1198E2C018A for ; Tue, 16 Jul 2013 16:22:52 +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 1Uyyeh-0002Sv-Oi; Tue, 16 Jul 2013 06:22:36 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uyyef-0001cZ-Vw; Tue, 16 Jul 2013 06:22:33 +0000 Received: from mail-pb0-x22f.google.com ([2607:f8b0:400e:c01::22f]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uyyed-0001cE-Ea for linux-mtd@lists.infradead.org; Tue, 16 Jul 2013 06:22:32 +0000 Received: by mail-pb0-f47.google.com with SMTP id rr13so336331pbb.6 for ; Mon, 15 Jul 2013 23:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=s1hSufIq9GaUmfXtFPwD2q2t2S6rEFIg20JeEwK1GVc=; b=Q5niRLzudkdCnTiHtq42eL+ch3100Knz4LOrzAI/Ne9vr/43jNgjyCZ7qEroxE7494 rVg9ZFAevpLquerpcWQQVSmtKJZhveaLcVc073CkwSV/+U+CxeTBLFQhOHPtjEIdwDAe UO3kZ0VXoFWW93cnkXPGWv5WTwdOyjsu7aitQvjHdC5gqwSLXShdzw2+PPOcVva61ERG HJDt2Nj3QTwrSY3IZ5CZjmMoeodJBei8iE0M2S5cjef790ckdVwKr7ecjymWOCruyBeL MMbgh7YTn6QkiX/SBwrkRjWsDncwCE0SceiPqJcSIeQRM+UdtzJ5fXoSMErM/LrawOI2 pN8A== X-Received: by 10.68.226.7 with SMTP id ro7mr47100915pbc.72.1373955727530; Mon, 15 Jul 2013 23:22:07 -0700 (PDT) Received: from localhost.localdomain ([218.24.172.134]) by mx.google.com with ESMTPSA id fl2sm2256623pab.23.2013.07.15.23.22.05 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 15 Jul 2013 23:22:06 -0700 (PDT) From: wangyuhang To: marex@denx.de, linux-mtd@lists.infradead.org Subject: [PATCH] m25p80: fix the malloc space without being freed when probe failed Date: Tue, 16 Jul 2013 14:20:56 +0800 Message-Id: <1373955657-10363-1-git-send-email-wangyuhang2014@gmail.com> X-Mailer: git-send-email 1.7.9.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130716_022231_563225_F356C036 X-CRM114-Status: GOOD ( 10.60 ) 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 Cc: wangyuhang 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: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org space allocated can not be freed when probe failed, So we use devm_kzalloc() to instead of kzalloc(). flash->fast_read is used without being initialized, here move it to the certain position. Signed-off-by: wangyuhang --- drivers/mtd/devices/m25p80.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 5b6b072..70f3c54 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -955,15 +955,9 @@ static int m25p_probe(struct spi_device *spi) } } - flash = kzalloc(sizeof *flash, GFP_KERNEL); + flash = devm_kzalloc(&spi->dev, 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); @@ -1032,6 +1026,11 @@ static int m25p_probe(struct spi_device *spi) flash->fast_read = true; #endif + flash->command = devm_kzalloc(&spi->dev, + MAX_CMD_SIZE + (flash->fast_read ? 1 : 0), GFP_KERNEL); + if (!flash->command) + return -ENOMEM; + if (info->addr_width) flash->addr_width = info->addr_width; else {