LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] usb: avoid redundant allocation and free of memory
@ 2019-05-23 11:52 Weitao Hou
0 siblings, 0 replies; only message in thread
From: Weitao Hou @ 2019-05-23 11:52 UTC (permalink / raw)
To: gregkh, oneukum, stern, chunfeng.yun, ebiederm, bigeasy,
iamkeyur96, keescook, houweitaoo
Cc: linux-usb, linux-kernel
If usb is not attached, it's unnessary to allocate, copy
and free memory
Signed-off-by: Weitao Hou <houweitaoo@gmail.com>
---
drivers/usb/core/devio.c | 8 +++-----
1 file 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)))
--
2.18.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-05-23 11:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-23 11:52 [PATCH] usb: avoid redundant allocation and free of memory Weitao Hou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).