Improve rz_dmac_prepare_descs_for_slave_sg() by replacing the loop for->for_each_sg and drop the variables sgl and sg_len. Also, assign lmdesc along with the declaration and improve the logic for assigning lmdesc->chcfg and lmdesc->header. Signed-off-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx> --- v2->v3: * Assign header after chcfg to make sure there is no code flow change. * Updated commit description. v2: * New patch. --- drivers/dma/sh/rz-dmac.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 153893045932..7c75ff314ea3 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -342,12 +342,12 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_dmac_chan *channel) static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel) { + struct rz_lmdesc *lmdesc = channel->lmdesc.tail; struct dma_chan *chan = &channel->vc.chan; struct rz_dmac *dmac = to_rz_dmac(chan->device); struct rz_dmac_desc *d = channel->desc; - struct scatterlist *sg, *sgl = d->sg; - struct rz_lmdesc *lmdesc; - unsigned int i, sg_len = d->sgcount; + struct scatterlist *sg; + unsigned int i; channel->chcfg |= CHCFG_SEL(channel->index) | CHCFG_DEM | CHCFG_DMS; @@ -358,9 +358,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel) channel->chcfg |= CHCFG_DAD | CHCFG_REQD; } - lmdesc = channel->lmdesc.tail; - - for (i = 0, sg = sgl; i < sg_len; i++, sg = sg_next(sg)) { + for_each_sg(d->sg, sg, d->sgcount, i) { if (d->direction == DMA_DEV_TO_MEM) { lmdesc->sa = channel->src_per_address; lmdesc->da = sg_dma_address(sg); @@ -372,13 +370,11 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel) lmdesc->tb = sg_dma_len(sg); lmdesc->chitvl = 0; lmdesc->chext = 0; - if (i == (sg_len - 1)) { - lmdesc->chcfg = (channel->chcfg & ~CHCFG_DEM); - lmdesc->header = HEADER_LV; - } else { - lmdesc->chcfg = channel->chcfg; - lmdesc->header = HEADER_LV; - } + lmdesc->chcfg = channel->chcfg; + if (i == (d->sgcount - 1)) + lmdesc->chcfg &= ~CHCFG_DEM; + + lmdesc->header = HEADER_LV; if (++lmdesc >= (channel->lmdesc.base + DMAC_NR_LMDESC)) lmdesc = channel->lmdesc.base; } -- 2.25.1