Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp755371ybh; Wed, 18 Mar 2020 08:32:53 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtUMnMl7WZHH5RlIqroQTEPp+kW8UtocM83SHI4col6OB/SWm9lzqCqGhwxfRG2UwZKZbsQ X-Received: by 2002:a9d:7607:: with SMTP id k7mr4287474otl.205.1584545573219; Wed, 18 Mar 2020 08:32:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584545573; cv=none; d=google.com; s=arc-20160816; b=qP/5qowvtcsbeZLwcLYnoG05jfXJpOZF0W8zZQjL6de8S6Xmfhlpfne4MapohSO2KY t6MfheCxQbaXbcyMMNaZJ3CSSyLz0JA1zNb2Ewgx4xDx5g5bRtfQberP3yO+Wqn7mHB5 xg1kv3dwOtwj3KGz1nDOK4+jllxoboCUKxe5kWmItqZOI6JVyL+GilP7eUhJ/2GmR4xT ZRfI/zVSxPxOBk+opH6Fr/IC0Hj5LFGEWsOgoc0h3AZoNpXWP76bfy3HswzXkcyfz/Tb 4REEmgBpdeBReAPifxentXezURRCB+ftw42OSvatIdfTWiR/7tASkYs2RJnlsx0PEHJK HVIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=AtVisLjVjBr1UVyndPSR+7zheBoKZNuNNMLKB6qDTbg=; b=hggi5EcT8UKEny0blZvIXadPifw2EVS8YpwoWW0tYat0hPFz1ryIaZyH+sBeJKkyCc Gg4ug/v7wWgjdjptf7xBhRaVvuZOCVaWaa7qo5jWDTirDcfC8RIxfSMkvp2ezjP5t7BR LxZ+phQQ6rNHVWiUgaQLwUJkvg2hRU1+41UIgqCzxw5aLplPtojXdfHADIpbcio4/Q+7 6q8tYO0WXypYQQ8mUa++heODzzEC8xnHgCsbB7WwUG5mBsWsgxiIxs1vYMk8avZBQ9IP fdcrQ2G6EZ7h4mIvPDNBHtZNXMjczogQULt9DrQNF67T/EwANKNR7Tl45MXFe1fUaxeb bEUg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z23si3313251oih.275.2020.03.18.08.32.40; Wed, 18 Mar 2020 08:32:53 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726864AbgCRPcR (ORCPT + 99 others); Wed, 18 Mar 2020 11:32:17 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:3662 "EHLO out4436.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbgCRPcR (ORCPT ); Wed, 18 Mar 2020 11:32:17 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=wenyang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0TsyvOKU_1584545517; Received: from localhost(mailfrom:wenyang@linux.alibaba.com fp:SMTPD_---0TsyvOKU_1584545517) by smtp.aliyun-inc.com(127.0.0.1); Wed, 18 Mar 2020 23:32:05 +0800 From: Wen Yang To: Joern Engel , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Wen Yang , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RESEND PATCH] mtd: phram: fix a double free issue in error path Date: Wed, 18 Mar 2020 23:31:56 +0800 Message-Id: <20200318153156.25612-1-wenyang@linux.alibaba.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The variable 'name' is released multiple times in the error path, which may cause double free issues. This problem is avoided by adding a goto label to release the mem uniformly. And this change also makes the code a bit more cleaner. Fixes: 4f678a58d335 ("mtd: fix memory leaks in phram_setup") Signed-off-by: Wen Yang Cc: Joern Engel Cc: Miquel Raynal Cc: Richard Weinberger Cc: Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org Cc: linux-kernel@vger.kernel.org --- drivers/mtd/devices/phram.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c index 931e5c2481b5..b50ec7ecd10c 100644 --- a/drivers/mtd/devices/phram.c +++ b/drivers/mtd/devices/phram.c @@ -243,22 +243,25 @@ static int phram_setup(const char *val) ret = parse_num64(&start, token[1]); if (ret) { - kfree(name); parse_err("illegal start address\n"); + goto error; } ret = parse_num64(&len, token[2]); if (ret) { - kfree(name); parse_err("illegal device length\n"); + goto error; } ret = register_device(name, start, len); - if (!ret) - pr_info("%s device: %#llx at %#llx\n", name, len, start); - else - kfree(name); + if (ret) + goto error; + + pr_info("%s device: %#llx at %#llx\n", name, len, start); + return 0; +error: + kfree(name); return ret; } -- 2.23.0