[bug report] mtd: rawnand: lpx32xx: Request DMA channels using DT entries

Dan Carpenter dan.carpenter at linaro.org
Thu Jul 4 08:21:25 PDT 2024


Hello Piotr Wojtaszczyk,

Commit 7326d3fb1ee3 ("mtd: rawnand: lpx32xx: Request DMA channels
using DT entries") from Jun 27, 2024 (linux-next), leads to the
following Smatch static checker warning:

	drivers/mtd/nand/raw/lpc32xx_mlc.c:609 lpc32xx_dma_setup()
	error: 'host->dma_chan' dereferencing possible ERR_PTR()

drivers/mtd/nand/raw/lpc32xx_mlc.c
    572 static int lpc32xx_dma_setup(struct lpc32xx_nand_host *host)
    573 {
    574         struct mtd_info *mtd = nand_to_mtd(&host->nand_chip);
    575         dma_cap_mask_t mask;
    576 
    577         host->dma_chan = dma_request_chan(mtd->dev.parent, "rx-tx");
                                 ^^^^^^^^^^^^^^^^

    578         if (!host->dma_chan) {

Why do we have two functions called dma_request_chan/channel()???  Confusing.
Anyway, the _chan() function returns error pointers and the _channel() function
returns NULL.  So this check is wrong.

    579                 /* fallback to request using platform data */
    580                 if (!host->pdata || !host->pdata->dma_filter) {
    581                         dev_err(mtd->dev.parent, "no DMA platform data\n");
    582                         return -ENOENT;
    583                 }
    584 
    585                 dma_cap_zero(mask);
    586                 dma_cap_set(DMA_SLAVE, mask);
    587                 host->dma_chan = dma_request_channel(mask, host->pdata->dma_filter, "nand-mlc");
                                         ^^^^^^^^^^^^^^^^^^^

    588 
    589                 if (!host->dma_chan) {
    590                         dev_err(mtd->dev.parent, "Failed to request DMA channel\n");
    591                         return -EBUSY;
    592                 }
    593         }
    594 
    595         /*
    596          * Set direction to a sensible value even if the dmaengine driver
    597          * should ignore it. With the default (DMA_MEM_TO_MEM), the amba-pl08x
    598          * driver criticizes it as "alien transfer direction".
    599          */
    600         host->dma_slave_config.direction = DMA_DEV_TO_MEM;
    601         host->dma_slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
    602         host->dma_slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
    603         host->dma_slave_config.src_maxburst = 128;
    604         host->dma_slave_config.dst_maxburst = 128;
    605         /* DMA controller does flow control: */
    606         host->dma_slave_config.device_fc = false;
    607         host->dma_slave_config.src_addr = MLC_BUFF(host->io_base_phy);
    608         host->dma_slave_config.dst_addr = MLC_BUFF(host->io_base_phy);
--> 609         if (dmaengine_slave_config(host->dma_chan, &host->dma_slave_config)) {
    610                 dev_err(mtd->dev.parent, "Failed to setup DMA slave\n");
    611                 goto out1;
    612         }
    613 
    614         return 0;
    615 out1:
    616         dma_release_channel(host->dma_chan);
    617         return -ENXIO;
    618 }

regards,
dan carpenter



More information about the linux-mtd mailing list