Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1063222imw; Fri, 15 Jul 2022 20:04:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s+TKDyXImSXuCnQmSUmfLkvHL9vfK7iBpXnGmyn8cDDvxxnEoD7gALl9yigVM/A8QxwJS+ X-Received: by 2002:a17:902:dac2:b0:16c:6a1:692c with SMTP id q2-20020a170902dac200b0016c06a1692cmr16129422plx.19.1657940668565; Fri, 15 Jul 2022 20:04:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657940668; cv=none; d=google.com; s=arc-20160816; b=tjYVixkLb9etayQMGZtM7AvukvRPi4PFp2v7PThdUERfeK4L8+8uMc+atY/4CdIifG w9TLlUTbgm3rNyArxCHcpwBC7K363WzfyOM0oIRzW7TF1RNlm1qJGWDsNHnPJyY6T5vC xm1KOIW0Q2NRldBAAgnZMCKSICAV6NJZGGiU4rEqMY/+RV1asiLwWVj578g2ITaknz0M /QfMOWyoBZ+ZzSpKDEjl8mSfSzo3HR6U3MdEjJe7xTmAXfcwT4giiiVz59wTxk5PwXVR L62cLlgRapwDNjqSqjEG/yoCDrk9LS/uOd85M5ceVvvquSb87jiAh2NRFURRT9cCZfW/ Eexg== 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; bh=I647M+BkJbOQbX8IR0K908b/gNBxgl7Lf67hpfjvGhg=; b=krv0YWbnHiW4REz1jyCzLh7HpL3QvaepTkeZrWoJP6ov9cGHY0IP35qWgNSb7+OEwk QJ9Zv9OGKX1xR1ZMysp9u1s2DWwP03Uwbe/otCl/2a7hs1CyDBF5whmYI9SZiMsjZRxM Xps7mpIEQDUhNrRAfe1INL+Lz3Ar1wv3Cws8Ib6ZqB/t8+ll+Ri9zvWGt42TC/KgcDJo dCQhzl9JB9k0HWZrF00U38on+Q5vt7lixCAi1VUSlz8T6YfwGrL0EPhPBzNJapzDRSk8 uO/KLmaU1JXDamw1FsVT5lEEBMUHk9V9EhfMXhNSYGxKfzwYbnwnyNrYkko4wWEVTaSm j7Zg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a17090abd8b00b001efb2bb6f70si10680219pjr.77.2022.07.15.20.04.13; Fri, 15 Jul 2022 20:04:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbiGPCqA (ORCPT + 99 others); Fri, 15 Jul 2022 22:46:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiGPCp7 (ORCPT ); Fri, 15 Jul 2022 22:45:59 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65C4D8C764; Fri, 15 Jul 2022 19:45:54 -0700 (PDT) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LlCDb4q09zVfqG; Sat, 16 Jul 2022 10:42:07 +0800 (CST) Received: from kwepemm600007.china.huawei.com (7.193.23.208) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 16 Jul 2022 10:45:51 +0800 Received: from localhost.localdomain (10.67.165.2) by kwepemm600007.china.huawei.com (7.193.23.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 16 Jul 2022 10:45:51 +0800 From: Jie Hai To: CC: , , , Subject: [PATCH] dmaengine: Fix refcount increasing in dma_chan_get Date: Sat, 16 Jul 2022 10:44:53 +0800 Message-ID: <20220716024453.1418259-1-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600007.china.huawei.com (7.193.23.208) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When both hisi_dma.ko and async_tx.ko are loaded, you must first remove async_tx if you want to remove hisi_dma. We expect to remove hisi_dma successfully after doing so. In fact, hisi_dma is still referenced and cannot be removed. Module async_tx.ko references DMAEngine by dmaegnine_get(), which is recorded by dmaengine_ref_count and it is the only module in the current kernel that references dmaengine in this way. When the DMA driver is loaded, the reference is reflected in the reference counts of the driver and of the channels. Load hisi_dma.ko and async_tx.ko in sequence, the reference count of each DMA channel changes from zero to two. If only async_tx.ko is unloaded, the reference count of each channel should be reduced to zero again. However, that of each channel is still one without actually being used. The reference count of each channel is adjusted to dmaengine_ref_count and then increased by one in dma_chan_get. This is the reason why the reference count is greater than the actual reference by one. This patch swaps the reference counting updating sequence. The reference counting of each channel increases by one, and then adjusts. Fixes: d2f4f99db3e9 ("dmaengine: Rework dma_chan_get") Signed-off-by: Jie Hai --- drivers/dma/dmaengine.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 2cfa8458b51b..78f8a9f3ad82 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -451,7 +451,8 @@ static int dma_chan_get(struct dma_chan *chan) /* The channel is already in use, update client count */ if (chan->client_count) { __module_get(owner); - goto out; + chan->client_count++; + return 0; } if (!try_module_get(owner)) @@ -470,11 +471,11 @@ static int dma_chan_get(struct dma_chan *chan) goto err_out; } + chan->client_count++; + if (!dma_has_cap(DMA_PRIVATE, chan->device->cap_mask)) balance_ref_count(chan); -out: - chan->client_count++; return 0; err_out: -- 2.30.0