Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2986451ybl; Mon, 19 Aug 2019 10:18:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqysekvKmE2q+rTMDY7/5lkcf7WAefAoGynVY0r/zKBuatijGxxfdgiGRkiqjoNJALYut9ym X-Received: by 2002:a17:90a:ab0d:: with SMTP id m13mr20891784pjq.84.1566235115322; Mon, 19 Aug 2019 10:18:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566235115; cv=none; d=google.com; s=arc-20160816; b=yldO852gJD/e+xmZiwg6X1u/c0rR9b2qoDeG61NYrOarNehXgqm0/Z/ONHJDABvWAy yuE7/chU/nuggN0jRE/+flLcCjdXFJ+yxgFKF84/XGXgy6jGtgbzjheNJY6Xu4WALfb4 arcH/nTMxEmTlxIVqVVh3rMk91+MdyOFFKHSBFc8HrFT6TSViUWJkygHnHBR4SJylmnG m7HTyrgnKb5Wu6jbeMfpj2LvswM/tA9JQ6JXlX+O9PAr+X2/vW6T6AvzioDglbir5yAT RRPzQgfoQzwLuZLeYlywZN2BnazUBKLJS/oUNVMM3EPyp9AspF8dPl9NIa4bqxgmanbf Tnyw== 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=TMs535P7xxFLiQOk7wJAthNZTpkgqr1nBQtH4nH/Y58=; b=a/jZgh3/1M5PWyCT8069J+mpV1zevvc45KSvJ7pELYfhAssVyX4qxS8d3CHB+AFnsH Ob5JV3j0txClan2L5Jf1sKd5rjsJ1ufdFAqGoui1kVWdojbC0cfhQtPrFUVQS8A56qi9 5Ey271T2Ts4clVvHiDzd3W/Hi1T2rbvyGGXn2R6jv4hdN589vFvXEmk0PduM0NgEegK3 kiJ3WhiGp5TzSsiOrlPom1kunvdemkdJMxr70gVj7rUIpdHJ7vGsbk57RDj35mb4Dl1d +5DNxUPyPife1ey7A2Iurd3G2v4o32JcviejvgSho0tyJJ89ZvLZNvCWPLM86P19DVND xOrw== 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 em12si9188217pjb.25.2019.08.19.10.18.19; Mon, 19 Aug 2019 10:18:35 -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 S1727835AbfHSRQL (ORCPT + 99 others); Mon, 19 Aug 2019 13:16:11 -0400 Received: from mail-yb1-f194.google.com ([209.85.219.194]:43508 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727356AbfHSRQL (ORCPT ); Mon, 19 Aug 2019 13:16:11 -0400 Received: by mail-yb1-f194.google.com with SMTP id o82so677984ybg.10 for ; Mon, 19 Aug 2019 10:16:10 -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=TMs535P7xxFLiQOk7wJAthNZTpkgqr1nBQtH4nH/Y58=; b=IsZolRq4D9ugD/n3Cx6odZ/1xIGiQ9XQL2IuWwAmIYWhbxIJx8dl6HcU7d5Ob44QHt ElaZvwnjhMgPhaOIAqszEwy+jKzICfAY06gudCjwe2YrdpPYFdvugT+CTrU53FYDAHd9 pmnJM1tp8UggQw3Duk7e6f26skYNyukq2na0Cp+jNi23iqo/s9KVthkuQXEK8Sw4DfdO Mv/c1BMYcAqziNZ7zpdeWzit5D06938NgiRLKrKjEzRTsIgw9SuC1ZfY+q7v56DLOoc5 9Hhx/pCc6nwUAnfQPjnRomSXoy7SFJevLZUNhR10KUIL7Rm6VgUFvB4maUvp92SLDcXM E5Bg== X-Gm-Message-State: APjAAAXRf0DbVsYyFDT9OLxBcJH0p2WTtm0qtpnxdS79Gr9bJs/rCv7r 5bD11CUDRu08CB7r/yjQMjI= X-Received: by 2002:a25:9747:: with SMTP id h7mr16350427ybo.432.1566234969941; Mon, 19 Aug 2019 10:16:09 -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 d195sm3365808ywb.101.2019.08.19.10.16.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Aug 2019 10:16:08 -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 v2] mtd: spi-nor: fix a memory leak bug Date: Mon, 19 Aug 2019 12:16:00 -0500 Message-Id: <1566234960-3226-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. Fixes: 816873eaeec6 ("mtd: spi-nor: parse SFDP 4-byte Address Instruction Table") 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