Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Staging: bcm: Use memdup_user rather than duplicating its implementation

This is a little bit restricted to reduce false positives

The semantic patch that makes this change is available
in scripts/coccinelle/api/memdup_user.cocci.

More information about semantic patching is available at
http://coccinelle.lip6.fr/

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Meyer and committed by
Greg Kroah-Hartman
2d9ebe77 5cf4d6b9

+12 -25
+12 -25
drivers/staging/bcm/Bcmchar.c
··· 728 728 if (IoBuffer.InputLength > MAX_CNTL_PKT_SIZE) 729 729 return -EINVAL; 730 730 731 - pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL); 732 - if (!pvBuffer) 733 - return -ENOMEM; 734 - 735 - if (copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) { 736 - kfree(pvBuffer); 737 - return -EFAULT; 738 - } 731 + pvBuffer = memdup_user(IoBuffer.InputBuffer, 732 + IoBuffer.InputLength); 733 + if (IS_ERR(pvBuffer)) 734 + return PTR_ERR(pvBuffer); 739 735 740 736 down(&Adapter->LowPowerModeSync); 741 737 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, ··· 1136 1140 if (IoBuffer.InputLength < sizeof(ULONG) * 2) 1137 1141 return -EINVAL; 1138 1142 1139 - pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL); 1140 - if (!pvBuffer) 1141 - return -ENOMEM; 1142 - 1143 - /* Get WrmBuffer structure */ 1144 - if (copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) { 1145 - kfree(pvBuffer); 1146 - return -EFAULT; 1147 - } 1143 + pvBuffer = memdup_user(IoBuffer.InputBuffer, 1144 + IoBuffer.InputLength); 1145 + if (IS_ERR(pvBuffer)) 1146 + return PTR_ERR(pvBuffer); 1148 1147 1149 1148 pBulkBuffer = (PBULKWRM_BUFFER)pvBuffer; 1150 1149 ··· 1301 1310 return STATUS_FAILURE; 1302 1311 } 1303 1312 1304 - pReadData = kzalloc(stNVMReadWrite.uiNumBytes, GFP_KERNEL); 1305 - if (!pReadData) 1306 - return -ENOMEM; 1307 - 1308 - if (copy_from_user(pReadData, stNVMReadWrite.pBuffer, stNVMReadWrite.uiNumBytes)) { 1309 - kfree(pReadData); 1310 - return -EFAULT; 1311 - } 1313 + pReadData = memdup_user(stNVMReadWrite.pBuffer, 1314 + stNVMReadWrite.uiNumBytes); 1315 + if (IS_ERR(pReadData)) 1316 + return PTR_ERR(pReadData); 1312 1317 1313 1318 do_gettimeofday(&tv0); 1314 1319 if (IOCTL_BCM_NVM_READ == cmd) {