aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Hunter <jon-hunter@ti.com>2012-09-25 14:59:31 -0400
committerVinod Koul <vinod.koul@intel.com>2013-01-08 01:05:00 -0500
commit5ca7c109e8eee8d97267d3308548509bb80d8bf0 (patch)
tree1677fb386e39530b2a87a1136621729525feeabf
parentbfc191ea568a9c00ab652750686f83ad2daf92a8 (diff)
of: dma: fix potential deadlock when requesting a slave channel
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 <nicolas.ferre@atmel.com> Cc: Benoit Cousson <b-cousson@ti.com> Cc: Stephen Warren <swarren@nvidia.com> Cc: Grant Likely <grant.likely@secretlab.ca> Cc: Russell King <linux@arm.linux.org.uk> Cc: Rob Herring <rob.herring@calxeda.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Vinod Koul <vinod.koul@intel.com> Cc: Dan Williams <djbw@fb.com> Signed-off-by: Jon Hunter <jon-hunter@ti.com> Signed-off-by: Vinod Koul <vinod.koul@linux.intel.com>
-rw-r--r--drivers/of/dma.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/drivers/of/dma.c b/drivers/of/dma.c
index 19ad37c066f5..4bed490a69e4 100644
--- a/drivers/of/dma.c
+++ b/drivers/of/dma.c
@@ -108,37 +108,32 @@ void of_dma_controller_free(struct device_node *np)
108EXPORT_SYMBOL_GPL(of_dma_controller_free); 108EXPORT_SYMBOL_GPL(of_dma_controller_free);
109 109
110/** 110/**
111 * of_dma_find_channel - Find a DMA channel by name 111 * of_dma_match_channel - Check if a DMA specifier matches name
112 * @np: device node to look for DMA channels 112 * @np: device node to look for DMA channels
113 * @name: name of desired channel 113 * @name: channel name to be matched
114 * @index: index of DMA specifier in list of DMA specifiers
114 * @dma_spec: pointer to DMA specifier as found in the device tree 115 * @dma_spec: pointer to DMA specifier as found in the device tree
115 * 116 *
116 * Find a DMA channel by the name. Returns 0 on success or appropriate 117 * Check if the DMA specifier pointed to by the index in a list of DMA
117 * errno value on error. 118 * specifiers, matches the name provided. Returns 0 if the name matches and
119 * a valid pointer to the DMA specifier is found. Otherwise returns -ENODEV.
118 */ 120 */
119static int of_dma_find_channel(struct device_node *np, char *name, 121static int of_dma_match_channel(struct device_node *np, char *name, int index,
120 struct of_phandle_args *dma_spec) 122 struct of_phandle_args *dma_spec)
121{ 123{
122 int count, i;
123 const char *s; 124 const char *s;
124 125
125 count = of_property_count_strings(np, "dma-names"); 126 if (of_property_read_string_index(np, "dma-names", index, &s))
126 if (count < 0) 127 return -ENODEV;
127 return count;
128 128
129 for (i = 0; i < count; i++) { 129 if (strcmp(name, s))
130 if (of_property_read_string_index(np, "dma-names", i, &s)) 130 return -ENODEV;
131 continue;
132 131
133 if (strcmp(name, s)) 132 if (of_parse_phandle_with_args(np, "dmas", "#dma-cells", index,
134 continue; 133 dma_spec))
134 return -ENODEV;
135 135
136 if (!of_parse_phandle_with_args(np, "dmas", "#dma-cells", i, 136 return 0;
137 dma_spec))
138 return 0;
139 }
140
141 return -ENODEV;
142} 137}
143 138
144/** 139/**
@@ -154,19 +149,22 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
154 struct of_phandle_args dma_spec; 149 struct of_phandle_args dma_spec;
155 struct of_dma *ofdma; 150 struct of_dma *ofdma;
156 struct dma_chan *chan; 151 struct dma_chan *chan;
157 int r; 152 int count, i;
158 153
159 if (!np || !name) { 154 if (!np || !name) {
160 pr_err("%s: not enough information provided\n", __func__); 155 pr_err("%s: not enough information provided\n", __func__);
161 return NULL; 156 return NULL;
162 } 157 }
163 158
164 do { 159 count = of_property_count_strings(np, "dma-names");
165 r = of_dma_find_channel(np, name, &dma_spec); 160 if (count < 0) {
166 if (r) { 161 pr_err("%s: dma-names property missing or empty\n", __func__);
167 pr_err("%s: can't find DMA channel\n", np->full_name); 162 return NULL;
168 return NULL; 163 }
169 } 164
165 for (i = 0; i < count; i++) {
166 if (of_dma_match_channel(np, name, i, &dma_spec))
167 continue;
170 168
171 ofdma = of_dma_find_controller(dma_spec.np); 169 ofdma = of_dma_find_controller(dma_spec.np);
172 if (!ofdma) { 170 if (!ofdma) {
@@ -185,9 +183,11 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
185 183
186 of_node_put(dma_spec.np); 184 of_node_put(dma_spec.np);
187 185
188 } while (!chan); 186 if (chan)
187 return chan;
188 }
189 189
190 return chan; 190 return NULL;
191} 191}
192 192
193/** 193/**