aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/storage
diff options
context:
space:
mode:
authorAdam Cozzette <acozzette@cs.hmc.edu>2011-08-24 14:22:37 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-08-24 18:06:54 -0400
commit065e60964e293227e4feb0c1f7e27e609316ed9a (patch)
tree96aa9ca56c7faeeaf2d3d25dfc2b1a0312ae7bcf /drivers/usb/storage
parent5de9ec4dc10e1a39b924fb165bcb3ddb6e8e6525 (diff)
ums_realtek: do not use stack memory for DMA
This patch changes rts51x_read_mem, rts51x_write_mem, and rts51x_read_status to allocate temporary buffers with kmalloc. This way stack addresses are not used for DMA when these functions call rts51x_bulk_transport. Signed-off-by: Adam Cozzette <acozzette@cs.hmc.edu> Cc: stable <stable@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/storage')
-rw-r--r--drivers/usb/storage/realtek_cr.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
index 34adc4b42ceb..232167ad4781 100644
--- a/drivers/usb/storage/realtek_cr.c
+++ b/drivers/usb/storage/realtek_cr.c
@@ -320,6 +320,11 @@ static int rts51x_read_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
320{ 320{
321 int retval; 321 int retval;
322 u8 cmnd[12] = { 0 }; 322 u8 cmnd[12] = { 0 };
323 u8 *buf;
324
325 buf = kmalloc(len, GFP_NOIO);
326 if (buf == NULL)
327 return USB_STOR_TRANSPORT_ERROR;
323 328
324 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len); 329 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len);
325 330
@@ -331,10 +336,14 @@ static int rts51x_read_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
331 cmnd[5] = (u8) len; 336 cmnd[5] = (u8) len;
332 337
333 retval = rts51x_bulk_transport(us, 0, cmnd, 12, 338 retval = rts51x_bulk_transport(us, 0, cmnd, 12,
334 data, len, DMA_FROM_DEVICE, NULL); 339 buf, len, DMA_FROM_DEVICE, NULL);
335 if (retval != USB_STOR_TRANSPORT_GOOD) 340 if (retval != USB_STOR_TRANSPORT_GOOD) {
341 kfree(buf);
336 return -EIO; 342 return -EIO;
343 }
337 344
345 memcpy(data, buf, len);
346 kfree(buf);
338 return 0; 347 return 0;
339} 348}
340 349
@@ -342,6 +351,12 @@ static int rts51x_write_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
342{ 351{
343 int retval; 352 int retval;
344 u8 cmnd[12] = { 0 }; 353 u8 cmnd[12] = { 0 };
354 u8 *buf;
355
356 buf = kmalloc(len, GFP_NOIO);
357 if (buf == NULL)
358 return USB_STOR_TRANSPORT_ERROR;
359 memcpy(buf, data, len);
345 360
346 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len); 361 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len);
347 362
@@ -353,7 +368,8 @@ static int rts51x_write_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
353 cmnd[5] = (u8) len; 368 cmnd[5] = (u8) len;
354 369
355 retval = rts51x_bulk_transport(us, 0, cmnd, 12, 370 retval = rts51x_bulk_transport(us, 0, cmnd, 12,
356 data, len, DMA_TO_DEVICE, NULL); 371 buf, len, DMA_TO_DEVICE, NULL);
372 kfree(buf);
357 if (retval != USB_STOR_TRANSPORT_GOOD) 373 if (retval != USB_STOR_TRANSPORT_GOOD)
358 return -EIO; 374 return -EIO;
359 375
@@ -365,6 +381,11 @@ static int rts51x_read_status(struct us_data *us,
365{ 381{
366 int retval; 382 int retval;
367 u8 cmnd[12] = { 0 }; 383 u8 cmnd[12] = { 0 };
384 u8 *buf;
385
386 buf = kmalloc(len, GFP_NOIO);
387 if (buf == NULL)
388 return USB_STOR_TRANSPORT_ERROR;
368 389
369 US_DEBUGP("%s, lun = %d\n", __func__, lun); 390 US_DEBUGP("%s, lun = %d\n", __func__, lun);
370 391
@@ -372,10 +393,14 @@ static int rts51x_read_status(struct us_data *us,
372 cmnd[1] = 0x09; 393 cmnd[1] = 0x09;
373 394
374 retval = rts51x_bulk_transport(us, lun, cmnd, 12, 395 retval = rts51x_bulk_transport(us, lun, cmnd, 12,
375 status, len, DMA_FROM_DEVICE, actlen); 396 buf, len, DMA_FROM_DEVICE, actlen);
376 if (retval != USB_STOR_TRANSPORT_GOOD) 397 if (retval != USB_STOR_TRANSPORT_GOOD) {
398 kfree(buf);
377 return -EIO; 399 return -EIO;
400 }
378 401
402 memcpy(status, buf, len);
403 kfree(buf);
379 return 0; 404 return 0;
380} 405}
381 406