Commit 2d9ebe77 authored by Thomas Meyer's avatar Thomas Meyer Committed by Greg Kroah-Hartman

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: default avatarThomas Meyer <thomas@m3y3r.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5cf4d6b9
...@@ -728,14 +728,10 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg) ...@@ -728,14 +728,10 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
if (IoBuffer.InputLength > MAX_CNTL_PKT_SIZE) if (IoBuffer.InputLength > MAX_CNTL_PKT_SIZE)
return -EINVAL; return -EINVAL;
pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL); pvBuffer = memdup_user(IoBuffer.InputBuffer,
if (!pvBuffer) IoBuffer.InputLength);
return -ENOMEM; if (IS_ERR(pvBuffer))
return PTR_ERR(pvBuffer);
if (copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) {
kfree(pvBuffer);
return -EFAULT;
}
down(&Adapter->LowPowerModeSync); down(&Adapter->LowPowerModeSync);
Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
...@@ -1140,15 +1136,10 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg) ...@@ -1140,15 +1136,10 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
if (IoBuffer.InputLength < sizeof(ULONG) * 2) if (IoBuffer.InputLength < sizeof(ULONG) * 2)
return -EINVAL; return -EINVAL;
pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL); pvBuffer = memdup_user(IoBuffer.InputBuffer,
if (!pvBuffer) IoBuffer.InputLength);
return -ENOMEM; if (IS_ERR(pvBuffer))
return PTR_ERR(pvBuffer);
/* Get WrmBuffer structure */
if (copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) {
kfree(pvBuffer);
return -EFAULT;
}
pBulkBuffer = (PBULKWRM_BUFFER)pvBuffer; pBulkBuffer = (PBULKWRM_BUFFER)pvBuffer;
...@@ -1310,14 +1301,10 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg) ...@@ -1310,14 +1301,10 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
return STATUS_FAILURE; return STATUS_FAILURE;
} }
pReadData = kzalloc(stNVMReadWrite.uiNumBytes, GFP_KERNEL); pReadData = memdup_user(stNVMReadWrite.pBuffer,
if (!pReadData) stNVMReadWrite.uiNumBytes);
return -ENOMEM; if (IS_ERR(pReadData))
return PTR_ERR(pReadData);
if (copy_from_user(pReadData, stNVMReadWrite.pBuffer, stNVMReadWrite.uiNumBytes)) {
kfree(pReadData);
return -EFAULT;
}
do_gettimeofday(&tv0); do_gettimeofday(&tv0);
if (IOCTL_BCM_NVM_READ == cmd) { if (IOCTL_BCM_NVM_READ == cmd) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment