mmc: fix mmc_app_send_scr() for dma transfer

This patch is based on the commit "af51715079e7fb6b290e1881d63d815dc4de5011":

* Bugfix to that mmc_send_cxd_data() code: dma-to-stack is
unsafe/nonportable, so kmalloc a bounce buffer instead.

The driver may invalidate the mmc_card->csd when host driver uses dma.
So this subroutine also needs a kmalloc buffer.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Chris Ball <cjb@laptop.org>

authored by Yoshihiro Shimoda and committed by Chris Ball 4f665cb6 58ac8177

+13 -1
+13 -1
drivers/mmc/core/sd_ops.c
··· 9 9 * your option) any later version. 10 10 */ 11 11 12 + #include <linux/slab.h> 12 13 #include <linux/types.h> 13 14 #include <linux/scatterlist.h> 14 15 ··· 253 252 struct mmc_command cmd; 254 253 struct mmc_data data; 255 254 struct scatterlist sg; 255 + void *data_buf; 256 256 257 257 BUG_ON(!card); 258 258 BUG_ON(!card->host); ··· 264 262 err = mmc_app_cmd(card->host, card); 265 263 if (err) 266 264 return err; 265 + 266 + /* dma onto stack is unsafe/nonportable, but callers to this 267 + * routine normally provide temporary on-stack buffers ... 268 + */ 269 + data_buf = kmalloc(sizeof(card->raw_scr), GFP_KERNEL); 270 + if (data_buf == NULL) 271 + return -ENOMEM; 267 272 268 273 memset(&mrq, 0, sizeof(struct mmc_request)); 269 274 memset(&cmd, 0, sizeof(struct mmc_command)); ··· 289 280 data.sg = &sg; 290 281 data.sg_len = 1; 291 282 292 - sg_init_one(&sg, scr, 8); 283 + sg_init_one(&sg, data_buf, 8); 293 284 294 285 mmc_set_data_timeout(&data, card); 295 286 296 287 mmc_wait_for_req(card->host, &mrq); 288 + 289 + memcpy(scr, data_buf, sizeof(card->raw_scr)); 290 + kfree(data_buf); 297 291 298 292 if (cmd.error) 299 293 return cmd.error;