Hello Konrad Dybcio,

Commit 5a903a44a984 ("drm/msm/a6xx: Introduce GMU wrapper support")
from Jun 16, 2023 (linux-next), leads to the following Smatch static
checker warning:

        drivers/gpu/drm/msm/adreno/a6xx_gmu.c:1844 a6xx_gmu_wrapper_init()
        warn: 'gmu->cxpd' can also be NULL

drivers/gpu/drm/msm/adreno/a6xx_gmu.c
    1790 int a6xx_gmu_wrapper_init(struct a6xx_gpu *a6xx_gpu, struct 
device_node *node)
    1791 {
    1792         struct platform_device *pdev = of_find_device_by_node(node);
    1793         struct a6xx_gmu *gmu = &a6xx_gpu->gmu;
    1794         int ret;
    1795 
    1796         if (!pdev)
    1797                 return -ENODEV;
    1798 
    1799         gmu->dev = &pdev->dev;
    1800 
    1801         ret = of_dma_configure(gmu->dev, node, true);
    1802         if (ret)
    1803                 return ret;
    1804 
    1805         pm_runtime_enable(gmu->dev);
    1806 
    1807         /* Mark legacy for manual SPTPRAC control */
    1808         gmu->legacy = true;
    1809 
    1810         /* Map the GMU registers */
    1811         gmu->mmio = a6xx_gmu_get_mmio(pdev, "gmu");
    1812         if (IS_ERR(gmu->mmio)) {
    1813                 ret = PTR_ERR(gmu->mmio);
    1814                 goto err_mmio;
    1815         }
    1816 
    1817         gmu->cxpd = dev_pm_domain_attach_by_name(gmu->dev, "cx");

dev_pm_domain_attach_by_name() sure seemse like it can return NULL.

    1818         if (IS_ERR(gmu->cxpd)) {
    1819                 ret = PTR_ERR(gmu->cxpd);
    1820                 goto err_mmio;
    1821         }
    1822 
    1823         if (!device_link_add(gmu->dev, gmu->cxpd, DL_FLAG_PM_RUNTIME)) 
{

If it did then device_link_add() then this would fail

    1824                 ret = -ENODEV;
    1825                 goto detach_cxpd;
    1826         }
    1827 
    1828         init_completion(&gmu->pd_gate);
    1829         complete_all(&gmu->pd_gate);
    1830         gmu->pd_nb.notifier_call = cxpd_notifier_cb;
    1831 
    1832         /* Get a link to the GX power domain to reset the GPU */
    1833         gmu->gxpd = dev_pm_domain_attach_by_name(gmu->dev, "gx");
    1834         if (IS_ERR(gmu->gxpd)) {
    1835                 ret = PTR_ERR(gmu->gxpd);
    1836                 goto err_mmio;
    1837         }
    1838 
    1839         gmu->initialized = true;
    1840 
    1841         return 0;
    1842 
    1843 detach_cxpd:
--> 1844         dev_pm_domain_detach(gmu->cxpd, false);
                                      ^^^^^^^^^
And this would crash.

    1845 
    1846 err_mmio:
    1847         iounmap(gmu->mmio);
    1848 
    1849         /* Drop reference taken in of_find_device_by_node */
    1850         put_device(gmu->dev);
    1851 
    1852         return ret;
    1853 }

regards,
dan carpenter

Reply via email to