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 * your option) any later version. 10 */ 11 12 #include <linux/types.h> 13 #include <linux/scatterlist.h> 14 ··· 253 struct mmc_command cmd; 254 struct mmc_data data; 255 struct scatterlist sg; 256 257 BUG_ON(!card); 258 BUG_ON(!card->host); ··· 264 err = mmc_app_cmd(card->host, card); 265 if (err) 266 return err; 267 268 memset(&mrq, 0, sizeof(struct mmc_request)); 269 memset(&cmd, 0, sizeof(struct mmc_command)); ··· 289 data.sg = &sg; 290 data.sg_len = 1; 291 292 - sg_init_one(&sg, scr, 8); 293 294 mmc_set_data_timeout(&data, card); 295 296 mmc_wait_for_req(card->host, &mrq); 297 298 if (cmd.error) 299 return cmd.error;
··· 9 * your option) any later version. 10 */ 11 12 + #include <linux/slab.h> 13 #include <linux/types.h> 14 #include <linux/scatterlist.h> 15 ··· 252 struct mmc_command cmd; 253 struct mmc_data data; 254 struct scatterlist sg; 255 + void *data_buf; 256 257 BUG_ON(!card); 258 BUG_ON(!card->host); ··· 262 err = mmc_app_cmd(card->host, card); 263 if (err) 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; 272 273 memset(&mrq, 0, sizeof(struct mmc_request)); 274 memset(&cmd, 0, sizeof(struct mmc_command)); ··· 280 data.sg = &sg; 281 data.sg_len = 1; 282 283 + sg_init_one(&sg, data_buf, 8); 284 285 mmc_set_data_timeout(&data, card); 286 287 mmc_wait_for_req(card->host, &mrq); 288 + 289 + memcpy(scr, data_buf, sizeof(card->raw_scr)); 290 + kfree(data_buf); 291 292 if (cmd.error) 293 return cmd.error;