Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp546339pxj; Thu, 20 May 2021 15:53:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeVgeU9D3exS3fDZm/W2Fdw411CrMXGrW4WKA7/SAPEtNRHvkIQtiyD/oiz+CaHIdTW+NJ X-Received: by 2002:a05:6402:7d4:: with SMTP id u20mr7400402edy.302.1621551219470; Thu, 20 May 2021 15:53:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621551219; cv=none; d=google.com; s=arc-20160816; b=L9SzXPe2IAxesrVxiQmjE2GUiaxkVFwZAuBLICrij8PaZH7cBQoe7UQ/wKNIbZ9C4K BmlMdH12Gtbu/hm6JwJv9bFFcG9x4OFy1Eqm/Xy2EPB1qB0w7KNpo8PDgjPZNXRe8mYA ErnynU1QyAlc7eZJQnEHnABEIsN+GXNj6yh6you/x1yAuiFyfrmoe2RGgCftedkPdxTf KIy551whtleF+2PWL9nbzuiy9uV+PnJLslkZDBFG5Wd7kTJX/p/WrQPHeVsTROlZ2AeB YCywv6WPyzS+mWnpdN3hc5rRbnA4grhmePb2tziQgRFTyOYRl5V62Y5sYMsrJzlx5p60 O0ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OBN0pTH71HC0B/qFM8GlV/yeiwpgqyyXaj7tNR98Qfw=; b=bGIlzfVk/7W3DieE3v4khbUjW6y3JdikgvGJpnN/eFVR+f7AOwTdTWfo6hxs6Uk/uo SBx4qMu8+5h1vXt5EjZB0rCvXxVCADQPCuvgKOTeV/4ZEp0d28ousKVIu4zPxbCepOnF Batu5rROZtiGE5G76lz1HkgFUI7UDKbRa9COE4JBMnXk1H+A9qVgfIh2/kIuE4OC4AS/ 768xvnzR+/fY4qPAn/TKT5rjWKCXmw4dVpbY2WTofT9vzR5XITBDld274g1hl5JkjHeB MAFFV7vfkCNSNzc4QRhDe3nm08teWw+gUrHuYPfLe2qpCLTwCMcJH2WgZjUvQMHxH3KL ALvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Le9IXu3W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jg13si4774333ejc.430.2021.05.20.15.53.15; Thu, 20 May 2021 15:53:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Le9IXu3W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238639AbhETLQX (ORCPT + 99 others); Thu, 20 May 2021 07:16:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:52622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237704AbhETK4Z (ORCPT ); Thu, 20 May 2021 06:56:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4CA116141C; Thu, 20 May 2021 10:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504912; bh=JmDvZXWy+Jc27NKZWL+WoDK+hpW72GjNPlnBBdJAO+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Le9IXu3W9myjEOdBJzUpRaEkIOhzvwjqBwAmuai7Ekd0PyaQQEYJUmr5+zUCOrPRy LZUXwZBfo8zC3pOGr/Shx8k3bRa8jSWJ5D02alMmbOgsovkh8rhE75dJoZ1OArK+6x UUyHghouJQ/b05JDN/f16WnQzwhJ5Ym0rmx6dJEM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lv Yunlong , Miquel Raynal , Sasha Levin Subject: [PATCH 4.9 110/240] mtd: rawnand: gpmi: Fix a double free in gpmi_nand_init Date: Thu, 20 May 2021 11:21:42 +0200 Message-Id: <20210520092112.376419100@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lv Yunlong [ Upstream commit 076de75de1e53160e9b099f75872c1f9adf41a0b ] If the callee gpmi_alloc_dma_buffer() failed to alloc memory for this->raw_buffer, gpmi_free_dma_buffer() will be called to free this->auxiliary_virt. But this->auxiliary_virt is still a non-NULL and valid ptr. Then gpmi_alloc_dma_buffer() returns err and gpmi_free_dma_buffer() is called again to free this->auxiliary_virt in err_out. This causes a double free. As gpmi_free_dma_buffer() has already called in gpmi_alloc_dma_buffer's error path, so it should return err directly instead of releasing the dma buffer again. Fixes: 4d02423e9afe6 ("mtd: nand: gpmi: Fix gpmi_nand_init() error path") Signed-off-by: Lv Yunlong Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20210403060905.5251-1-lyl2019@mail.ustc.edu.cn Signed-off-by: Sasha Levin --- drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c index f4a99e91c250..c43bd945d93a 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c @@ -2020,7 +2020,7 @@ static int gpmi_nand_init(struct gpmi_nand_data *this) this->bch_geometry.auxiliary_size = 128; ret = gpmi_alloc_dma_buffer(this); if (ret) - goto err_out; + return ret; ret = nand_scan_ident(mtd, GPMI_IS_MX6(this) ? 2 : 1, NULL); if (ret) -- 2.30.2