Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1625306pxb; Fri, 10 Sep 2021 09:56:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHc3rLPbic+ustFj88dOF0OgLexIKNFw9VAcqVVZqrTYcjwGNFuJYPAlLc0l/nsut3S5AP X-Received: by 2002:a17:906:2c5a:: with SMTP id f26mr10568638ejh.205.1631292983897; Fri, 10 Sep 2021 09:56:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631292983; cv=none; d=google.com; s=arc-20160816; b=tmUu6KUUfgbRdj+S4IvgxtWkWquiV4Tantpdn+1PUrUo3ZuqDHAvpLsm6WIaImfOVO hnMmLydAV/vCct3+NBBh4YBfP7V7yM+cUYe6VWbUTpilRdr1KuewDWeYAjHoqg4cGU6C xKggEeMLrWYjJd9gDAKMOv/p6BX8bYtG2sCWw7/8QvQfjQPaZI0DAXHXJERW9NiPIwn6 zIw+BTKXbjg8lWS+QQRqDcJ8sp+ck1jbsiwfeNaLC8D/WzZvURD3+VHQiExx5a+UNB8M iDn4cWi9PQpE8sLupeDHpy7mQq7fI5Hr5WQY/QKUG0tOAax0EbCY2jLTjDqp0427ZHlv zzBQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=MSQF0TCIoWCnsmwyIDXDivOhQ6nSWPF+tN5KyDLNnIo=; b=jAU0IAhOBkSdMTj07S9KWTAs+na+aqiMHm4e3/dDeeJdGf9oA6uN2EUQd9TOjiK6X9 5jJzcnqCwvA+cZSjrOm56mBrmquGqCKVOKO9vXWYx+DP6Ik0VI6d0aAPe5hePYVVkmc1 Gr2DSBXivo8QzCyr73E9cRTRvsmdqUwcSEC4sTq//t6kg72v6CPIDjjpSyfGkjGl/Ioj OS9UE6Kb2Jx/jHJ5kwhuiBpEOStnEMjf+qKtRQ22XVaqbCPx9/vIkyY8UT6LY4isizpK JmQzShlbe/lCBaOfMlQH+5QO/cvhQanlGfzP+dbznCIzqeXRPQ45MlwDFm6pF7lDlJCg 42ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fudan.edu.cn header.s=dkim header.b=XQMjrGOd; 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=REJECT sp=REJECT dis=NONE) header.from=fudan.edu.cn Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v25si5309980edx.491.2021.09.10.09.55.58; Fri, 10 Sep 2021 09:56:23 -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=@fudan.edu.cn header.s=dkim header.b=XQMjrGOd; 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=REJECT sp=REJECT dis=NONE) header.from=fudan.edu.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230148AbhIJQze (ORCPT + 99 others); Fri, 10 Sep 2021 12:55:34 -0400 Received: from zg8tmty1ljiyny4xntqumjca.icoremail.net ([165.227.154.27]:58736 "HELO zg8tmty1ljiyny4xntqumjca.icoremail.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S230203AbhIJQzc (ORCPT ); Fri, 10 Sep 2021 12:55:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fudan.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-Id:MIME-Version:Content-Transfer-Encoding; bh=MSQF0TCIoW CnsmwyIDXDivOhQ6nSWPF+tN5KyDLNnIo=; b=XQMjrGOdcfLXFuJHmuQYyjjnA4 86cjdkBCwzYszHhmTu/jiJ5UL6+80CZ0n4mvcMmZz27kT8tdJc7b7z5doAkYRW2j 9c/LzDKLxjqTNdBt3Issth7r7MX4LwZdDvWMWowXIhBD1bx0B+SJI+6X1bNC58oK vSO43Dc4+67FoWL70= Received: from localhost.localdomain (unknown [223.104.213.26]) by app2 (Coremail) with SMTP id XQUFCgCnV6yFjTthaLhUAA--.17616S4; Sat, 11 Sep 2021 00:53:35 +0800 (CST) From: Xin Xiong To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Cc: yuanxzhang@fudan.edu.cn, Xin Xiong , Xiyu Yang , Xin Tan Subject: [PATCH] drivers/mtd/nand: fix reference count leaks in ebu_nand_probe Date: Sat, 11 Sep 2021 00:53:16 +0800 Message-Id: <20210910165316.2500-1-xiongx18@fudan.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: XQUFCgCnV6yFjTthaLhUAA--.17616S4 X-Coremail-Antispam: 1UD129KBjvJXoWxXFW5Kr1fKF1DGFy7tF1DZFb_yoW5Xr1xpF WrJFW2k3y0gFsrGrW2va1kWF1fArs7ZayrG39ru340y3s0qF4ag348trWFvFyDArWIqr1F gF1jqF18AFWDXaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvK14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r 4UJVWxJr1lnxkEFVAIw20F6cxK64vIFxWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG 64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE14v26r 1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAq YI8I648v4I1lc2xSY4AK67AK6r1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWrJr0_WFyUJwCI 42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxh VjvjDU0xZFpf9x0JUeBT5UUUUU= X-CM-SenderInfo: arytiiqsuqiimz6i3vldqovvfxof0/1tbiAg8AEFKp2aoYLwAAsi Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The reference counting issue happens in several error handling paths on two refcounted object related to the "ebu_host" object (dma_tx, dma_rx). In these paths, the function forgets to balance one or both objects' reference count. For example, when request dma tx chan fails, the function forgets to decrease the refcount of "ebu_host->dma_rx" increased by dma_request_chan(), causing refcount leaks. What's more, the "ebu_host->clk" object also need to be handled correctly. Fix this issue by keeping the return value and jumping to "err_cleanup_dma" label. Signed-off-by: Xin Xiong Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan --- drivers/mtd/nand/raw/intel-nand-controller.c | 23 ++++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c index 8b49fd56c..d5148f220 100644 --- a/drivers/mtd/nand/raw/intel-nand-controller.c +++ b/drivers/mtd/nand/raw/intel-nand-controller.c @@ -631,19 +631,27 @@ static int ebu_nand_probe(struct platform_device *pdev) ebu_host->clk_rate = clk_get_rate(ebu_host->clk); ebu_host->dma_tx = dma_request_chan(dev, "tx"); - if (IS_ERR(ebu_host->dma_tx)) - return dev_err_probe(dev, PTR_ERR(ebu_host->dma_tx), + if (IS_ERR(ebu_host->dma_tx)) { + ret = dev_err_probe(dev, PTR_ERR(ebu_host->dma_tx), "failed to request DMA tx chan!.\n"); + ebu_host->dma_tx = NULL; + goto err_cleanup_dma; + } ebu_host->dma_rx = dma_request_chan(dev, "rx"); - if (IS_ERR(ebu_host->dma_rx)) - return dev_err_probe(dev, PTR_ERR(ebu_host->dma_rx), + if (IS_ERR(ebu_host->dma_rx)) { + ret = dev_err_probe(dev, PTR_ERR(ebu_host->dma_rx), "failed to request DMA rx chan!.\n"); + ebu_host->dma_rx = NULL; + goto err_cleanup_dma; + } resname = devm_kasprintf(dev, GFP_KERNEL, "addr_sel%d", cs); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, resname); - if (!res) - return -EINVAL; + if (!res) { + ret = -EINVAL; + goto err_cleanup_dma; + } ebu_host->cs[cs].addr_sel = res->start; writel(ebu_host->cs[cs].addr_sel | EBU_ADDR_MASK(5) | EBU_ADDR_SEL_REGEN, ebu_host->ebu + EBU_ADDR_SEL(cs)); @@ -653,7 +661,8 @@ static int ebu_nand_probe(struct platform_device *pdev) mtd = nand_to_mtd(&ebu_host->chip); if (!mtd->name) { dev_err(ebu_host->dev, "NAND label property is mandatory\n"); - return -EINVAL; + ret = -EINVAL; + goto err_cleanup_dma; } mtd->dev.parent = dev; -- 2.25.1