Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp340241pxj; Thu, 20 May 2021 10:30:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyY5sKLZ3o3rFjPC1yp3Rj/lNejvlhQcyw+TVBA0EBJF8SGKI9Zidn6VrFS8DyRnzyEn2pe X-Received: by 2002:a17:907:2067:: with SMTP id qp7mr5829776ejb.333.1621531817690; Thu, 20 May 2021 10:30:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621531817; cv=none; d=google.com; s=arc-20160816; b=aAl3W+ALO5QYslnmEKjwCh4FAfU9VUtMGK/FRHw5TughBmYfoYGsDgaxjGHAjFzqsZ PvOrqUwfStP+mvlINjq5uusInH06UYN79St+Ju9rH1Wn+Lge9X8Ek7Mdu0Zt/XONUB3g f7IMw3ruv5Um0rjmi3f5mKtma7Ai8M0lz/UAgO3RzrNHmUH/W3lbuc4+J8yiC63SKzT0 tf17TejII7XxSyI9DPE/KT/YlBBpr6fzW0hBXbdHfgAXNwtrmrxfT3PKUzOSZUCo8cQ7 X2cxinX+Ld/RoYj87yaSTyrANd+tfvNoFCBLrXWczN8v7ILDVtlb4JkqjNgMMwuna3Fn /bsw== 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=y2NobPZCcxQ5Un1+LWwVTG/IAbg34Oh2DGPkpY/2tA0=; b=dnpalLV9H2DBa57XPyYGKzq53m1Z/N0GWUdWk5P2y8w1XeKQn+UogYNzlHdtDJ6eGT 1NLQIExd1LMRMqaCwq+Hj4jtvJvWB6XHFVC6LyUITw4jFtOidRQyFOHvxM4EilTJyd5K DladzSh0Q7GzkKbjlgy/ngksZvsk/BLnCf/fEfC9PHOuIN3DxAThwVJHCdc4E3xvkWhz xBjtIMmtv3fyA848EnCwoB+/zAMnn70ZX6n93GgiWjAHJtJhgoOurCfNCHow00C7EdgC TK9PyKtNieKM+wnxzWtL+54tA+/Q+3hRBI20CX5x+lf+b7VW6KU0wpfwG1qGExbj47QV N49g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QoJ8yMOv; 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 h8si3956463ejj.270.2021.05.20.10.29.54; Thu, 20 May 2021 10:30:17 -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=QoJ8yMOv; 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 S234232AbhETJ4g (ORCPT + 99 others); Thu, 20 May 2021 05:56:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:54742 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234128AbhETJxD (ORCPT ); Thu, 20 May 2021 05:53:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AC93C6135A; Thu, 20 May 2021 09:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503383; bh=yh2vdzoMHIAK9iIBgUTaRUpKDEZCrnSY4DkPBh+2t8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QoJ8yMOv+I2BVlx1oA0pJpwGrjruQfrX7UELFlkq7hBV0l9LQL14v6O/b+kZ3NpV8 5QYOx/4rLn063J/x1/8lsetHIRlg1qs4RUCVtBzBDIGuyF0HLM3kYyK3sF8N3RmZ/S HtNNZCWj/crRcpZnQiCBVbGTGgwv7dkgePp8wEHM= 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.19 197/425] mtd: rawnand: gpmi: Fix a double free in gpmi_nand_init Date: Thu, 20 May 2021 11:19:26 +0200 Message-Id: <20210520092137.893161733@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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/raw/gpmi-nand/gpmi-nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c index fe99d9323d4a..6bd414bac34d 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c @@ -1931,7 +1931,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; chip->dummy_controller.ops = &gpmi_nand_controller_ops; ret = nand_scan(chip, GPMI_IS_MX6(this) ? 2 : 1); -- 2.30.2