From patchwork Mon Dec 8 11:07:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Scheel X-Patchwork-Id: 5455501 Return-Path: X-Original-To: patchwork-dmaengine@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7642C9F2E8 for ; Mon, 8 Dec 2014 11:09:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 93EFE20166 for ; Mon, 8 Dec 2014 11:09:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 93E8C20155 for ; Mon, 8 Dec 2014 11:09:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755123AbaLHLJf (ORCPT ); Mon, 8 Dec 2014 06:09:35 -0500 Received: from smtp.work.de ([212.12.45.188]:44285 "EHLO smtp.work.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755106AbaLHLJR (ORCPT ); Mon, 8 Dec 2014 06:09:17 -0500 Received: from [127.0.0.1] (helo=avionic-0108.net.jusst.de.) by smtp.work.de with esmtpa (Exim 4.80) (envelope-from ) id 1XxwBn-0008Hj-2d; Mon, 08 Dec 2014 12:09:15 +0100 From: Julian Scheel To: dmaengine@vger.kernel.org Cc: Julian Scheel Subject: [PATCH] dmaengine: maintain privatecnt in get_any_slave_channel Date: Mon, 8 Dec 2014 12:07:33 +0100 Message-Id: <1418036853-2889-1-git-send-email-julian@jusst.de> X-Mailer: git-send-email 2.1.3 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As dma_get_any_slave_channel is used to request a channel which will later on be released through dma_release_channel it needs to maintain the privatecnt just as __dma_request_channel does. Do this by refactoring the privatenct handling into a helper function which is used from __dma_request_channel as well as dma_get_any_slave_channel. Signed-off-by: Julian Scheel --- drivers/dma/dmaengine.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 24bfaf0..0215db4 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -535,6 +535,24 @@ struct dma_chan *dma_get_slave_channel(struct dma_chan *chan) } EXPORT_SYMBOL_GPL(dma_get_slave_channel); + +static int dma_get_channel_private(struct dma_device *device, struct dma_chan *chan) +{ + int err; + + /* We first set DMA_PRIVATE to disable + * balance_ref_count as this channel will not be + * published in the general-purpose allocator + */ + dma_cap_set(DMA_PRIVATE, device->cap_mask); + device->privatecnt++; + + err = dma_chan_get(chan); + if (err && --device->privatecnt == 0) + dma_cap_clear(DMA_PRIVATE, device->cap_mask); + return err; +} + struct dma_chan *dma_get_any_slave_channel(struct dma_device *device) { dma_cap_mask_t mask; @@ -549,7 +567,7 @@ struct dma_chan *dma_get_any_slave_channel(struct dma_device *device) chan = private_candidate(&mask, device, NULL, NULL); if (chan) { - err = dma_chan_get(chan); + err = dma_get_channel_private(device, chan); if (err) { pr_debug("%s: failed to get %s: (%d)\n", __func__, dma_chan_name(chan), err); @@ -584,13 +602,9 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, chan = private_candidate(mask, device, fn, fn_param); if (chan) { /* Found a suitable channel, try to grab, prep, and - * return it. We first set DMA_PRIVATE to disable - * balance_ref_count as this channel will not be - * published in the general-purpose allocator + * return it. */ - dma_cap_set(DMA_PRIVATE, device->cap_mask); - device->privatecnt++; - err = dma_chan_get(chan); + err = dma_get_channel_private(device, chan); if (err == -ENODEV) { pr_debug("%s: %s module removed\n", @@ -601,8 +615,6 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, __func__, dma_chan_name(chan), err); else break; - if (--device->privatecnt == 0) - dma_cap_clear(DMA_PRIVATE, device->cap_mask); chan = NULL; } }