| From aa808480fb9fa62c96bd38a83328a87971a95ed4 Mon Sep 17 00:00:00 2001 |
| From: Joel Stanley <joel@jms.id.au> |
| Date: Wed, 31 Jul 2019 18:10:37 +0930 |
| Subject: [PATCH] aspeed: espi: Clean up error handling |
| |
| I was seeing a crash shortly after the ESPI driver failed to probe: |
| |
| AST ESPI Unable to get GPIO IRQ -22 |
| Trying to free nonexistent resource <000000001e6ee000-000000001e6ee1ff> |
| aspeed_espi: probe of 1e6ee000.espi failed with error -22 |
| |
| The error handling was freeing the unallocated resource. |
| |
| The driver correctly makes allocations using the devm APIs. This means |
| the kernel will handle cleaning up of resources on failure. This patch |
| removes the unnecessary error handling. |
| |
| Signed-off-by: Joel Stanley <joel@jms.id.au> |
| --- |
| drivers/soc/aspeed/aspeed-espi.c | 30 ++++++------------------------ |
| 1 file changed, 6 insertions(+), 24 deletions(-) |
| |
| diff --git a/drivers/soc/aspeed/aspeed-espi.c b/drivers/soc/aspeed/aspeed-espi.c |
| index 342d45bdbad3..2b72f05dd24f 100644 |
| --- a/drivers/soc/aspeed/aspeed-espi.c |
| +++ b/drivers/soc/aspeed/aspeed-espi.c |
| @@ -1284,17 +1284,10 @@ static int aspeed_espi_probe(struct platform_device *pdev) |
| aspeed_espi->dma_mode = 0; |
| |
| res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| - if (res == NULL) { |
| - dev_err(&pdev->dev, "no memory resource defined\n"); |
| - ret = -ENODEV; |
| - goto err_free; |
| - } |
| - |
| aspeed_espi->reg_base = devm_ioremap_resource(&pdev->dev, res); |
| - if (aspeed_espi->reg_base == NULL) { |
| + if (IS_ERR(aspeed_espi->reg_base)) { |
| dev_err(&pdev->dev, "failed to ioremap() registers\n"); |
| - ret = -ENODEV; |
| - goto err_free_mem; |
| + return ERR_PTR(aspeed_espi->reg_base); |
| } |
| |
| sysfs_bin_attr_init(&aspeed_espi->oob_channel); |
| @@ -1398,15 +1391,14 @@ static int aspeed_espi_probe(struct platform_device *pdev) |
| aspeed_espi->irq = platform_get_irq(pdev, 0); |
| if (aspeed_espi->irq < 0) { |
| dev_err(&pdev->dev, "no irq specified\n"); |
| - ret = -ENOENT; |
| - goto err_free_mem; |
| + return aspeed_espi->irq; |
| } |
| |
| ret = devm_request_irq(&pdev->dev, aspeed_espi->irq, aspeed_espi_isr, |
| 0, dev_name(&pdev->dev), aspeed_espi); |
| if (ret) { |
| printk("AST ESPI Unable to get IRQ"); |
| - goto err_free_mem; |
| + return ret; |
| } |
| |
| aspeed_espi->reset = devm_reset_control_get(&pdev->dev, NULL); |
| @@ -1421,7 +1413,7 @@ static int aspeed_espi_probe(struct platform_device *pdev) |
| 0, dev_name(&pdev->dev), aspeed_espi); |
| if (ret) { |
| printk("AST ESPI Unable to get GPIO IRQ %d\n", ret); |
| - goto err_free_mem; |
| + return ret; |
| } |
| |
| aspeed_espi_ctrl_init(aspeed_espi); |
| @@ -1429,7 +1421,7 @@ static int aspeed_espi_probe(struct platform_device *pdev) |
| ret = misc_register(&aspeed_espi_misc); |
| if (ret) { |
| printk(KERN_ERR "ESPI : failed misc_register\n"); |
| - goto err_free_irq; |
| + return ret; |
| } |
| |
| platform_set_drvdata(pdev, aspeed_espi); |
| @@ -1444,16 +1436,6 @@ static int aspeed_espi_probe(struct platform_device *pdev) |
| printk(KERN_INFO "aspeed_espi: driver successfully loaded.\n"); |
| |
| return 0; |
| - |
| -err_free_irq: |
| - free_irq(aspeed_espi->irq, pdev); |
| - |
| -err_free_mem: |
| - release_mem_region(res->start, resource_size(res)); |
| -err_free: |
| - kfree(aspeed_espi); |
| - |
| - return ret; |
| } |
| |
| static int aspeed_espi_remove(struct platform_device *pdev) |
| -- |
| 2.20.1 |
| |