Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3545632pxb; Sun, 26 Sep 2021 19:02:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzQb4WtCHWjkHsw94k2o5U40g3v4+PKHM9khKE5q2L9mEluRHU5PnaStDl7ee8nW2oOOHp X-Received: by 2002:a17:902:758b:b0:13e:8b1:e49f with SMTP id j11-20020a170902758b00b0013e08b1e49fmr8946757pll.6.1632708121764; Sun, 26 Sep 2021 19:02:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632708121; cv=none; d=google.com; s=arc-20160816; b=TXg8XjuahhpRaqZYzt3v5DBi+n3dSM51/c16T0oyEWKO+DE6Xmjake/+kYIWUsIb8y p6ESLw0PXgsazlKe2jY1YPBOO0sO5GBeryByYV6OrcrPk5cLn1Zv+eS1ekLOuayujGGO 9ZQQ+BRAUfCB8KIVWYAScduzA3myHWDTfSps19xXAwQ0c34O4JyTSIGQD+1lqjWDL1JA 12N5ICqdYRuYRn53tfmgnZN1eftx8tYgeJjlsCK6EDAlNYPWoEtgAqiA6LdCgQOZNK80 G8P3zNLWxyeN8w2YZemw1bpbG+Hxkb7MZI3Qci39OAVABAnHDwJOTNA98gVcwZXgwsom 37tg== 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=INcf37QQi9siQzq/L1Iyk1bKxcSM2+zBRsgtdm2Bjhw=; b=SaGR4VYe2IdA57p5pxC20Moxgf8BdITrbWPtbPHKqmU0i8Sn/kYdSJKDgpLPV41qIe eGSqVF4lx/ZZm0gqbAe/XW0qYrTiqI+9zLJBdWZRVZAkqiKDYn2rkeYfPJWX3H1CHk2x 5bMtbMgQaoqHj++lAzBgm3XpV4PAol9t+Qo+hM+v/UajV/1WA7XJ8Bz6JAJEBMLr0wxs KHXlsR8APxlYoLPXYy18GzVfavZDQhb5459a+s3Y1C3N1BfW88rXDh/WmzLG3rxyRQK/ 2ApIdNTm1pdtFlbgvEjJiCmwr2VgoUADfoBcKcLSiQ5D2pq1XO4OYRkf/BkkDkUaMvvx x8CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fudan.edu.cn header.s=dkim header.b=lYA4G2bI; 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 t21si21751505pfh.287.2021.09.26.19.01.49; Sun, 26 Sep 2021 19:02:01 -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=lYA4G2bI; 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 S232435AbhI0CCO (ORCPT + 99 others); Sun, 26 Sep 2021 22:02:14 -0400 Received: from zg8tmty1ljiyny4xntqumjca.icoremail.net ([165.227.154.27]:39157 "HELO zg8tmty1ljiyny4xntqumjca.icoremail.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S232434AbhI0CCM (ORCPT ); Sun, 26 Sep 2021 22:02:12 -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=INcf37QQi9 siQzq/L1Iyk1bKxcSM2+zBRsgtdm2Bjhw=; b=lYA4G2bIi1F4zXgtFKJ7DY8PQZ kaexJzBEr1Ez13IgvQuK8pDSRWMUfdKNWTfC7VH9pttlBOmeQfcRvT8azbU95AFl AqZx14T+pO+20W2r3g30SsBGjOZUOjlqHwjsfhfsv8Hggc/RIo/Ft80lrGte5QCp a3dD+J6OFsJBK8atM= Received: from localhost.localdomain (unknown [39.144.40.15]) by app2 (Coremail) with SMTP id XQUFCgDX3s6ZJVFhNA_yAA--.45020S4; Mon, 27 Sep 2021 10:00:24 +0800 (CST) From: Xin Xiong To: Ulf Hansson , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yuanxzhang@fudan.edu.cn, Xin Xiong , Xiyu Yang , Xin Tan Subject: [PATCH v2] drivers/mmc: fix reference count leaks in moxart_probe Date: Mon, 27 Sep 2021 09:57:59 +0800 Message-Id: <20210927015759.30855-1-xiongx18@fudan.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: XQUFCgDX3s6ZJVFhNA_yAA--.45020S4 X-Coremail-Antispam: 1UD129KBjvJXoW7WF1xJF4Utw4rKFyUXr4xJFb_yoW8WrW8pF 48Cr9IkrWUtr4akF47Ca1DWF18ur4Fyw43KrZ093s7Z34UJFsrC348Ga40qr95JryrXFZY gF1YqF15uFZ5JFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvm14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IE rcIFxwCY02Avz4vE14v_Gr1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr 1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE 14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7 IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWrZr1j6s0DMIIF0xvE x4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnU UI43ZEXa7VUbBMKJUUUUU== X-CM-SenderInfo: arytiiqsuqiimz6i3vldqovvfxof0/1tbiAg4REFKp2bi50AAAs+ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The issue happens in several error handling paths on two refcounted object related to the object "host" (dma_chan_rx, dma_chan_tx). In these paths, the function forgets to decrement one or both objects' reference count increased earlier by dma_request_chan(), causing reference count leaks. Fix it by balancing the refcounts of both objects in some error handling paths. Signed-off-by: Xin Xiong Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan --- drivers/mmc/host/moxart-mmc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c index 6c9d38132..e27ab3446 100644 --- a/drivers/mmc/host/moxart-mmc.c +++ b/drivers/mmc/host/moxart-mmc.c @@ -621,6 +621,14 @@ static int moxart_probe(struct platform_device *pdev) ret = -EPROBE_DEFER; goto out; } + if (!IS_ERR(host->dma_chan_tx)) { + dma_release_channel(host->dma_chan_tx); + host->dma_chan_tx = NULL; + } + if (!IS_ERR(host->dma_chan_rx)) { + dma_release_channel(host->dma_chan_rx); + host->dma_chan_rx = NULL; + } dev_dbg(dev, "PIO mode transfer enabled\n"); host->have_dma = false; } else { @@ -675,6 +683,10 @@ static int moxart_probe(struct platform_device *pdev) return 0; out: + if (!IS_ERR_OR_NULL(host->dma_chan_tx)) + dma_release_channel(host->dma_chan_tx); + if (!IS_ERR_OR_NULL(host->dma_chan_rx)) + dma_release_channel(host->dma_chan_rx); if (mmc) mmc_free_host(mmc); return ret; -- 2.25.1