From patchwork Tue Sep 25 18:59:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hunter, Jon" X-Patchwork-Id: 1506341 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 90EBDDFE80 for ; Tue, 25 Sep 2012 19:05:06 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TGaPR-0004R7-Fh; Tue, 25 Sep 2012 19:03:05 +0000 Received: from arroyo.ext.ti.com ([192.94.94.40]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TGaPO-0004Qj-0C for linux-arm-kernel@lists.infradead.org; Tue, 25 Sep 2012 19:03:03 +0000 Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id q8PIxlSr026773; Tue, 25 Sep 2012 13:59:47 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id q8PIxlKq010404; Tue, 25 Sep 2012 13:59:47 -0500 Received: from dlelxv24.itg.ti.com (172.17.1.199) by dfle73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.1.323.3; Tue, 25 Sep 2012 13:59:47 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlelxv24.itg.ti.com (8.13.8/8.13.8) with ESMTP id q8PIxlfW031698; Tue, 25 Sep 2012 13:59:47 -0500 Received: from localhost (ula0741266.am.dhcp.ti.com [192.157.144.139]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id q8PIxkw16503; Tue, 25 Sep 2012 13:59:46 -0500 (CDT) From: Jon Hunter To: Vinod Koul Subject: [PATCH] of: dma: fix potential deadlock when requesting a slave channel Date: Tue, 25 Sep 2012 13:59:31 -0500 Message-ID: <1348599571-29546-1-git-send-email-jon-hunter@ti.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -7.7 (-------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-7.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [192.94.94.40 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.8 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Stephen Warren , Benoit Cousson , Arnd Bergmann , Vinod Koul , device-tree , Nicolas Ferre , Rob Herring , Grant Likely , Jon Hunter , Dan Williams , Russell King , linux-omap , linux-arm X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org In the latest version of the OF dma handlers I added support (rather hastily) to exhaustively search for an available dma slave channel, for the use-case where we have alternative slave channels that can be used. In the current implementation a deadlock scenario can occur causing the CPU to loop forever. The scenario is as follows ... 1. There are alternative channels avaialble 2. The first channel that is found by calling of_dma_find_channel() is not available and so the call to the xlate function returns NULL. In this case we will call of_dma_find_channel() again but we will return the same channel that we found the first time and hence, again the xlate will return NULL and we will loop here forever. Fix this potential deadlock by just using a single for-loop and not a for-loop nested in a do-while loop. This change also replaces the function of_dma_find_channel() with of_dma_match_channel() which performs a simple check to see if a DMA channel matches the name specified. I have tested this implementation on an OMAP4 panda board by adding a dummy DMA specifier, that will cause the xlate function to return NULL, to the beginning of a list of DMA specifiers for a DMA client. Cc: Nicolas Ferre Cc: Benoit Cousson Cc: Stephen Warren Cc: Grant Likely Cc: Russell King Cc: Rob Herring Cc: Arnd Bergmann Cc: Vinod Koul Cc: Dan Williams Signed-off-by: Jon Hunter --- drivers/of/dma.c | 60 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/drivers/of/dma.c b/drivers/of/dma.c index 19ad37c..4bed490 100644 --- a/drivers/of/dma.c +++ b/drivers/of/dma.c @@ -108,37 +108,32 @@ void of_dma_controller_free(struct device_node *np) EXPORT_SYMBOL_GPL(of_dma_controller_free); /** - * of_dma_find_channel - Find a DMA channel by name + * of_dma_match_channel - Check if a DMA specifier matches name * @np: device node to look for DMA channels - * @name: name of desired channel + * @name: channel name to be matched + * @index: index of DMA specifier in list of DMA specifiers * @dma_spec: pointer to DMA specifier as found in the device tree * - * Find a DMA channel by the name. Returns 0 on success or appropriate - * errno value on error. + * Check if the DMA specifier pointed to by the index in a list of DMA + * specifiers, matches the name provided. Returns 0 if the name matches and + * a valid pointer to the DMA specifier is found. Otherwise returns -ENODEV. */ -static int of_dma_find_channel(struct device_node *np, char *name, - struct of_phandle_args *dma_spec) +static int of_dma_match_channel(struct device_node *np, char *name, int index, + struct of_phandle_args *dma_spec) { - int count, i; const char *s; - count = of_property_count_strings(np, "dma-names"); - if (count < 0) - return count; + if (of_property_read_string_index(np, "dma-names", index, &s)) + return -ENODEV; - for (i = 0; i < count; i++) { - if (of_property_read_string_index(np, "dma-names", i, &s)) - continue; + if (strcmp(name, s)) + return -ENODEV; - if (strcmp(name, s)) - continue; + if (of_parse_phandle_with_args(np, "dmas", "#dma-cells", index, + dma_spec)) + return -ENODEV; - if (!of_parse_phandle_with_args(np, "dmas", "#dma-cells", i, - dma_spec)) - return 0; - } - - return -ENODEV; + return 0; } /** @@ -154,19 +149,22 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np, struct of_phandle_args dma_spec; struct of_dma *ofdma; struct dma_chan *chan; - int r; + int count, i; if (!np || !name) { pr_err("%s: not enough information provided\n", __func__); return NULL; } - do { - r = of_dma_find_channel(np, name, &dma_spec); - if (r) { - pr_err("%s: can't find DMA channel\n", np->full_name); - return NULL; - } + count = of_property_count_strings(np, "dma-names"); + if (count < 0) { + pr_err("%s: dma-names property missing or empty\n", __func__); + return NULL; + } + + for (i = 0; i < count; i++) { + if (of_dma_match_channel(np, name, i, &dma_spec)) + continue; ofdma = of_dma_find_controller(dma_spec.np); if (!ofdma) { @@ -185,9 +183,11 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np, of_node_put(dma_spec.np); - } while (!chan); + if (chan) + return chan; + } - return chan; + return NULL; } /**