[PATCH v2] mmc: meson: Add driver for the SD/MMC host found on Amlogic MesonX SoCs

Daniel Drake drake at endlessm.com
Wed Jun 10 06:44:27 PDT 2015


On Wed, Jun 10, 2015 at 2:53 AM, Carlo Caione <carlo at caione.org> wrote:
> +static int meson_mmc_map_dma(struct meson_mmc_host *host,
> +                            struct mmc_data *data,
> +                            unsigned int flags)
> +{      u32 i, dma_len;
> +       struct scatterlist *sg;
> +
> +       dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
> +                            ((data->flags & MMC_DATA_READ) ?
> +                            DMA_FROM_DEVICE : DMA_TO_DEVICE));
> +       if (dma_len == 0) {
> +               dev_err(mmc_dev(host->mmc), "dma_map_sg failed\n");
> +               return -ENOMEM;
> +       }
> +
> +       for_each_sg(data->sg, sg, data->sg_len, i) {
> +               if (sg->offset & 3 || sg->length & 3) {
> +                       dev_err(mmc_dev(host->mmc),
> +                               "unaligned scatterlist: os %x length %d\n",
> +                               sg->offset, sg->length);
> +                       return -EINVAL;
> +               }
> +       }

If the offset/length check fails here, do you leak the DMA mapping?
If so, can you do the offset/length check first to avoid that?

There should only ever be 1 entry in the scatterlist, right? In that
case you can do a simple check there, and then instead of looping,
just check the first entry in the scatterlist.

Daniel



More information about the linux-arm-kernel mailing list