aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-06-06 06:33:13 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2012-07-06 13:17:05 -0400
commite4a09cbf2dc7ba6c7fd7e07a3ab3d3f499a575e2 (patch)
treede637233fe175db5aff43c96b4c1b4c13f88c1cd
parent874d72c4fe07713c4889c944d3c7ebbce352c762 (diff)
mtd: mxc_nand: Use managed resources
To make the error path simpler and to make subsequent patches easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Acked-by: Shawn Guo <shawn.guo@linaro.org> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
-rw-r--r--drivers/mtd/nand/mxc_nand.c70
1 files changed, 23 insertions, 47 deletions
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index fc3b38c7ffb4..db428c24e2c8 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -1344,8 +1344,8 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1344 int err = 0; 1344 int err = 0;
1345 1345
1346 /* Allocate memory for MTD device structure and private data */ 1346 /* Allocate memory for MTD device structure and private data */
1347 host = kzalloc(sizeof(struct mxc_nand_host) + NAND_MAX_PAGESIZE + 1347 host = devm_kzalloc(&pdev->dev, sizeof(struct mxc_nand_host) +
1348 NAND_MAX_OOBSIZE, GFP_KERNEL); 1348 NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE, GFP_KERNEL);
1349 if (!host) 1349 if (!host)
1350 return -ENOMEM; 1350 return -ENOMEM;
1351 1351
@@ -1372,26 +1372,17 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1372 this->read_buf = mxc_nand_read_buf; 1372 this->read_buf = mxc_nand_read_buf;
1373 this->verify_buf = mxc_nand_verify_buf; 1373 this->verify_buf = mxc_nand_verify_buf;
1374 1374
1375 host->clk = clk_get(&pdev->dev, "nfc"); 1375 host->clk = devm_clk_get(&pdev->dev, "nfc");
1376 if (IS_ERR(host->clk)) { 1376 if (IS_ERR(host->clk))
1377 err = PTR_ERR(host->clk); 1377 return PTR_ERR(host->clk);
1378 goto eclk;
1379 }
1380
1381 clk_prepare_enable(host->clk);
1382 host->clk_act = 1;
1383 1378
1384 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1379 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1385 if (!res) { 1380 if (!res)
1386 err = -ENODEV; 1381 return -ENODEV;
1387 goto eres;
1388 }
1389 1382
1390 host->base = ioremap(res->start, resource_size(res)); 1383 host->base = devm_request_and_ioremap(&pdev->dev, res);
1391 if (!host->base) { 1384 if (!host->base)
1392 err = -ENOMEM; 1385 return -ENOMEM;
1393 goto eres;
1394 }
1395 1386
1396 host->main_area0 = host->base; 1387 host->main_area0 = host->base;
1397 1388
@@ -1399,7 +1390,7 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1399 if (err > 0) 1390 if (err > 0)
1400 err = mxcnd_probe_pdata(host); 1391 err = mxcnd_probe_pdata(host);
1401 if (err < 0) 1392 if (err < 0)
1402 goto eirq; 1393 return err;
1403 1394
1404 if (host->devtype_data->regs_offset) 1395 if (host->devtype_data->regs_offset)
1405 host->regs = host->base + host->devtype_data->regs_offset; 1396 host->regs = host->base + host->devtype_data->regs_offset;
@@ -1416,15 +1407,11 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1416 1407
1417 if (host->devtype_data->needs_ip) { 1408 if (host->devtype_data->needs_ip) {
1418 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 1409 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1419 if (!res) { 1410 if (!res)
1420 err = -ENODEV; 1411 return -ENODEV;
1421 goto eirq; 1412 host->regs_ip = devm_request_and_ioremap(&pdev->dev, res);
1422 } 1413 if (!host->regs_ip)
1423 host->regs_ip = ioremap(res->start, resource_size(res)); 1414 return -ENOMEM;
1424 if (!host->regs_ip) {
1425 err = -ENOMEM;
1426 goto eirq;
1427 }
1428 } 1415 }
1429 1416
1430 if (host->pdata.hw_ecc) { 1417 if (host->pdata.hw_ecc) {
@@ -1458,9 +1445,13 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1458 */ 1445 */
1459 host->devtype_data->irq_control(host, 0); 1446 host->devtype_data->irq_control(host, 0);
1460 1447
1461 err = request_irq(host->irq, mxc_nfc_irq, IRQF_DISABLED, DRIVER_NAME, host); 1448 err = devm_request_irq(&pdev->dev, host->irq, mxc_nfc_irq,
1449 IRQF_DISABLED, DRIVER_NAME, host);
1462 if (err) 1450 if (err)
1463 goto eirq; 1451 return err;
1452
1453 clk_prepare_enable(host->clk);
1454 host->clk_act = 1;
1464 1455
1465 /* 1456 /*
1466 * Now that we "own" the interrupt make sure the interrupt mask bit is 1457 * Now that we "own" the interrupt make sure the interrupt mask bit is
@@ -1512,15 +1503,7 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1512 return 0; 1503 return 0;
1513 1504
1514escan: 1505escan:
1515 free_irq(host->irq, host); 1506 clk_disable_unprepare(host->clk);
1516eirq:
1517 if (host->regs_ip)
1518 iounmap(host->regs_ip);
1519 iounmap(host->base);
1520eres:
1521 clk_put(host->clk);
1522eclk:
1523 kfree(host);
1524 1507
1525 return err; 1508 return err;
1526} 1509}
@@ -1529,16 +1512,9 @@ static int __devexit mxcnd_remove(struct platform_device *pdev)
1529{ 1512{
1530 struct mxc_nand_host *host = platform_get_drvdata(pdev); 1513 struct mxc_nand_host *host = platform_get_drvdata(pdev);
1531 1514
1532 clk_put(host->clk);
1533
1534 platform_set_drvdata(pdev, NULL); 1515 platform_set_drvdata(pdev, NULL);
1535 1516
1536 nand_release(&host->mtd); 1517 nand_release(&host->mtd);
1537 free_irq(host->irq, host);
1538 if (host->regs_ip)
1539 iounmap(host->regs_ip);
1540 iounmap(host->base);
1541 kfree(host);
1542 1518
1543 return 0; 1519 return 0;
1544} 1520}