From 71b0621e217ac51778320320fa31aa273e38e310 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christian=20L=C3=BCtke-Stetzkamp?= Date: Wed, 18 Apr 2018 17:27:33 +0200 Subject: [PATCH] staging: mt7621-mmc: Start cleanup of msdc_dma_config MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Currently the msdc_dma_config function has some variables, that are not needed, uses the macro msdc_init_bd that is only used here and does not use the for_each_sg iterator. That last fact could cause a bug if the scatterlist is chained. The function is changed to remove these things, but none of the changes should change the behavior of it (despite the case of a linked scatterlist). Signed-off-by: Christian Lütke-Stetzkamp Signed-off-by: Greg Kroah-Hartman --- drivers/staging/mt7621-mmc/sd.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c index e25aeede7059..9c800a0b8206 100644 --- a/drivers/staging/mt7621-mmc/sd.c +++ b/drivers/staging/mt7621-mmc/sd.c @@ -209,15 +209,6 @@ static int msdc_rsp[] = { ((struct gpd *)_gpd)->blknum = blknum; \ } while (0) -#define msdc_init_bd(_bd, blkpad, dwpad, dptr, dlen) \ - do { \ - BUG_ON(dlen > 0xFFFFUL); \ - ((struct bd *)_bd)->blkpad = blkpad; \ - ((struct bd *)_bd)->dwpad = dwpad; \ - ((struct bd *)_bd)->ptr = (void *)dptr; \ - ((struct bd *)_bd)->buflen = dlen; \ - } while (0) - #define msdc_txfifocnt() ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_TXCNT) >> 16) #define msdc_rxfifocnt() ((sdr_read32(MSDC_FIFOCS) & MSDC_FIFOCS_RXCNT) >> 0) #define msdc_fifo_write32(v) sdr_write32(MSDC_TXDATA, (v)) @@ -1260,9 +1251,8 @@ static u8 msdc_dma_calcs(u8 *buf, u32 len) static int msdc_dma_config(struct msdc_host *host, struct msdc_dma *dma) { u32 base = host->base; - u32 sglen = dma->sglen; //u32 i, j, num, bdlen, arg, xfersz; - u32 j, num, bdlen; + u32 j, num; u8 blkpad, dwpad, chksum; struct scatterlist *sg = dma->sg; struct gpd *gpd; @@ -1291,12 +1281,11 @@ static int msdc_dma_config(struct msdc_host *host, struct msdc_dma *dma) chksum = (dma->flags & DMA_FLAG_EN_CHKSUM) ? 1 : 0; /* calculate the required number of gpd */ - num = (sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD; + num = (dma->sglen + MAX_BD_PER_GPD - 1) / MAX_BD_PER_GPD; BUG_ON(num != 1); gpd = dma->gpd; bd = dma->bd; - bdlen = sglen; /* modify gpd*/ //gpd->intr = 0; @@ -1306,19 +1295,23 @@ static int msdc_dma_config(struct msdc_host *host, struct msdc_dma *dma) gpd->chksum = (chksum ? msdc_dma_calcs((u8 *)gpd, 16) : 0); /* modify bd*/ - for (j = 0; j < bdlen; j++) { - msdc_init_bd(&bd[j], blkpad, dwpad, sg_dma_address(sg), sg_dma_len(sg)); - if (j == bdlen - 1) + for_each_sg(dma->sg, sg, dma->sglen, j) { + bd[j].blkpad = blkpad; + bd[j].dwpad = dwpad; + bd[j].ptr = (void *)sg_dma_address(sg); + bd[j].buflen = sg_dma_len(sg); + + if (j == dma->sglen - 1) bd[j].eol = 1; /* the last bd */ else bd[j].eol = 0; + bd[j].chksum = 0; /* checksume need to clear first */ bd[j].chksum = (chksum ? msdc_dma_calcs((u8 *)(&bd[j]), 16) : 0); - sg++; } dma->used_gpd += 2; - dma->used_bd += bdlen; + dma->used_bd += dma->sglen; sdr_set_field(MSDC_DMA_CFG, MSDC_DMA_CFG_DECSEN, chksum); sdr_set_field(MSDC_DMA_CTRL, MSDC_DMA_CTRL_BRUSTSZ, -- 2.11.0