Commit ac51b9611db597aa55e06218c62c3511702d772f
Committed by
Chris Ball
1 parent
76a411f9f9
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
mmc: sh_mobile_sdhi: use managed resource allocations
Use managed allocations to get memory, clock and interrupts . This significantly simplifies clean up paths. Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Signed-off-by: Chris Ball <cjb@laptop.org>
Showing 1 changed file with 14 additions and 43 deletions Side-by-side Diff
drivers/mmc/host/sh_mobile_sdhi.c
... | ... | @@ -147,7 +147,7 @@ |
147 | 147 | int irq, ret, i = 0; |
148 | 148 | bool multiplexed_isr = true; |
149 | 149 | |
150 | - priv = kzalloc(sizeof(struct sh_mobile_sdhi), GFP_KERNEL); | |
150 | + priv = devm_kzalloc(&pdev->dev, sizeof(struct sh_mobile_sdhi), GFP_KERNEL); | |
151 | 151 | if (priv == NULL) { |
152 | 152 | dev_err(&pdev->dev, "kzalloc failed\n"); |
153 | 153 | return -ENOMEM; |
154 | 154 | |
... | ... | @@ -159,11 +159,11 @@ |
159 | 159 | if (p->init) { |
160 | 160 | ret = p->init(pdev, &sdhi_ops); |
161 | 161 | if (ret) |
162 | - goto einit; | |
162 | + return ret; | |
163 | 163 | } |
164 | 164 | } |
165 | 165 | |
166 | - priv->clk = clk_get(&pdev->dev, NULL); | |
166 | + priv->clk = devm_clk_get(&pdev->dev, NULL); | |
167 | 167 | if (IS_ERR(priv->clk)) { |
168 | 168 | ret = PTR_ERR(priv->clk); |
169 | 169 | dev_err(&pdev->dev, "cannot get clock: %d\n", ret); |
170 | 170 | |
171 | 171 | |
172 | 172 | |
173 | 173 | |
174 | 174 | |
175 | 175 | |
... | ... | @@ -223,33 +223,33 @@ |
223 | 223 | irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_CARD_DETECT); |
224 | 224 | if (irq >= 0) { |
225 | 225 | multiplexed_isr = false; |
226 | - ret = request_irq(irq, tmio_mmc_card_detect_irq, 0, | |
226 | + ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_card_detect_irq, 0, | |
227 | 227 | dev_name(&pdev->dev), host); |
228 | 228 | if (ret) |
229 | - goto eirq_card_detect; | |
229 | + goto eirq; | |
230 | 230 | } |
231 | 231 | |
232 | 232 | irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDIO); |
233 | 233 | if (irq >= 0) { |
234 | 234 | multiplexed_isr = false; |
235 | - ret = request_irq(irq, tmio_mmc_sdio_irq, 0, | |
235 | + ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_sdio_irq, 0, | |
236 | 236 | dev_name(&pdev->dev), host); |
237 | 237 | if (ret) |
238 | - goto eirq_sdio; | |
238 | + goto eirq; | |
239 | 239 | } |
240 | 240 | |
241 | 241 | irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDCARD); |
242 | 242 | if (irq >= 0) { |
243 | 243 | multiplexed_isr = false; |
244 | - ret = request_irq(irq, tmio_mmc_sdcard_irq, 0, | |
244 | + ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_sdcard_irq, 0, | |
245 | 245 | dev_name(&pdev->dev), host); |
246 | 246 | if (ret) |
247 | - goto eirq_sdcard; | |
247 | + goto eirq; | |
248 | 248 | } else if (!multiplexed_isr) { |
249 | 249 | dev_err(&pdev->dev, |
250 | 250 | "Principal SD-card IRQ is missing among named interrupts\n"); |
251 | 251 | ret = irq; |
252 | - goto eirq_sdcard; | |
252 | + goto eirq; | |
253 | 253 | } |
254 | 254 | |
255 | 255 | if (multiplexed_isr) { |
256 | 256 | |
257 | 257 | |
... | ... | @@ -258,15 +258,15 @@ |
258 | 258 | if (irq < 0) |
259 | 259 | break; |
260 | 260 | i++; |
261 | - ret = request_irq(irq, tmio_mmc_irq, 0, | |
261 | + ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq, 0, | |
262 | 262 | dev_name(&pdev->dev), host); |
263 | 263 | if (ret) |
264 | - goto eirq_multiplexed; | |
264 | + goto eirq; | |
265 | 265 | } |
266 | 266 | |
267 | 267 | /* There must be at least one IRQ source */ |
268 | 268 | if (!i) |
269 | - goto eirq_multiplexed; | |
269 | + goto eirq; | |
270 | 270 | } |
271 | 271 | |
272 | 272 | dev_info(&pdev->dev, "%s base at 0x%08lx clock rate %u MHz\n", |
273 | 273 | |
274 | 274 | |
... | ... | @@ -276,28 +276,12 @@ |
276 | 276 | |
277 | 277 | return ret; |
278 | 278 | |
279 | -eirq_multiplexed: | |
280 | - while (i--) { | |
281 | - irq = platform_get_irq(pdev, i); | |
282 | - free_irq(irq, host); | |
283 | - } | |
284 | -eirq_sdcard: | |
285 | - irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDIO); | |
286 | - if (irq >= 0) | |
287 | - free_irq(irq, host); | |
288 | -eirq_sdio: | |
289 | - irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_CARD_DETECT); | |
290 | - if (irq >= 0) | |
291 | - free_irq(irq, host); | |
292 | -eirq_card_detect: | |
279 | +eirq: | |
293 | 280 | tmio_mmc_host_remove(host); |
294 | 281 | eprobe: |
295 | - clk_put(priv->clk); | |
296 | 282 | eclkget: |
297 | 283 | if (p && p->cleanup) |
298 | 284 | p->cleanup(pdev); |
299 | -einit: | |
300 | - kfree(priv); | |
301 | 285 | return ret; |
302 | 286 | } |
303 | 287 | |
304 | 288 | |
305 | 289 | |
306 | 290 | |
... | ... | @@ -305,25 +289,12 @@ |
305 | 289 | { |
306 | 290 | struct mmc_host *mmc = platform_get_drvdata(pdev); |
307 | 291 | struct tmio_mmc_host *host = mmc_priv(mmc); |
308 | - struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data); | |
309 | 292 | struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; |
310 | - int i = 0, irq; | |
311 | 293 | |
312 | 294 | tmio_mmc_host_remove(host); |
313 | 295 | |
314 | - while (1) { | |
315 | - irq = platform_get_irq(pdev, i++); | |
316 | - if (irq < 0) | |
317 | - break; | |
318 | - free_irq(irq, host); | |
319 | - } | |
320 | - | |
321 | - clk_put(priv->clk); | |
322 | - | |
323 | 296 | if (p && p->cleanup) |
324 | 297 | p->cleanup(pdev); |
325 | - | |
326 | - kfree(priv); | |
327 | 298 | |
328 | 299 | return 0; |
329 | 300 | } |