[bug report] net: ethernet: mtk_eth_soc: add support for coherent DMA

Dan Carpenter dan.carpenter at linaro.org
Fri Jul 19 16:52:40 PDT 2024


Hello Felix Fietkau,

Commit d776a57e4a28 ("net: ethernet: mtk_eth_soc: add support for
coherent DMA") from Apr 5, 2022 (linux-next), leads to the following
Smatch static checker warning:

	drivers/net/ethernet/mediatek/mtk_eth_soc.c:3927 mtk_hw_init()
	error: we previously assumed 'eth->ethsys' could be null (see line 3902)

drivers/net/ethernet/mediatek/mtk_eth_soc.c
    3883 static int mtk_hw_init(struct mtk_eth *eth, bool reset)
    3884 {
    3885         u32 dma_mask = ETHSYS_DMA_AG_MAP_PDMA | ETHSYS_DMA_AG_MAP_QDMA |
    3886                        ETHSYS_DMA_AG_MAP_PPE;
    3887         const struct mtk_reg_map *reg_map = eth->soc->reg_map;
    3888         int i, val, ret;
    3889 
    3890         if (!reset && test_and_set_bit(MTK_HW_INIT, &eth->state))
    3891                 return 0;
    3892 
    3893         if (!reset) {
    3894                 pm_runtime_enable(eth->dev);
    3895                 pm_runtime_get_sync(eth->dev);
    3896 
    3897                 ret = mtk_clk_enable(eth);
    3898                 if (ret)
    3899                         goto err_disable_pm;
    3900         }
    3901 
    3902         if (eth->ethsys)
                     ^^^^^^^^^^^
Check for NULL

    3903                 regmap_update_bits(eth->ethsys, ETHSYS_DMA_AG_MAP, dma_mask,
    3904                                    of_dma_is_coherent(eth->dma_dev->of_node) * dma_mask);
    3905 
    3906         if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) {
    3907                 ret = device_reset(eth->dev);
    3908                 if (ret) {
    3909                         dev_err(eth->dev, "MAC reset failed!\n");
    3910                         goto err_disable_pm;
    3911                 }
    3912 
    3913                 /* set interrupt delays based on current Net DIM sample */
    3914                 mtk_dim_rx(&eth->rx_dim.work);
    3915                 mtk_dim_tx(&eth->tx_dim.work);
    3916 
    3917                 /* disable delay and normal interrupt */
    3918                 mtk_tx_irq_disable(eth, ~0);
    3919                 mtk_rx_irq_disable(eth, ~0);
    3920 
    3921                 return 0;
    3922         }
    3923 
    3924         msleep(100);
    3925 
    3926         if (reset)
--> 3927                 mtk_hw_warm_reset(eth);
    3928         else
    3929                 mtk_hw_reset(eth);

Either of these reset functions is going to dereference eth->ethsys without
checking.

regards,
dan carpenter



More information about the Linux-mediatek mailing list