Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp2114273lkv; Thu, 20 May 2021 03:44:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPEmmU2g0XIljBrbCoyjSNfNPXpAdGTrEh/T3TbOcqSg9XWiZhxROkrl6qfEPbRuu/p/NC X-Received: by 2002:a05:6e02:104b:: with SMTP id p11mr4490186ilj.275.1621507484017; Thu, 20 May 2021 03:44:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621507484; cv=none; d=google.com; s=arc-20160816; b=n8JhXutHxXKMuI7WEthvF7kr9XkDiA3a3aYAXb/gQnXFwRNtXrUo0U5+gKj3GClQWS Ddrye3bP2V6PHo3apHo+0aNZoGSeD5jKMXCh6a2rNyGjwUiZKncnGCYt271VW+hlAgvo TrHt3Pu3MaNEdD45xPGaZzHFUNOM9ZiI4c6j4ww0YmOtAk0i/N4+uV4g1Xpv3TchKNWC yTFnCn8L8/6d7G7wHDj1Ys6BV0yQ0PeSkMYzgqIj78Hjn87v/WHhDu+nh9GPrfp3tyF2 MUQ4KGJSuX4zA+vPDFuJDjDKiTAZcZ+Ox1ciVuZnG1yQedJwtj9WYupLsfcWVdPM9cBb wz7Q== 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=o1J70PPUMacyci0wfWEjEzysZcDh2nH+U8QWm1Qsb3g=; b=hjm0YUqmSccCuTylYfFL+AIoo+Cx2ciZ2h1NDvPTpYnlWrYFq11lToZNEIm1E4gtz0 voqdabgfh/RtlrZFBhWo7Xqu9r/YtilCZFu+wtBY7TErIGNbKCpARRxVUpTN31c99viV wh1EhH+OzeMSveCnBoIqL7aiwVsPv92b4Tko3S/xXRWYfk+55dGnKNeEabf5K6mw/RNe GaKWMXar9Me9FX5So93LSTPy4O48E3xewENEgzcGgcq5uGRBpuxu2Zr9sTIcSqJLx/Ly 0voy+WrpN4CIhYWciZFNZJirbpqV2fhMwQGhUjcpLTpqbeGsUuMaVZfPgo8RUVN8ICEu YZ9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VXPPvioI; 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 o21si2161482jat.63.2021.05.20.03.44.15; Thu, 20 May 2021 03:44:44 -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=VXPPvioI; 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 S237333AbhETKn0 (ORCPT + 99 others); Thu, 20 May 2021 06:43:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:54242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236803AbhETK2Z (ORCPT ); Thu, 20 May 2021 06:28:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E7F9B61C2C; Thu, 20 May 2021 09:50:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504257; bh=mhxo0Y4O+//2DH4/zYXUM/1/ZzLnbPkrIy1xHvogl6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VXPPvioI97R7Ield3/t2736lFXS7ARnwMtZHubijREfG5p/RJpl7ybpELiOK5JCDk aNs0oFFNm8K5ZH+6q1HUNU+3+Su1oQsBpN5P7otAbGdNS5eci431PqHlLTmAKyZ4th 3gVS4yK6ZUwdsxwV3QE3z7BM9/eb62n6jWGOxPJA= 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.14 162/323] mtd: rawnand: gpmi: Fix a double free in gpmi_nand_init Date: Thu, 20 May 2021 11:20:54 +0200 Message-Id: <20210520092125.659517689@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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 c7d0d2eed6c2..5a694bdc4f75 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c @@ -2022,7 +2022,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