Skip to content

Commit 4f665cb

Browse files
shimodaycjb
authored andcommitted
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 <[email protected]> Signed-off-by: Chris Ball <[email protected]>
1 parent 58ac817 commit 4f665cb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

drivers/mmc/core/sd_ops.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* your option) any later version.
1010
*/
1111

12+
#include <linux/slab.h>
1213
#include <linux/types.h>
1314
#include <linux/scatterlist.h>
1415

@@ -252,6 +253,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
252253
struct mmc_command cmd;
253254
struct mmc_data data;
254255
struct scatterlist sg;
256+
void *data_buf;
255257

256258
BUG_ON(!card);
257259
BUG_ON(!card->host);
@@ -263,6 +265,13 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
263265
if (err)
264266
return err;
265267

268+
/* dma onto stack is unsafe/nonportable, but callers to this
269+
* routine normally provide temporary on-stack buffers ...
270+
*/
271+
data_buf = kmalloc(sizeof(card->raw_scr), GFP_KERNEL);
272+
if (data_buf == NULL)
273+
return -ENOMEM;
274+
266275
memset(&mrq, 0, sizeof(struct mmc_request));
267276
memset(&cmd, 0, sizeof(struct mmc_command));
268277
memset(&data, 0, sizeof(struct mmc_data));
@@ -280,12 +289,15 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
280289
data.sg = &sg;
281290
data.sg_len = 1;
282291

283-
sg_init_one(&sg, scr, 8);
292+
sg_init_one(&sg, data_buf, 8);
284293

285294
mmc_set_data_timeout(&data, card);
286295

287296
mmc_wait_for_req(card->host, &mrq);
288297

298+
memcpy(scr, data_buf, sizeof(card->raw_scr));
299+
kfree(data_buf);
300+
289301
if (cmd.error)
290302
return cmd.error;
291303
if (data.error)

0 commit comments

Comments
 (0)