mmc: omap: Fix DMA configuration to not rely on device id
Hello Tony Lindgren,
This is a semi-automatic email about new static checker warnings.
The patch 31ee9181eb92: "mmc: omap: Fix DMA configuration to not rely on device id" from Nov 26, 2013, leads to the following Smatch complaint:
drivers/mmc/host/omap.c:1468 mmc_omap_probe()
error: we previously assumed 'res' could be null (see line 1410)
drivers/mmc/host/omap.c
1409 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
1410 if (res)
^^^
Patch introduces a check.
1411 sig = res->start;
1412 host->dma_rx = dma_request_slave_channel_compat(mask,
1413 omap_dma_filter_fn, &sig, &pdev->dev, "rx");
1414 if (!host->dma_rx)
1415 dev_warn(host->dev, "unable to obtain RX DMA engine channel %u\n",
1416 sig);
1417
1418 ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host);
1419 if (ret)
1420 goto err_free_dma;
1421
1422 if (pdata->init != NULL) {
1423 ret = pdata->init(&pdev->dev);
1424 if (ret < 0)
1425 goto err_free_irq;
1426 }
1427
1428 host->nr_slots = pdata->nr_slots;
1429 host->reg_shift = (mmc_omap7xx() ? 1 : 2);
1430
1431 host->mmc_omap_wq = alloc_workqueue("mmc_omap", 0, 0);
1432 if (!host->mmc_omap_wq)
1433 goto err_plat_cleanup;
1434
1435 for (i = 0; i < pdata->nr_slots; i++) {
1436 ret = mmc_omap_new_slot(host, i);
1437 if (ret < 0) {
1438 while (--i >= 0)
1439 mmc_omap_remove_slot(host->slots[i]);
1440
1441 goto err_destroy_wq;
1442 }
1443 }
1444
1445 return 0;
1446
1447 err_destroy_wq:
1448 destroy_workqueue(host->mmc_omap_wq);
1449 err_plat_cleanup:
1450 if (pdata->cleanup)
1451 pdata->cleanup(&pdev->dev);
1452 err_free_irq:
1453 free_irq(host->irq, host);
1454 err_free_dma:
1455 if (host->dma_tx)
1456 dma_release_channel(host->dma_tx);
1457 if (host->dma_rx)
1458 dma_release_channel(host->dma_rx);
1459 clk_put(host->fclk);
1460 err_free_iclk:
1461 clk_disable(host->iclk);
1462 clk_put(host->iclk);
1463 err_free_mmc_host:
1464 iounmap(host->virt_base);
1465 err_ioremap:
1466 kfree(host);
1467 err_free_mem_region:
1468 release_mem_region(res->start, resource_size(res));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Existing unchecked dereferences.
1469 return ret;
1470 }
regards,
dan carpenter
Quoted 74 lines · Dan Carpenter
Hello Tony Lindgren,
This is a semi-automatic email about new static checker warnings.
The patch
31ee9181eb92: "mmc: omap: Fix DMA configuration to not rely on device id" from Nov 26, 2013, leads to the following Smatch complaint:
drivers/mmc/host/omap.c:1468mmc_omap_probe()
error: we previously assumed 'res' could be null (see line 1410)
drivers/mmc/host/omap.c
1409 res =platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
1410 if (res)^^^Patch introduces a check.
1411 sig =
res->start;
1412host->dma_rx= dma_request_slave_channel_compat(mask,
1413omap_dma_filter_fn, &sig,&pdev->dev, "rx");
1414 if (!host->dma_rx)
1415 dev_warn(host->dev, "unable to obtain RX DMA engine channel %u\n",
1416 sig);
1417
1418 ret =request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host);
1419 if (ret)
1420 gotoerr_free_dma;
1421
1422 if (pdata->init!= NULL) {
1423 ret =pdata->init(&pdev->dev);
1424 if (ret < 0)
1425 gotoerr_free_irq;
1426 }
1427
1428host->nr_slots=pdata->nr_slots;
1429host->reg_shift= (mmc_omap7xx()? 1 : 2);
1430
1431host->mmc_omap_wq=alloc_workqueue("mmc_omap", 0, 0);
1432 if (!host->mmc_omap_wq)
1433 gotoerr_plat_cleanup;
1434
1435 for (i = 0; i <pdata->nr_slots; i++) {
1436 ret =mmc_omap_new_slot(host, i);
1437 if (ret < 0) {
1438 while (--i >= 0)
1439mmc_omap_remove_slot(host->slots[i]);
1440
1441 gotoerr_destroy_wq;
1442 }
1443 }
1444
1445 return 0;
1446
1447err_destroy_wq:
1448destroy_workqueue(host->mmc_omap_wq);
1449err_plat_cleanup:
1450 if (pdata->cleanup)
1451pdata->cleanup(&pdev->dev);
1452err_free_irq:
1453free_irq(host->irq, host);
1454err_free_dma:
1455 if (host->dma_tx)
1456dma_release_channel(host->dma_tx);
1457 if (host->dma_rx)
1458dma_release_channel(host->dma_rx);
1459clk_put(host->fclk);
1460err_free_iclk:
1461clk_disable(host->iclk);
1462clk_put(host->iclk);
1463err_free_mmc_host:
1464iounmap(host->virt_base);
1465err_ioremap:
1466 kfree(host);
1467err_free_mem_region:
Quoted 6 lines
1468 release_mem_region(res->start, resource_size(res)); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Existing unchecked dereferences.
1469 return ret;
1470 }
Oops. Thanks a lot for reporting this, I'll post a fix for it separately.
Looks like the minimal fix is to add what at least omap_hsmmc.c is doing:
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (res)
release_mem_region(res->start, resource_size(res));
Regards,
Tony