* USB: core: devio: fixed a trailing statement code style issue
@ 2018-08-12 18:06 Tom Todd
0 siblings, 0 replies; 3+ messages in thread
From: Tom Todd @ 2018-08-12 18:06 UTC (permalink / raw)
To: gregkh
Cc: stern, dan.carpenter, arvind.yadav.cs, thomas.m.a.todd, linux-usb,
linux-kernel
Fixed a code styling issue
Signed-off-by: Tom Todd <thomas.m.a.todd@gmail.com>
---
drivers/usb/core/devio.c | 57 ++++++++++++++++++++--------------------
1 file changed, 29 insertions(+), 28 deletions(-)
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 476dcc5f2da3..118a29349b1d 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -2139,38 +2139,39 @@ static int proc_ioctl(struct usb_dev_state *ps, struct usbdevfs_ioctl *ctl)
retval = -EHOSTUNREACH;
else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno)))
retval = -EINVAL;
- else switch (ctl->ioctl_code) {
-
- /* disconnect kernel driver from interface */
- case USBDEVFS_DISCONNECT:
- if (intf->dev.driver) {
- driver = to_usb_driver(intf->dev.driver);
- dev_dbg(&intf->dev, "disconnect by usbfs\n");
- usb_driver_release_interface(driver, intf);
- } else
- retval = -ENODATA;
- break;
+ else
+ switch (ctl->ioctl_code) {
+
+ /* disconnect kernel driver from interface */
+ case USBDEVFS_DISCONNECT:
+ if (intf->dev.driver) {
+ driver = to_usb_driver(intf->dev.driver);
+ dev_dbg(&intf->dev, "disconnect by usbfs\n");
+ usb_driver_release_interface(driver, intf);
+ } else
+ retval = -ENODATA;
+ break;
- /* let kernel drivers try to (re)bind to the interface */
- case USBDEVFS_CONNECT:
- if (!intf->dev.driver)
- retval = device_attach(&intf->dev);
- else
- retval = -EBUSY;
- break;
+ /* let kernel drivers try to (re)bind to the interface */
+ case USBDEVFS_CONNECT:
+ if (!intf->dev.driver)
+ retval = device_attach(&intf->dev);
+ else
+ retval = -EBUSY;
+ break;
- /* talk directly to the interface's driver */
- default:
- if (intf->dev.driver)
- driver = to_usb_driver(intf->dev.driver);
- if (driver == NULL || driver->unlocked_ioctl == NULL) {
- retval = -ENOTTY;
- } else {
- retval = driver->unlocked_ioctl(intf, ctl->ioctl_code, buf);
- if (retval == -ENOIOCTLCMD)
+ /* talk directly to the interface's driver */
+ default:
+ if (intf->dev.driver)
+ driver = to_usb_driver(intf->dev.driver);
+ if (driver == NULL || driver->unlocked_ioctl == NULL) {
retval = -ENOTTY;
+ } else {
+ retval = driver->unlocked_ioctl(intf, ctl->ioctl_code, buf);
+ if (retval == -ENOIOCTLCMD)
+ retval = -ENOTTY;
+ }
}
- }
/* cleanup and return */
if (retval >= 0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* USB: core: devio: fixed a trailing statement code style issue
@ 2018-08-12 18:34 Joe Perches
0 siblings, 0 replies; 3+ messages in thread
From: Joe Perches @ 2018-08-12 18:34 UTC (permalink / raw)
To: Tom Todd, gregkh
Cc: stern, dan.carpenter, arvind.yadav.cs, linux-usb, linux-kernel
On Sun, 2018-08-12 at 19:06 +0100, Tom Todd wrote:
> Fixed a code styling issue
while it's OK to fix style only issues, it's much better
to reorganize the code for reader clarity.
For this code, something like:
o use memdup_user
o use an exit label to free allocated memory
o invert tests to return on unexpected results
o move logical continuations to EOL
o don't use successive code like:
if (foo)
return -ERRNO;
else if (bar)
return -ERRNO;
else
baz;
simpler and less indentation is:
if (foo)
return -ERRNO;
if (bar)
return -ERRNO;
baz;
---
drivers/usb/core/devio.c | 68 ++++++++++++++++++++++++++----------------------
1 file changed, 37 insertions(+), 31 deletions(-)
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 6ce77b33da61..74ae4e052357 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -2118,68 +2118,74 @@ static int proc_ioctl(struct usb_dev_state *ps, struct usbdevfs_ioctl *ctl)
/* alloc buffer */
size = _IOC_SIZE(ctl->ioctl_code);
if (size > 0) {
- buf = kmalloc(size, GFP_KERNEL);
- if (buf == NULL)
- return -ENOMEM;
- if ((_IOC_DIR(ctl->ioctl_code) & _IOC_WRITE)) {
- if (copy_from_user(buf, ctl->data, size)) {
- kfree(buf);
+ if (_IOC_DIR(ctl->ioctl_code) & _IOC_WRITE) {
+ buf = memdup_user(ctl->data, size);
+ if (!buf)
return -EFAULT;
- }
} else {
- memset(buf, 0, size);
+ buf = kzalloc(size, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
}
}
if (!connected(ps)) {
- kfree(buf);
- return -ENODEV;
+ retval = -ENODEV;
+ goto exit;
}
-
- if (ps->dev->state != USB_STATE_CONFIGURED)
+ if (ps->dev->state != USB_STATE_CONFIGURED) {
retval = -EHOSTUNREACH;
- else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno)))
+ goto exit;
+ }
+ intf = usb_ifnum_to_if(ps->dev, ctl->ifno);
+ if (!intf) {
retval = -EINVAL;
- else switch (ctl->ioctl_code) {
+ goto exit;
+ }
+ switch (ctl->ioctl_code) {
/* disconnect kernel driver from interface */
case USBDEVFS_DISCONNECT:
- if (intf->dev.driver) {
- driver = to_usb_driver(intf->dev.driver);
- dev_dbg(&intf->dev, "disconnect by usbfs\n");
- usb_driver_release_interface(driver, intf);
- } else
+ if (!intf->dev.driver) {
retval = -ENODATA;
+ goto exit;
+ }
+ driver = to_usb_driver(intf->dev.driver);
+ dev_dbg(&intf->dev, "disconnect by usbfs\n");
+ usb_driver_release_interface(driver, intf);
break;
/* let kernel drivers try to (re)bind to the interface */
case USBDEVFS_CONNECT:
- if (!intf->dev.driver)
- retval = device_attach(&intf->dev);
- else
+ if (!intf->dev.driver) {
retval = -EBUSY;
+ goto exit;
+ }
+ retval = device_attach(&intf->dev);
break;
/* talk directly to the interface's driver */
default:
if (intf->dev.driver)
driver = to_usb_driver(intf->dev.driver);
- if (driver == NULL || driver->unlocked_ioctl == NULL) {
+ if (!driver || !driver->unlocked_ioctl) {
retval = -ENOTTY;
- } else {
- retval = driver->unlocked_ioctl(intf, ctl->ioctl_code, buf);
- if (retval == -ENOIOCTLCMD)
- retval = -ENOTTY;
+ goto exit;
+ }
+ retval = driver->unlocked_ioctl(intf, ctl->ioctl_code, buf);
+ if (retval == -ENOIOCTLCMD) {
+ retval = -ENOTTY;
+ goto exit;
}
+ break;
}
/* cleanup and return */
- if (retval >= 0
- && (_IOC_DIR(ctl->ioctl_code) & _IOC_READ) != 0
- && size > 0
- && copy_to_user(ctl->data, buf, size) != 0)
+ if (retval >= 0 && (_IOC_DIR(ctl->ioctl_code) & _IOC_READ) != 0 &&
+ size > 0 && copy_to_user(ctl->data, buf, size) != 0)
retval = -EFAULT;
+exit:
kfree(buf);
return retval;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* USB: core: devio: fixed a trailing statement code style issue
@ 2018-08-12 21:50 Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2018-08-12 21:50 UTC (permalink / raw)
To: Tom Todd; +Cc: gregkh, stern, arvind.yadav.cs, linux-usb, linux-kernel
On Sun, Aug 12, 2018 at 07:06:56PM +0100, Tom Todd wrote:
> Fixed a code styling issue
>
Just ignore checkpatch on this one. The code is slightly unusual so
checkpatch got confused.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-08-12 21:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-12 21:50 USB: core: devio: fixed a trailing statement code style issue Dan Carpenter
-- strict thread matches above, loose matches on Subject: below --
2018-08-12 18:34 Joe Perches
2018-08-12 18:06 Tom Todd
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).