mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
staging:wlan-ng: use memdup_user instead of kmalloc/copy_from_user
memdup_user() is shorter and safer equivalent of kmalloc/copy_from_user pair. Signed-off-by: Ivan Safonov <insafonov@gmail.com> Link: https://lore.kernel.org/r/20210213120527.451531-1-insafonov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
b2591ab0c9
commit
bc4bf94cc2
@@ -569,24 +569,22 @@ static int p80211knetdev_do_ioctl(struct net_device *dev,
|
|||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate a buf of size req->len */
|
msgbuf = memdup_user(req->data, req->len);
|
||||||
msgbuf = kmalloc(req->len, GFP_KERNEL);
|
if (IS_ERR(msgbuf)) {
|
||||||
if (msgbuf) {
|
result = PTR_ERR(msgbuf);
|
||||||
if (copy_from_user(msgbuf, (void __user *)req->data, req->len))
|
goto bail;
|
||||||
result = -EFAULT;
|
|
||||||
else
|
|
||||||
result = p80211req_dorequest(wlandev, msgbuf);
|
|
||||||
|
|
||||||
if (result == 0) {
|
|
||||||
if (copy_to_user
|
|
||||||
((void __user *)req->data, msgbuf, req->len)) {
|
|
||||||
result = -EFAULT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
kfree(msgbuf);
|
|
||||||
} else {
|
|
||||||
result = -ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = p80211req_dorequest(wlandev, msgbuf);
|
||||||
|
|
||||||
|
if (result == 0) {
|
||||||
|
if (copy_to_user
|
||||||
|
((void __user *)req->data, msgbuf, req->len)) {
|
||||||
|
result = -EFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kfree(msgbuf);
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
/* If allocate,copyfrom or copyto fails, return errno */
|
/* If allocate,copyfrom or copyto fails, return errno */
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user