summaryrefslogtreecommitdiff
path: root/drivers/usb/core
diff options
context:
space:
mode:
authorWeitao Hou <houweitaoo@gmail.com>2019-05-23 19:52:08 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-05-24 09:53:24 +0200
commit086ebf92aa791b6cc8805decffca7b8898d99a4e (patch)
tree623da57e5879fac1bd3b057ea46958ee4ccbfd6c /drivers/usb/core
parent6e9aed4ed4ca129510fcb1af495391d4717246d6 (diff)
usb: avoid redundant allocation and free of memory
If usb is not attached, it's unnessary to allocate, copy and free memory Signed-off-by: Weitao Hou <houweitaoo@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/core')
-rw-r--r--drivers/usb/core/devio.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index fa783531ee88..aa17dab6c4ea 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -2130,6 +2130,9 @@ static int proc_ioctl(struct usb_dev_state *ps, struct usbdevfs_ioctl *ctl)
if (ps->privileges_dropped)
return -EACCES;
+ if (!connected(ps))
+ return -ENODEV;
+
/* alloc buffer */
size = _IOC_SIZE(ctl->ioctl_code);
if (size > 0) {
@@ -2146,11 +2149,6 @@ static int proc_ioctl(struct usb_dev_state *ps, struct usbdevfs_ioctl *ctl)
}
}
- if (!connected(ps)) {
- kfree(buf);
- return -ENODEV;
- }
-
if (ps->dev->state != USB_STATE_CONFIGURED)
retval = -EHOSTUNREACH;
else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno)))