2013-10-10 21:41:39

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH 0/6] drivers: usb: core: Adapt source to styleguide

Hi,

I patches several files in drivers/usb/core/ to adapt them to the kernel
styleguide.

Most of these patches are whitespace/indention fixes.

As these patches are only style-patches, I just compiled the kernel, no compile
errors or warnings. So I think everything seems to be okay!

Note: I did not fix all ERROR messages from the scripts/checkpatch.pl script, as
I don't know what to do with "do not use assignments in if-condition" messages.

Matthias Beyer (6):
drivers: usb: core: {file,hub,sysfs,usb}.c: Whitespace fixes
drivers: usb: core: file.c: moved asterisk to variable name
drivers: usb: core: hub.c: Comments shouldnt be C99 // comment style
drivers: usb: core: devio.c: Coding style fixes
drivers: usb: core: devio.c: Braces around switch
drivers: usb: core: devio.c: Else should be on closing braces

drivers/usb/core/devio.c | 97 ++++++++++++++++++++-------------------
drivers/usb/core/file.c | 8 ++--
drivers/usb/core/hub.c | 115 +++++++++++++++++++++++------------------------
drivers/usb/core/sysfs.c | 5 ++-
drivers/usb/core/usb.c | 2 +-
5 files changed, 116 insertions(+), 111 deletions(-)

--
1.8.4


2013-10-10 21:41:44

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH 1/6] drivers: usb: core: {file,hub,sysfs,usb}.c: Whitespace fixes

including:

- removing of trailing whitespace
- removing spaces before array indexing (foo [] to foo[])
- reindention of a switch-case block
- spaces to tabs

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/file.c | 6 +--
drivers/usb/core/hub.c | 111 +++++++++++++++++++++++------------------------
drivers/usb/core/sysfs.c | 5 ++-
drivers/usb/core/usb.c | 2 +-
4 files changed, 62 insertions(+), 62 deletions(-)

diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 7421888..903c7ef 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -8,7 +8,7 @@
* (C) Copyright Deti Fliegl 1999 (new USB architecture)
* (C) Copyright Randy Dunlap 2000
* (C) Copyright David Brownell 2000-2001 (kernel hotplug, usb_device_id,
- more docs, etc)
+ * more docs, etc)
* (C) Copyright Yggdrasil Computing, Inc. 2000
* (usb_device_id matching changes by Adam J. Richter)
* (C) Copyright Greg Kroah-Hartman 2002-2003
@@ -44,7 +44,7 @@ static int usb_open(struct inode * inode, struct file * file)
file->f_op = new_fops;
/* Curiouser and curiouser... NULL ->open() as "no device" ? */
if (file->f_op->open)
- err = file->f_op->open(inode,file);
+ err = file->f_op->open(inode, file);
if (err) {
fops_put(file->f_op);
file->f_op = fops_get(old_fops);
@@ -166,7 +166,7 @@ int usb_register_dev(struct usb_interface *intf,
char *temp;

#ifdef CONFIG_USB_DYNAMIC_MINORS
- /*
+ /*
* We don't care what the device tries to start at, we want to start
* at zero to pack the devices into the smallest available space with
* no holes in the minor range.
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index e6b682c..e5fdf4b 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -120,7 +120,7 @@ static inline char *portspeed(struct usb_hub *hub, int portstatus)
if (hub_is_superspeed(hub->hdev))
return "5.0 Gb/s";
if (portstatus & USB_PORT_STAT_HIGH_SPEED)
- return "480 Mb/s";
+ return "480 Mb/s";
else if (portstatus & USB_PORT_STAT_LOW_SPEED)
return "1.5 Mb/s";
else
@@ -857,7 +857,7 @@ static int hub_hub_status(struct usb_hub *hub,
"%s failed (err = %d)\n", __func__, ret);
} else {
*status = le16_to_cpu(hub->status->hub.wHubStatus);
- *change = le16_to_cpu(hub->status->hub.wHubChange);
+ *change = le16_to_cpu(hub->status->hub.wHubChange);
ret = 0;
}
mutex_unlock(&hub->status_mutex);
@@ -956,7 +956,7 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1)
*/

set_bit(port1, hub->change_bits);
- kick_khubd(hub);
+ kick_khubd(hub);
}

/**
@@ -1361,7 +1361,7 @@ static int hub_configure(struct usb_hub *hub,
if ((wHubCharacteristics & HUB_CHAR_COMPOUND) &&
!(hub_is_superspeed(hdev))) {
int i;
- char portstr [USB_MAXCHILDREN + 1];
+ char portstr[USB_MAXCHILDREN + 1];

for (i = 0; i < hdev->maxchild; i++)
portstr[i] = hub->descriptor->u.hs.DeviceRemovable
@@ -1429,32 +1429,32 @@ static int hub_configure(struct usb_hub *hub,

/* Note 8 FS bit times == (8 bits / 12000000 bps) ~= 666ns */
switch (wHubCharacteristics & HUB_CHAR_TTTT) {
- case HUB_TTTT_8_BITS:
- if (hdev->descriptor.bDeviceProtocol != 0) {
- hub->tt.think_time = 666;
- dev_dbg(hub_dev, "TT requires at most %d "
- "FS bit times (%d ns)\n",
- 8, hub->tt.think_time);
- }
- break;
- case HUB_TTTT_16_BITS:
- hub->tt.think_time = 666 * 2;
- dev_dbg(hub_dev, "TT requires at most %d "
- "FS bit times (%d ns)\n",
- 16, hub->tt.think_time);
- break;
- case HUB_TTTT_24_BITS:
- hub->tt.think_time = 666 * 3;
- dev_dbg(hub_dev, "TT requires at most %d "
- "FS bit times (%d ns)\n",
- 24, hub->tt.think_time);
- break;
- case HUB_TTTT_32_BITS:
- hub->tt.think_time = 666 * 4;
+ case HUB_TTTT_8_BITS:
+ if (hdev->descriptor.bDeviceProtocol != 0) {
+ hub->tt.think_time = 666;
dev_dbg(hub_dev, "TT requires at most %d "
"FS bit times (%d ns)\n",
- 32, hub->tt.think_time);
- break;
+ 8, hub->tt.think_time);
+ }
+ break;
+ case HUB_TTTT_16_BITS:
+ hub->tt.think_time = 666 * 2;
+ dev_dbg(hub_dev, "TT requires at most %d "
+ "FS bit times (%d ns)\n",
+ 16, hub->tt.think_time);
+ break;
+ case HUB_TTTT_24_BITS:
+ hub->tt.think_time = 666 * 3;
+ dev_dbg(hub_dev, "TT requires at most %d "
+ "FS bit times (%d ns)\n",
+ 24, hub->tt.think_time);
+ break;
+ case HUB_TTTT_32_BITS:
+ hub->tt.think_time = 666 * 4;
+ dev_dbg(hub_dev, "TT requires at most %d "
+ "FS bit times (%d ns)\n",
+ 32, hub->tt.think_time);
+ break;
}

/* probe() zeroes hub->indicator[] */
@@ -1560,7 +1560,7 @@ static int hub_configure(struct usb_hub *hub,

/* maybe cycle the hub leds */
if (hub->has_indicators && blinkenlights)
- hub->indicator [0] = INDICATOR_CYCLE;
+ hub->indicator[0] = INDICATOR_CYCLE;

for (i = 0; i < hdev->maxchild; i++) {
ret = usb_hub_create_port_device(hub, i + 1);
@@ -1978,7 +1978,7 @@ static void choose_devnum(struct usb_device *udev)
if (devnum >= 128)
devnum = find_next_zero_bit(bus->devmap.devicemap,
128, 1);
- bus->devnum_next = ( devnum >= 127 ? 1 : devnum + 1);
+ bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1);
}
if (devnum < 128) {
set_bit(devnum, bus->devmap.devicemap);
@@ -2232,8 +2232,7 @@ static int usb_enumerate_device(struct usb_device *udev)
udev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL);
udev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL);
udev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL);
- }
- else {
+ } else {
/* read the standard strings and cache them if present */
udev->product = usb_cache_string(udev, udev->descriptor.iProduct);
udev->manufacturer = usb_cache_string(udev,
@@ -3108,8 +3107,8 @@ static int finish_port_resume(struct usb_device *udev)
retry_reset_resume:
status = usb_reset_and_verify_device(udev);

- /* 10.5.4.5 says be sure devices in the tree are still there.
- * For now let's assume the device didn't go crazy on resume,
+ /* 10.5.4.5 says be sure devices in the tree are still there.
+ * For now let's assume the device didn't go crazy on resume,
* and device drivers will know about any resume quirks.
*/
if (status == 0) {
@@ -3855,7 +3854,7 @@ EXPORT_SYMBOL_GPL(usb_enable_ltm);
* Between connect detection and reset signaling there must be a delay
* of 100ms at least for debounce and power-settling. The corresponding
* timer shall restart whenever the downstream port detects a disconnect.
- *
+ *
* Apparently there are some bluetooth and irda-dongles and a number of
* low-speed devices for which this debounce period may last over a second.
* Not covered by the spec - but easy to deal with.
@@ -4055,7 +4054,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
udev->tt = &hub->tt;
udev->ttport = port1;
}
-
+
/* Why interleave GET_DESCRIPTOR and SET_ADDRESS this way?
* Because device hardware and firmware is sometimes buggy in
* this area, and this is how Linux has done it for ages.
@@ -4130,11 +4129,11 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
#undef GET_DESCRIPTOR_BUFSIZE
}

- /*
- * If device is WUSB, we already assigned an
- * unauthorized address in the Connect Ack sequence;
- * authorization will assign the final address.
- */
+ /*
+ * If device is WUSB, we already assigned an
+ * unauthorized address in the Connect Ack sequence;
+ * authorization will assign the final address.
+ */
if (udev->wusb == 0) {
for (j = 0; j < SET_ADDRESS_TRIES; ++j) {
retval = hub_set_address(udev, devnum);
@@ -4163,7 +4162,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
msleep(10);
if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3))
break;
- }
+ }

retval = usb_get_device_descriptor(udev, 8);
if (retval < 8) {
@@ -4219,7 +4218,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i);
usb_ep0_reinit(udev);
}
-
+
retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE);
if (retval < (signed)sizeof(udev->descriptor)) {
if (retval != -ENODEV)
@@ -4316,7 +4315,7 @@ hub_power_remaining (struct usb_hub *hub)
}
if (remaining < 0) {
dev_warn(hub->intfdev, "%dmA over power budget!\n",
- - remaining);
+ -remaining);
remaining = 0;
}
return remaining;
@@ -4427,7 +4426,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);

if (portstatus & USB_PORT_STAT_ENABLE)
- goto done;
+ goto done;
return;
}
if (hub_is_superspeed(hub->hdev))
@@ -4450,7 +4449,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
}

usb_set_device_state(udev, USB_STATE_POWERED);
- udev->bus_mA = hub->mA_per_port;
+ udev->bus_mA = hub->mA_per_port;
udev->level = hdev->level + 1;
udev->wusb = hub_is_wusb(hub);

@@ -4504,7 +4503,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
goto loop_disable;
}
}
-
+
/* check for devices running slower than they could */
if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200
&& udev->speed == USB_SPEED_FULL
@@ -4564,7 +4563,7 @@ loop:
dev_err(hub_dev, "unable to enumerate USB device on port %d\n",
port1);
}
-
+
done:
hub_port_disable(hub, port1, 1);
if (hcd->driver->relinquish_port && !hub->hdev->parent)
@@ -4729,7 +4728,7 @@ static void hub_events(void)
* EM interference sometimes causes badly
* shielded USB devices to be shutdown by
* the hub, this hack enables them again.
- * Works at least with mouse driver.
+ * Works at least with mouse driver.
*/
if (!(portstatus & USB_PORT_STAT_ENABLE)
&& !connect_change
@@ -4841,7 +4840,7 @@ static void hub_events(void)
dev_dbg(hub_dev, "over-current change\n");
clear_hub_feature(hdev, C_HUB_OVER_CURRENT);
msleep(500); /* Cool down */
- hub_power_on(hub, true);
+ hub_power_on(hub, true);
hub_hub_status(hub, &status, &unused);
if (status & HUB_STATUS_OVERCURRENT)
dev_err(hub_dev, "over-current "
@@ -4861,7 +4860,7 @@ static void hub_events(void)
usb_unlock_device(hdev);
kref_put(&hub->kref, hub_release);

- } /* end while (1) */
+ } /* end while (1) */
}

static int hub_thread(void *__unused)
@@ -4886,7 +4885,7 @@ static int hub_thread(void *__unused)

static const struct usb_device_id hub_id_table[] = {
{ .match_flags = USB_DEVICE_ID_MATCH_VENDOR
- | USB_DEVICE_ID_MATCH_INT_CLASS,
+ | USB_DEVICE_ID_MATCH_INT_CLASS,
.idVendor = USB_VENDOR_GENESYS_LOGIC,
.bInterfaceClass = USB_CLASS_HUB,
.driver_info = HUB_QUIRK_CHECK_PORT_AUTOSUSPEND},
@@ -5120,13 +5119,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev)

if (ret < 0)
goto re_enumerate;
-
+
/* Device might have changed firmware (DFU or similar) */
if (descriptors_changed(udev, &descriptor, bos)) {
dev_info(&udev->dev, "device firmware changed\n");
udev->descriptor = descriptor; /* for disconnect() calls */
goto re_enumerate;
- }
+ }

/* Restore the device's previous configuration */
if (!udev->actconfig)
@@ -5151,7 +5150,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
udev->actconfig->desc.bConfigurationValue, ret);
mutex_unlock(hcd->bandwidth_mutex);
goto re_enumerate;
- }
+ }
mutex_unlock(hcd->bandwidth_mutex);
usb_set_device_state(udev, USB_STATE_CONFIGURED);

@@ -5198,7 +5197,7 @@ done:
usb_release_bos_descriptor(udev);
udev->bos = bos;
return 0;
-
+
re_enumerate:
/* LPM state doesn't matter when we're about to destroy the device. */
hub_port_logical_disconnect(parent_hub, port1);
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 6d2c8ed..da74740 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -390,7 +390,8 @@ static DEVICE_ATTR_RW(autosuspend);
static const char on_string[] = "on";
static const char auto_string[] = "auto";

-static void warn_level(void) {
+static void warn_level(void)
+{
static int level_warned;

if (!level_warned) {
@@ -644,7 +645,7 @@ static ssize_t authorized_store(struct device *dev,
result = usb_deauthorize_device(usb_dev);
else
result = usb_authorize_device(usb_dev);
- return result < 0? result : size;
+ return result < 0 ? result : size;
}
static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, S_IRUGO | S_IWUSR,
authorized_show, authorized_store);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 0a6ee2e..4d11449 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -497,7 +497,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
dev->authorized = 1;
else {
dev->authorized = usb_hcd->authorized_default;
- dev->wusb = usb_bus_is_wusb(bus)? 1 : 0;
+ dev->wusb = usb_bus_is_wusb(bus) ? 1 : 0;
}
return dev;
}
--
1.8.4

2013-10-10 21:41:55

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH 6/6] drivers: usb: core: devio.c: Else should be on closing braces

moved else keyword of if-else construct to closing braces.

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/devio.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 215d882..adbdea3 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1840,11 +1840,9 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)

if (ps->dev->state != USB_STATE_CONFIGURED) {
retval = -EHOSTUNREACH;
- }
- else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno))) {
+ } else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno))) {
retval = -EINVAL;
- }
- else {
+ } else {
switch (ctl->ioctl_code) {

/* disconnect kernel driver from interface */
--
1.8.4

2013-10-10 21:41:52

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH 5/6] drivers: usb: core: devio.c: Braces around switch

Added braces around switch statement as the styleguide tells us.
Indented the switch-block for it and split a function call
(driver->unlocked_ioctl() on line 1876) arguments to several lines to
fit the 80-column convention.

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/devio.c | 60 ++++++++++++++++++++++++++----------------------
1 file changed, 33 insertions(+), 27 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 8aca6b93..215d882 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1843,36 +1843,42 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
}
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;
+ }
}
}

--
1.8.4

2013-10-10 21:41:50

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH 3/6] drivers: usb: core: hub.c: Comments shouldnt be C99 // comment style

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/hub.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index e5fdf4b..5e9fc21 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -2488,7 +2488,7 @@ error_device_descriptor:
usb_autosuspend_device(usb_dev);
error_autoresume:
out_authorized:
- usb_unlock_device(usb_dev); // complements locktree
+ usb_unlock_device(usb_dev); /* complements locktree */
return result;
}

@@ -3210,7 +3210,7 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
if (status == 0 && !port_is_suspended(hub, portstatus))
goto SuspendCleared;

- // dev_dbg(hub->intfdev, "resume port %d\n", port1);
+ /* dev_dbg(hub->intfdev, "resume port %d\n", port1); */

set_bit(port1, hub->busy_bits);

--
1.8.4

2013-10-10 21:42:34

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH 4/6] drivers: usb: core: devio.c: Coding style fixes

Whitespace fixes, including:

- Whitespace after if-keyword
- Spaces to Tabs

Other coding style fixes:

- Added braces for if-else blocks where missing

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/devio.c | 39 ++++++++++++++++++++-------------------
1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 71dc5d7..8aca6b93 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1222,7 +1222,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
return -ENOENT;

u = 0;
- switch(uurb->type) {
+ switch (uurb->type) {
case USBDEVFS_URB_TYPE_CONTROL:
if (!usb_endpoint_xfer_control(&ep->desc))
return -EINVAL;
@@ -1636,32 +1636,32 @@ static int proc_reapurbnonblock(struct dev_state *ps, void __user *arg)
static int proc_control_compat(struct dev_state *ps,
struct usbdevfs_ctrltransfer32 __user *p32)
{
- struct usbdevfs_ctrltransfer __user *p;
- __u32 udata;
- p = compat_alloc_user_space(sizeof(*p));
- if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
- get_user(udata, &p32->data) ||
+ struct usbdevfs_ctrltransfer __user *p;
+ __u32 udata;
+ p = compat_alloc_user_space(sizeof(*p));
+ if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
+ get_user(udata, &p32->data) ||
put_user(compat_ptr(udata), &p->data))
return -EFAULT;
- return proc_control(ps, p);
+ return proc_control(ps, p);
}

static int proc_bulk_compat(struct dev_state *ps,
struct usbdevfs_bulktransfer32 __user *p32)
{
- struct usbdevfs_bulktransfer __user *p;
- compat_uint_t n;
- compat_caddr_t addr;
+ struct usbdevfs_bulktransfer __user *p;
+ compat_uint_t n;
+ compat_caddr_t addr;

- p = compat_alloc_user_space(sizeof(*p));
+ p = compat_alloc_user_space(sizeof(*p));

- if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
- get_user(n, &p32->len) || put_user(n, &p->len) ||
- get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
- get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
- return -EFAULT;
+ if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
+ get_user(n, &p32->len) || put_user(n, &p->len) ||
+ get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
+ get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
+ return -EFAULT;

- return proc_bulk(ps, p);
+ return proc_bulk(ps, p);
}
static int proc_disconnectsignal_compat(struct dev_state *ps, void __user *arg)
{
@@ -1838,9 +1838,10 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
return -ENODEV;
}

- 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)))
+ }
+ else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno))) {
retval = -EINVAL;
else switch (ctl->ioctl_code) {

--
1.8.4

2013-10-10 21:43:06

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH 2/6] drivers: usb: core: file.c: moved asterisk to variable name

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 903c7ef..3bdfbf8 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -27,7 +27,7 @@
static const struct file_operations *usb_minors[MAX_USB_MINORS];
static DECLARE_RWSEM(minor_rwsem);

-static int usb_open(struct inode * inode, struct file * file)
+static int usb_open(struct inode *inode, struct file *file)
{
int minor = iminor(inode);
const struct file_operations *c;
--
1.8.4

2013-10-12 00:06:09

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 4/6] drivers: usb: core: devio.c: Coding style fixes

On Thu, Oct 10, 2013 at 11:41:30PM +0200, Matthias Beyer wrote:
> @@ -1838,9 +1838,10 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
> return -ENODEV;
> }
>
> - 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)))
> + }
> + else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno))) {
> retval = -EINVAL;
> else switch (ctl->ioctl_code) {

I don't think you actually built the code after you made this change :(

drivers/usb/core/devio.c: In function ‘proc_ioctl’:
drivers/usb/core/devio.c:1844:2: error: expected ‘}’ before ‘else’

Please be more careful.

thanks,

greg k-h

2013-10-12 00:08:11

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 5/6] drivers: usb: core: devio.c: Braces around switch

On Thu, Oct 10, 2013 at 11:41:31PM +0200, Matthias Beyer wrote:
> Added braces around switch statement as the styleguide tells us.
> Indented the switch-block for it and split a function call
> (driver->unlocked_ioctl() on line 1876) arguments to several lines to
> fit the 80-column convention.
>
> Signed-off-by: Matthias Beyer <[email protected]>
> ---
> drivers/usb/core/devio.c | 60 ++++++++++++++++++++++++++----------------------

This patch has fuzz, due to me not applying your previous one, so I
can't apply it.

Can you fix it up, and resend the remaining patches that I didn't apply
in this series?

thanks,

greg k-h

2013-10-12 00:09:32

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 0/6] drivers: usb: core: Adapt source to styleguide

On Thu, Oct 10, 2013 at 11:41:26PM +0200, Matthias Beyer wrote:
> Hi,
>
> I patches several files in drivers/usb/core/ to adapt them to the kernel
> styleguide.
>
> Most of these patches are whitespace/indention fixes.
>
> As these patches are only style-patches, I just compiled the kernel, no compile
> errors or warnings. So I think everything seems to be okay!
>
> Note: I did not fix all ERROR messages from the scripts/checkpatch.pl script, as
> I don't know what to do with "do not use assignments in if-condition" messages.

You can fix those up if you want. An example would be:
bad code:
if ((x = foo() == NULL)
do_something();
good code:
x = foo();
if (x == NULL)
do_something();

Hope this helps,

greg k-h

2013-10-12 11:01:49

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH 1/1] drivers: usb: core: devio.c: Coding style fixes

Whitespace fixes, including:

- Whitespace after if-keyword
- Spaces to Tabs

Other coding style fixes:

- Added braces for if-else blocks where missing

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/devio.c | 40 +++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 71dc5d7..5f8a40d 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1222,7 +1222,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
return -ENOENT;

u = 0;
- switch(uurb->type) {
+ switch (uurb->type) {
case USBDEVFS_URB_TYPE_CONTROL:
if (!usb_endpoint_xfer_control(&ep->desc))
return -EINVAL;
@@ -1636,32 +1636,32 @@ static int proc_reapurbnonblock(struct dev_state *ps, void __user *arg)
static int proc_control_compat(struct dev_state *ps,
struct usbdevfs_ctrltransfer32 __user *p32)
{
- struct usbdevfs_ctrltransfer __user *p;
- __u32 udata;
- p = compat_alloc_user_space(sizeof(*p));
- if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
- get_user(udata, &p32->data) ||
+ struct usbdevfs_ctrltransfer __user *p;
+ __u32 udata;
+ p = compat_alloc_user_space(sizeof(*p));
+ if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
+ get_user(udata, &p32->data) ||
put_user(compat_ptr(udata), &p->data))
return -EFAULT;
- return proc_control(ps, p);
+ return proc_control(ps, p);
}

static int proc_bulk_compat(struct dev_state *ps,
struct usbdevfs_bulktransfer32 __user *p32)
{
- struct usbdevfs_bulktransfer __user *p;
- compat_uint_t n;
- compat_caddr_t addr;
+ struct usbdevfs_bulktransfer __user *p;
+ compat_uint_t n;
+ compat_caddr_t addr;

- p = compat_alloc_user_space(sizeof(*p));
+ p = compat_alloc_user_space(sizeof(*p));

- if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
- get_user(n, &p32->len) || put_user(n, &p->len) ||
- get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
- get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
- return -EFAULT;
+ if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
+ get_user(n, &p32->len) || put_user(n, &p->len) ||
+ get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
+ get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
+ return -EFAULT;

- return proc_bulk(ps, p);
+ return proc_bulk(ps, p);
}
static int proc_disconnectsignal_compat(struct dev_state *ps, void __user *arg)
{
@@ -1838,10 +1838,12 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
return -ENODEV;
}

- 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)))
+ }
+ else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno))) {
retval = -EINVAL;
+ }
else switch (ctl->ioctl_code) {

/* disconnect kernel driver from interface */
--
1.8.4

2013-10-12 11:05:44

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH 1/1] drivers: usb: core: devio.c: Braces around switch (updated)

Added braces around switch statement as the styleguide tells us.
Indented the switch-block for it and split a function call
(driver->unlocked_ioctl() on line 1876) arguments to several lines to
fit the 80-column convention.

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/devio.c | 63 +++++++++++++++++++++++++-----------------------
1 file changed, 33 insertions(+), 30 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 5f8a40d..adbdea3 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1840,40 +1840,43 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)

if (ps->dev->state != USB_STATE_CONFIGURED) {
retval = -EHOSTUNREACH;
- }
- else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno))) {
+ } 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;
+ }
}
}

--
1.8.4

2013-10-12 16:20:29

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH 1/1] drivers: usb: core: devio.c: Coding style fixes

Hello.

On 12-10-2013 13:01, Matthias Beyer wrote:

> Whitespace fixes, including:

> - Whitespace after if-keyword
> - Spaces to Tabs

> Other coding style fixes:

> - Added braces for if-else blocks where missing

> Signed-off-by: Matthias Beyer <[email protected]>
> ---
> drivers/usb/core/devio.c | 40 +++++++++++++++++++++-------------------
> 1 file changed, 21 insertions(+), 19 deletions(-)

> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index 71dc5d7..5f8a40d 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
[...]
> @@ -1636,32 +1636,32 @@ static int proc_reapurbnonblock(struct dev_state *ps, void __user *arg)
> static int proc_control_compat(struct dev_state *ps,
> struct usbdevfs_ctrltransfer32 __user *p32)
> {
> - struct usbdevfs_ctrltransfer __user *p;
> - __u32 udata;
> - p = compat_alloc_user_space(sizeof(*p));
> - if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
> - get_user(udata, &p32->data) ||
> + struct usbdevfs_ctrltransfer __user *p;
> + __u32 udata;

Could you also add an empty line here, for consistency with the below code?

> + p = compat_alloc_user_space(sizeof(*p));
> + if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
> + get_user(udata, &p32->data) ||
> put_user(compat_ptr(udata), &p->data))
> return -EFAULT;
> - return proc_control(ps, p);
> + return proc_control(ps, p);
> }
>
> static int proc_bulk_compat(struct dev_state *ps,
> struct usbdevfs_bulktransfer32 __user *p32)
> {
> - struct usbdevfs_bulktransfer __user *p;
> - compat_uint_t n;
> - compat_caddr_t addr;
> + struct usbdevfs_bulktransfer __user *p;
> + compat_uint_t n;
> + compat_caddr_t addr;
>
> - p = compat_alloc_user_space(sizeof(*p));
> + p = compat_alloc_user_space(sizeof(*p));
>
> - if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
> - get_user(n, &p32->len) || put_user(n, &p->len) ||
> - get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
> - get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
> - return -EFAULT;
> + if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
> + get_user(n, &p32->len) || put_user(n, &p->len) ||
> + get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
> + get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
> + return -EFAULT;
>
> - return proc_bulk(ps, p);
> + return proc_bulk(ps, p);
> }
> static int proc_disconnectsignal_compat(struct dev_state *ps, void __user *arg)
> {
> @@ -1838,10 +1838,12 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
> return -ENODEV;
> }
>
> - 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)))
> + }
> + else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno))) {

No, } and *else* should be on the same line. But wait, both arms of *if*
are single statements, so why you added {} in the first place? :-/

> retval = -EINVAL;
> + }

WBR, Sergei

2013-10-14 18:12:16

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/1] drivers: usb: core: devio.c: Coding style fixes

On Sat, Oct 12, 2013 at 01:01:34PM +0200, Matthias Beyer wrote:
> Whitespace fixes, including:
>
> - Whitespace after if-keyword
> - Spaces to Tabs
>
> Other coding style fixes:
>
> - Added braces for if-else blocks where missing

When doing coding style cleanups, please only do one thing per patch.
You are doing a bunch of different things here, all in one patch, which
isn't good so I can't take it, sorry.

Please split this up into different patches and I will be glad to accept
it.

thanks,

greg k-h

2013-10-14 18:12:52

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/1] drivers: usb: core: devio.c: Braces around switch (updated)

On Sat, Oct 12, 2013 at 01:05:35PM +0200, Matthias Beyer wrote:
> Added braces around switch statement as the styleguide tells us.
> Indented the switch-block for it and split a function call
> (driver->unlocked_ioctl() on line 1876) arguments to several lines to
> fit the 80-column convention.

This patch doesn't apply at all, any reason why?

confused,

greg k-h

2013-10-14 19:46:54

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH v2 0/5] Coding style fixes

Actually this is the third reroll of this patchseries, but I just figured out
how to place this "v2" thing in the patches... sorry for that!

As Greg KH requested:

I splitted the coding style fixes into several patches. The replacing of spaces
by tabs in proc_reapurbnonblock() and proc_control_compat() is splitted into two
patches. As the patch for adding braces around the switch-block in here did not
apply (don't know why), this patch series resubmits it (also splitted).

Note: This patch series makes the remaining patches from the origin patch series
_obsolete_. So you have not to apply 5/6 and 6/6 from the origin patch series
(I would be confused if it still works)!

Btw: If you are stressed out by me sending coding style fixes, I wouldn't take
it wrong if you would redirect me to a submaintainer or so!

Best regards!

Matthias Beyer (5):
drivers: usb: core: devio.c: Spaces to tabs for proc_reapurbnonblock()
drivers: usb: core: devio.c: Spaces to tabs for proc_control_compat()
drivers: usb: core: devio.c: Braces around if-elseif-else
drivers: usb: core: devio.c: Reindented switch-block
drivers: usb: core: devio.c: Put arguments on new line

drivers/usb/core/devio.c | 95 +++++++++++++++++++++++++-----------------------
1 file changed, 49 insertions(+), 46 deletions(-)

--
1.8.4

2013-10-14 19:47:04

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH v2 3/5] drivers: usb: core: devio.c: Braces around if-elseif-else

This patch applies the rules for braces to the if-elseif-else statement
in proc_ioctl().

As the kernel styleguide says: If there is at least one multiline block
in a if-else branching, we should add braces around all blocks. This
includes braces around the switch-statement on the else branch, which
needs a reindent after adding the braces.

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/devio.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index d15aa51..dd8701b 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1222,7 +1222,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
return -ENOENT;

u = 0;
- switch(uurb->type) {
+ switch (uurb->type) {
case USBDEVFS_URB_TYPE_CONTROL:
if (!usb_endpoint_xfer_control(&ep->desc))
return -EINVAL;
@@ -1838,11 +1838,12 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
return -ENODEV;
}

- 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)))
+ } else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno))) {
retval = -EINVAL;
- else switch (ctl->ioctl_code) {
+ } else {
+ switch (ctl->ioctl_code) {

/* disconnect kernel driver from interface */
case USBDEVFS_DISCONNECT:
@@ -1874,6 +1875,7 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
retval = -ENOTTY;
}
}
+ }

/* cleanup and return */
if (retval >= 0
--
1.8.4

2013-10-14 19:47:22

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH v2 5/5] drivers: usb: core: devio.c: Put arguments on new line

To fit the 80-cols convention, this patch moves the arguments (the
second and third one) for driver->unlocked_ioctl() onto a new line.

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/devio.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 9761a27..0387948 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1870,7 +1870,8 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
if (driver == NULL || driver->unlocked_ioctl == NULL) {
retval = -ENOTTY;
} else {
- retval = driver->unlocked_ioctl(intf, ctl->ioctl_code, buf);
+ retval = driver->unlocked_ioctl(intf,
+ ctl->ioctl_code, buf);
if (retval == -ENOIOCTLCMD)
retval = -ENOTTY;
}
--
1.8.4

2013-10-14 19:47:01

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH v2 2/5] drivers: usb: core: devio.c: Spaces to tabs for proc_control_compat()

Replaced spaces by tabs for proc_control_compat() function.

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/devio.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 6a2e567..d15aa51 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1649,19 +1649,19 @@ static int proc_control_compat(struct dev_state *ps,
static int proc_bulk_compat(struct dev_state *ps,
struct usbdevfs_bulktransfer32 __user *p32)
{
- struct usbdevfs_bulktransfer __user *p;
- compat_uint_t n;
- compat_caddr_t addr;
+ struct usbdevfs_bulktransfer __user *p;
+ compat_uint_t n;
+ compat_caddr_t addr;

- p = compat_alloc_user_space(sizeof(*p));
+ p = compat_alloc_user_space(sizeof(*p));

- if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
- get_user(n, &p32->len) || put_user(n, &p->len) ||
- get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
- get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
- return -EFAULT;
+ if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
+ get_user(n, &p32->len) || put_user(n, &p->len) ||
+ get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
+ get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
+ return -EFAULT;

- return proc_bulk(ps, p);
+ return proc_bulk(ps, p);
}
static int proc_disconnectsignal_compat(struct dev_state *ps, void __user *arg)
{
--
1.8.4

2013-10-14 19:47:53

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH v2 4/5] drivers: usb: core: devio.c: Reindented switch-block

Reindented the switch-block.

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/devio.c | 56 ++++++++++++++++++++++++------------------------
1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index dd8701b..9761a27 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1843,39 +1843,39 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
} 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;
+ 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
--
1.8.4

2013-10-14 19:48:21

by Matthias Beyer

[permalink] [raw]
Subject: [PATCH v2 1/5] drivers: usb: core: devio.c: Spaces to tabs for proc_reapurbnonblock()

Replaced spaces by tabs for proc_reapurbnonblock() function.

Signed-off-by: Matthias Beyer <[email protected]>
---
drivers/usb/core/devio.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 71dc5d7..6a2e567 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1636,14 +1636,14 @@ static int proc_reapurbnonblock(struct dev_state *ps, void __user *arg)
static int proc_control_compat(struct dev_state *ps,
struct usbdevfs_ctrltransfer32 __user *p32)
{
- struct usbdevfs_ctrltransfer __user *p;
- __u32 udata;
- p = compat_alloc_user_space(sizeof(*p));
- if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
- get_user(udata, &p32->data) ||
+ struct usbdevfs_ctrltransfer __user *p;
+ __u32 udata;
+ p = compat_alloc_user_space(sizeof(*p));
+ if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
+ get_user(udata, &p32->data) ||
put_user(compat_ptr(udata), &p->data))
return -EFAULT;
- return proc_control(ps, p);
+ return proc_control(ps, p);
}

static int proc_bulk_compat(struct dev_state *ps,
--
1.8.4

2013-10-16 20:40:18

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2 3/5] drivers: usb: core: devio.c: Braces around if-elseif-else

On Mon, Oct 14, 2013 at 09:46:38PM +0200, Matthias Beyer wrote:
> This patch applies the rules for braces to the if-elseif-else statement
> in proc_ioctl().
>
> As the kernel styleguide says: If there is at least one multiline block
> in a if-else branching, we should add braces around all blocks. This
> includes braces around the switch-statement on the else branch, which
> needs a reindent after adding the braces.
>
> Signed-off-by: Matthias Beyer <[email protected]>
> ---
> drivers/usb/core/devio.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index d15aa51..dd8701b 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -1222,7 +1222,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
> return -ENOENT;
>
> u = 0;
> - switch(uurb->type) {
> + switch (uurb->type) {
> case USBDEVFS_URB_TYPE_CONTROL:
> if (!usb_endpoint_xfer_control(&ep->desc))
> return -EINVAL;
> @@ -1838,11 +1838,12 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
> return -ENODEV;
> }
>
> - 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)))
> + } else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno))) {
> retval = -EINVAL;
> - else switch (ctl->ioctl_code) {
> + } else {
> + switch (ctl->ioctl_code) {
>
> /* disconnect kernel driver from interface */
> case USBDEVFS_DISCONNECT:
> @@ -1874,6 +1875,7 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
> retval = -ENOTTY;
> }
> }
> + }

Two braces in line like that should scream at you that something is
wrong with the indentation here.

I'd leave it alone for the switch statement, as it's not needed.

Actually this whole thing should be fine, it's correct, right?

thanks,

greg k-h

2013-10-16 20:40:48

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2 5/5] drivers: usb: core: devio.c: Put arguments on new line

On Mon, Oct 14, 2013 at 09:46:40PM +0200, Matthias Beyer wrote:
> To fit the 80-cols convention, this patch moves the arguments (the
> second and third one) for driver->unlocked_ioctl() onto a new line.
>
> Signed-off-by: Matthias Beyer <[email protected]>
> ---
> drivers/usb/core/devio.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index 9761a27..0387948 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -1870,7 +1870,8 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
> if (driver == NULL || driver->unlocked_ioctl == NULL) {
> retval = -ENOTTY;
> } else {
> - retval = driver->unlocked_ioctl(intf, ctl->ioctl_code, buf);
> + retval = driver->unlocked_ioctl(intf,
> + ctl->ioctl_code, buf);

Nah, it looks worse this way, just leave it alone.

thanks,

greg k-h