Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1798416ybl; Sun, 18 Aug 2019 10:41:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYBU4Z/2E6UF6QXHHovaJcNHOFaFw4svhgazu/K8oRdvHR8E3fPt17Db3bwusXXBIIkGU2 X-Received: by 2002:a63:b46:: with SMTP id a6mr16819765pgl.235.1566150070955; Sun, 18 Aug 2019 10:41:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566150070; cv=none; d=google.com; s=arc-20160816; b=sEHu95RCuZxU9VfxC/CohoTxnYc49kms9Evatn9QgQg+IOJNdCYTb7m9KXqQJdNin1 NXs47XCJ8P6TVKe83RISzd3a6FqVOiviUlfOR2Ru4VtBizGQ/MfQgEOKlIDtlWfsV0aQ aXa9Tub1nUgGqjY5Mfum+/B8OgcsXIeyqu1POe24G61lDMoAtDbjS9WgOwzIOhW/EnkR khWTXS5lV8tVtH/jReZSZMoxB4ClOSrQgl3XcS5Mkh360D/kNpOmtstuNE7Clw+Zg7AJ JEExbAdSNA68uosR2vA7RYhX46b8iDcbjXzFamSGvdOc/yokxPQd3ebWnagFWsUnwzMt ufiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=xRA6A3IpkVXBsZQsDundHQBjGso3fPaNrTm4wSuFb2I=; b=nzCYV5L2gGXcFgMSzf5fdE7Q5U44VIgX1wdn7f2zbF3bpbhyeI+3wQI0PDfv+KjNV7 MOf3ynSYankS8NdHs1uZsZcZl+ezbB9aiZlCPyoLnLDYtFkAO3JoDP2Tb+L3Ah/6yNO0 FyCKY/fBWborn2W8SeDfcyKuhwCt207CucxDjvUuzI90ljuvggTMr3Aj0VGKTkvutCc2 ClhweSd3UeLaufPpB9o1rlu3fyeZwS3cM1vWYX1Vr8wSVAd4koPakEEhkrfVryM9bjZ+ nK7iHnvM8nAOjSzrCue8n5xnwzaZf4Uf+JGF8jr8qa9ohDmzk1V1jRTtzFJWTNIjjuT1 qz7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p11si7262533pjr.3.2019.08.18.10.40.54; Sun, 18 Aug 2019 10:41:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726608AbfHRRj7 (ORCPT + 99 others); Sun, 18 Aug 2019 13:39:59 -0400 Received: from mail-yb1-f193.google.com ([209.85.219.193]:43019 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726005AbfHRRj7 (ORCPT ); Sun, 18 Aug 2019 13:39:59 -0400 Received: by mail-yb1-f193.google.com with SMTP id o82so3586053ybg.10 for ; Sun, 18 Aug 2019 10:39:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xRA6A3IpkVXBsZQsDundHQBjGso3fPaNrTm4wSuFb2I=; b=uU0J1dSdSR7wvFsgN5du50NOA4Kv2eLMyfQlPiwjTiLDsbSNMF19nVD/lgvsYSf6uM BcUf0wMSytjl1VQChOOHjxbSuZYtALfBWKObQbedeb24oCoodGERIx2Zsg1S0CBYqJUz ngiSG+eUkLSESsH0G+Uktchz56ORLNWg0TWNvULzdBtcvkG75XRlWEkj9bH+S6TATQLg CXIVL1iaUeV+G5bdjaEY6G1fjNTeL6+TKGMYu7eePwuv2ITVYzrZXJtsfUFyeJXmwD+J 4FNP81tTTQAW+DuD6NfssmmDo5PTqMHC0EgPV1wa0wcalMhf/nUfm6M2f0Ncor9tlkCH Ko/g== X-Gm-Message-State: APjAAAWYKSQq7wo2jFtbMiuYb80yJfualV5iC/i7Ah0Z1DZu4voIY4Bp iRQc0o/HJWjBFjVXqwlGb8c= X-Received: by 2002:a25:782:: with SMTP id 124mr14756624ybh.106.1566149998215; Sun, 18 Aug 2019 10:39:58 -0700 (PDT) Received: from localhost.localdomain (24-158-240-219.dhcp.smyr.ga.charter.com. [24.158.240.219]) by smtp.gmail.com with ESMTPSA id d81sm254314ywe.59.2019.08.18.10.39.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Aug 2019 10:39:57 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Marek Vasut , Tudor Ambarus , David Woodhouse , Brian Norris , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org (open list:SPI NOR SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] mtd: spi-nor: fix a memory leak bug Date: Sun, 18 Aug 2019 12:39:53 -0500 Message-Id: <1566149993-2748-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In spi_nor_parse_4bait(), 'dwords' is allocated through kmalloc(). However, it is not deallocated in the following execution if spi_nor_read_sfdp() fails, leading to a memory leak. To fix this issue, free 'dwords' before returning the error. Signed-off-by: Wenwen Wang --- drivers/mtd/spi-nor/spi-nor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 03cc788..a41a466 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -3453,7 +3453,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor, addr = SFDP_PARAM_HEADER_PTP(param_header); ret = spi_nor_read_sfdp(nor, addr, len, dwords); if (ret) - return ret; + goto out; /* Fix endianness of the 4BAIT DWORDs. */ for (i = 0; i < SFDP_4BAIT_DWORD_MAX; i++) -- 2.7.4