Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 00/14] USB: legousbtower: misc cleanups
@ 2019-11-05  8:41 Johan Hovold
  2019-11-05  8:41 ` [PATCH 01/14] USB: legousbtower: drop redundant MODULE_LICENSE ifdef Johan Hovold
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

Here's a bunch of clean ups to the legousbtower driver as a promised
follow up to the earlier set of fixes.

Johan


Johan Hovold (14):
  USB: legousbtower: drop redundant MODULE_LICENSE ifdef
  USB: legousbtower: drop redundant NULL check
  USB: legousbtower: zero driver data at allocation
  USB: legousbtower: drop redundant open_count check
  USB: legousbtower: drop noisy disconnect messages
  USB: legousbtower: drop redundant interrupt-in running flag
  USB: legousbtower: stop interrupt-out URB unconditionally
  USB: legousbtower: remove tower_abort_transfers()
  USB: legousbtower: clean up pointer declarations in driver data
  USB: legousbtower: drop unnecessary packed attributes
  USB: legousbtower: drop redundant endianness comments
  USB: legousbtower: clean up runaway white space
  USB: legousbtower: drop superfluous brackets
  USB: legousbtower: drop superfluous newlines

 drivers/usb/misc/legousbtower.c | 303 +++++++++++++-------------------
 1 file changed, 118 insertions(+), 185 deletions(-)

-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 01/14] USB: legousbtower: drop redundant MODULE_LICENSE ifdef
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 02/14] USB: legousbtower: drop redundant NULL check Johan Hovold
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

The MODULE_LICENSE macro is unconditionally defined in module.h, no need
to ifdef its use.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 23061f1526b4..1be84dc13067 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -962,6 +962,4 @@ module_usb_driver(tower_driver);
 
 MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
-#ifdef MODULE_LICENSE
 MODULE_LICENSE("GPL");
-#endif
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 02/14] USB: legousbtower: drop redundant NULL check
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
  2019-11-05  8:41 ` [PATCH 01/14] USB: legousbtower: drop redundant MODULE_LICENSE ifdef Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 03/14] USB: legousbtower: zero driver data at allocation Johan Hovold
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

Drop redundant NULL check from tower_abort_transfers(), which is never
called with a NULL argument.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 1be84dc13067..a3ae843e0a3a 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -457,9 +457,6 @@ static int tower_release (struct inode *inode, struct file *file)
  */
 static void tower_abort_transfers (struct lego_usb_tower *dev)
 {
-	if (dev == NULL)
-		return;
-
 	/* shutdown transfer */
 	if (dev->interrupt_in_running) {
 		dev->interrupt_in_running = 0;
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 03/14] USB: legousbtower: zero driver data at allocation
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
  2019-11-05  8:41 ` [PATCH 01/14] USB: legousbtower: drop redundant MODULE_LICENSE ifdef Johan Hovold
  2019-11-05  8:41 ` [PATCH 02/14] USB: legousbtower: drop redundant NULL check Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 04/14] USB: legousbtower: drop redundant open_count check Johan Hovold
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

Zero the driver data at allocation rather than depend on explicit
zeroing, which easy to miss.

Also drop an unnecessary driver-data pointer initialisation.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 25 ++-----------------------
 1 file changed, 2 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index a3ae843e0a3a..c880d58e8683 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -791,45 +791,24 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
 {
 	struct device *idev = &interface->dev;
 	struct usb_device *udev = interface_to_usbdev(interface);
-	struct lego_usb_tower *dev = NULL;
+	struct lego_usb_tower *dev;
 	struct tower_get_version_reply *get_version_reply = NULL;
 	int retval = -ENOMEM;
 	int result;
 
 	/* allocate memory for our device state and initialize it */
-
-	dev = kmalloc (sizeof(struct lego_usb_tower), GFP_KERNEL);
-
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
 	if (!dev)
 		goto exit;
 
 	mutex_init(&dev->lock);
-
 	dev->udev = usb_get_dev(udev);
-	dev->open_count = 0;
-	dev->disconnected = 0;
-
-	dev->read_buffer = NULL;
-	dev->read_buffer_length = 0;
-	dev->read_packet_length = 0;
 	spin_lock_init (&dev->read_buffer_lock);
 	dev->packet_timeout_jiffies = msecs_to_jiffies(packet_timeout);
 	dev->read_last_arrival = jiffies;
-
 	init_waitqueue_head (&dev->read_wait);
 	init_waitqueue_head (&dev->write_wait);
 
-	dev->interrupt_in_buffer = NULL;
-	dev->interrupt_in_endpoint = NULL;
-	dev->interrupt_in_urb = NULL;
-	dev->interrupt_in_running = 0;
-	dev->interrupt_in_done = 0;
-
-	dev->interrupt_out_buffer = NULL;
-	dev->interrupt_out_endpoint = NULL;
-	dev->interrupt_out_urb = NULL;
-	dev->interrupt_out_busy = 0;
-
 	result = usb_find_common_endpoints_reverse(interface->cur_altsetting,
 			NULL, NULL,
 			&dev->interrupt_in_endpoint,
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 04/14] USB: legousbtower: drop redundant open_count check
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
                   ` (2 preceding siblings ...)
  2019-11-05  8:41 ` [PATCH 03/14] USB: legousbtower: zero driver data at allocation Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 05/14] USB: legousbtower: drop noisy disconnect messages Johan Hovold
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

Drop redundant open_count check in release; the open count is used as a
flag and is only set to 0 or 1.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index c880d58e8683..1626a0d2b12b 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -421,13 +421,6 @@ static int tower_release (struct inode *inode, struct file *file)
 
 	mutex_lock(&dev->lock);
 
-	if (dev->open_count != 1) {
-		dev_dbg(&dev->udev->dev, "%s: device not opened exactly once\n",
-			__func__);
-		retval = -ENODEV;
-		goto unlock_exit;
-	}
-
 	if (dev->disconnected) {
 		/* the device was unplugged before the file was released */
 
@@ -444,7 +437,6 @@ static int tower_release (struct inode *inode, struct file *file)
 	tower_abort_transfers (dev);
 	dev->open_count = 0;
 
-unlock_exit:
 	mutex_unlock(&dev->lock);
 exit:
 	return retval;
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 05/14] USB: legousbtower: drop noisy disconnect messages
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
                   ` (3 preceding siblings ...)
  2019-11-05  8:41 ` [PATCH 04/14] USB: legousbtower: drop redundant open_count check Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 06/14] USB: legousbtower: drop redundant interrupt-in running flag Johan Hovold
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

User space already sees -ENODEV in case it tries to do I/O post
disconnect, no need to spam the logs with printk messages that don't
even include any device-id information.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 1626a0d2b12b..937bce23adf0 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -540,7 +540,6 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
 	/* verify that the device wasn't unplugged */
 	if (dev->disconnected) {
 		retval = -ENODEV;
-		pr_err("No device or device unplugged %d\n", retval);
 		goto unlock_exit;
 	}
 
@@ -626,7 +625,6 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
 	/* verify that the device wasn't unplugged */
 	if (dev->disconnected) {
 		retval = -ENODEV;
-		pr_err("No device or device unplugged %d\n", retval);
 		goto unlock_exit;
 	}
 
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 06/14] USB: legousbtower: drop redundant interrupt-in running flag
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
                   ` (4 preceding siblings ...)
  2019-11-05  8:41 ` [PATCH 05/14] USB: legousbtower: drop noisy disconnect messages Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 07/14] USB: legousbtower: stop interrupt-out URB unconditionally Johan Hovold
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

Drop the redundant interrupt-in-running flag, which tried to keep track
of when the interrupt-in URB was in flight. This isn't needed since we
can stop the URB unconditionally in tower_abort_transfers() and the URB
can not be submitted while usb_kill_urb() is running anyway.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 937bce23adf0..33533faa019e 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -206,7 +206,6 @@ struct lego_usb_tower {
 	struct usb_endpoint_descriptor* interrupt_in_endpoint;
 	struct urb*		interrupt_in_urb;
 	int			interrupt_in_interval;
-	int			interrupt_in_running;
 	int			interrupt_in_done;
 
 	char*			interrupt_out_buffer;
@@ -379,7 +378,6 @@ static int tower_open (struct inode *inode, struct file *file)
 			  dev,
 			  dev->interrupt_in_interval);
 
-	dev->interrupt_in_running = 1;
 	dev->interrupt_in_done = 0;
 	mb();
 
@@ -387,7 +385,6 @@ static int tower_open (struct inode *inode, struct file *file)
 	if (retval) {
 		dev_err(&dev->udev->dev,
 			"Couldn't submit interrupt_in_urb %d\n", retval);
-		dev->interrupt_in_running = 0;
 		goto unlock_exit;
 	}
 
@@ -450,11 +447,7 @@ static int tower_release (struct inode *inode, struct file *file)
 static void tower_abort_transfers (struct lego_usb_tower *dev)
 {
 	/* shutdown transfer */
-	if (dev->interrupt_in_running) {
-		dev->interrupt_in_running = 0;
-		mb();
-		usb_kill_urb(dev->interrupt_in_urb);
-	}
+	usb_kill_urb(dev->interrupt_in_urb);
 	if (dev->interrupt_out_busy)
 		usb_kill_urb(dev->interrupt_out_urb);
 }
@@ -731,15 +724,11 @@ static void tower_interrupt_in_callback (struct urb *urb)
 	}
 
 resubmit:
-	/* resubmit if we're still running */
-	if (dev->interrupt_in_running) {
-		retval = usb_submit_urb (dev->interrupt_in_urb, GFP_ATOMIC);
-		if (retval)
-			dev_err(&dev->udev->dev,
-				"%s: usb_submit_urb failed (%d)\n",
-				__func__, retval);
+	retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC);
+	if (retval) {
+		dev_err(&dev->udev->dev, "%s: usb_submit_urb failed (%d)\n",
+			__func__, retval);
 	}
-
 exit:
 	dev->interrupt_in_done = 1;
 	wake_up_interruptible (&dev->read_wait);
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 07/14] USB: legousbtower: stop interrupt-out URB unconditionally
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
                   ` (5 preceding siblings ...)
  2019-11-05  8:41 ` [PATCH 06/14] USB: legousbtower: drop redundant interrupt-in running flag Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 08/14] USB: legousbtower: remove tower_abort_transfers() Johan Hovold
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

Stop also the interrupt-out URB unconditionally in
tower_abort_transfers() which is called from release() (for connected
devices). Calling usb_kill_urb() for an idle URB is perfectly fine.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 33533faa019e..3e409dfe172c 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -448,8 +448,7 @@ static void tower_abort_transfers (struct lego_usb_tower *dev)
 {
 	/* shutdown transfer */
 	usb_kill_urb(dev->interrupt_in_urb);
-	if (dev->interrupt_out_busy)
-		usb_kill_urb(dev->interrupt_out_urb);
+	usb_kill_urb(dev->interrupt_out_urb);
 }
 
 
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 08/14] USB: legousbtower: remove tower_abort_transfers()
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
                   ` (6 preceding siblings ...)
  2019-11-05  8:41 ` [PATCH 07/14] USB: legousbtower: stop interrupt-out URB unconditionally Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 09/14] USB: legousbtower: clean up pointer declarations in driver data Johan Hovold
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

Drop the tower_abort_transfers() function which is now only called from
release and instead explicitly kill the two URBs.

This incidentally also fixes the outdated comment about freeing memory.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 3e409dfe172c..f85b6ed2fb8b 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -226,7 +226,6 @@ static int tower_release	(struct inode *inode, struct file *file);
 static __poll_t tower_poll	(struct file *file, poll_table *wait);
 static loff_t tower_llseek	(struct file *file, loff_t off, int whence);
 
-static void tower_abort_transfers (struct lego_usb_tower *dev);
 static void tower_check_for_read_packet (struct lego_usb_tower *dev);
 static void tower_interrupt_in_callback (struct urb *urb);
 static void tower_interrupt_out_callback (struct urb *urb);
@@ -431,7 +430,11 @@ static int tower_release (struct inode *inode, struct file *file)
 	if (dev->interrupt_out_busy) {
 		wait_event_interruptible_timeout (dev->write_wait, !dev->interrupt_out_busy, 2 * HZ);
 	}
-	tower_abort_transfers (dev);
+
+	/* shutdown transfers */
+	usb_kill_urb(dev->interrupt_in_urb);
+	usb_kill_urb(dev->interrupt_out_urb);
+
 	dev->open_count = 0;
 
 	mutex_unlock(&dev->lock);
@@ -439,19 +442,6 @@ static int tower_release (struct inode *inode, struct file *file)
 	return retval;
 }
 
-
-/**
- *	tower_abort_transfers
- *      aborts transfers and frees associated data structures
- */
-static void tower_abort_transfers (struct lego_usb_tower *dev)
-{
-	/* shutdown transfer */
-	usb_kill_urb(dev->interrupt_in_urb);
-	usb_kill_urb(dev->interrupt_out_urb);
-}
-
-
 /**
  *	tower_check_for_read_packet
  *
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 09/14] USB: legousbtower: clean up pointer declarations in driver data
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
                   ` (7 preceding siblings ...)
  2019-11-05  8:41 ` [PATCH 08/14] USB: legousbtower: remove tower_abort_transfers() Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 10/14] USB: legousbtower: drop unnecessary packed attributes Johan Hovold
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

Clean up the pointer declarations in the driver data, whose style wasn't
even consistent with the rest of the driver.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index f85b6ed2fb8b..c8ed8792b931 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -186,13 +186,13 @@ MODULE_DEVICE_TABLE (usb, tower_table);
 /* Structure to hold all of our device specific stuff */
 struct lego_usb_tower {
 	struct mutex		lock;		/* locks this structure */
-	struct usb_device*	udev;		/* save off the usb device pointer */
+	struct usb_device	*udev;		/* save off the usb device pointer */
 	unsigned char		minor;		/* the starting minor number for this device */
 
 	int			open_count;	/* number of times this port has been opened */
 	unsigned long		disconnected:1;
 
-	char*			read_buffer;
+	char			*read_buffer;
 	size_t			read_buffer_length; /* this much came in */
 	size_t			read_packet_length; /* this much will be returned on read */
 	spinlock_t		read_buffer_lock;
@@ -202,15 +202,15 @@ struct lego_usb_tower {
 	wait_queue_head_t	read_wait;
 	wait_queue_head_t	write_wait;
 
-	char*			interrupt_in_buffer;
-	struct usb_endpoint_descriptor* interrupt_in_endpoint;
-	struct urb*		interrupt_in_urb;
+	char			*interrupt_in_buffer;
+	struct usb_endpoint_descriptor *interrupt_in_endpoint;
+	struct urb		*interrupt_in_urb;
 	int			interrupt_in_interval;
 	int			interrupt_in_done;
 
-	char*			interrupt_out_buffer;
-	struct usb_endpoint_descriptor* interrupt_out_endpoint;
-	struct urb*		interrupt_out_urb;
+	char			*interrupt_out_buffer;
+	struct usb_endpoint_descriptor *interrupt_out_endpoint;
+	struct urb		*interrupt_out_urb;
 	int			interrupt_out_interval;
 	int			interrupt_out_busy;
 
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 10/14] USB: legousbtower: drop unnecessary packed attributes
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
                   ` (8 preceding siblings ...)
  2019-11-05  8:41 ` [PATCH 09/14] USB: legousbtower: clean up pointer declarations in driver data Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 11/14] USB: legousbtower: drop redundant endianness comments Johan Hovold
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

Drop the packed attributes from the two message structs whose fields
are naturally aligned and do not have any padding.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index c8ed8792b931..a9b08468a302 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -160,7 +160,7 @@ struct tower_reset_reply {
 	__le16 size;		/* little-endian */
 	__u8 err_code;
 	__u8 spare;
-} __attribute__ ((packed));
+};
 
 struct tower_get_version_reply {
 	__le16 size;		/* little-endian */
@@ -169,7 +169,7 @@ struct tower_get_version_reply {
 	__u8 major;
 	__u8 minor;
 	__le16 build_no;		/* little-endian */
-} __attribute__ ((packed));
+};
 
 
 /* table of devices that work with this driver */
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 11/14] USB: legousbtower: drop redundant endianness comments
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
                   ` (9 preceding siblings ...)
  2019-11-05  8:41 ` [PATCH 10/14] USB: legousbtower: drop unnecessary packed attributes Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 12/14] USB: legousbtower: clean up runaway white space Johan Hovold
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

The endianness is already encoded in the type specifier so drop the
redundant little-endian comments from the message structs.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index a9b08468a302..03f6861dfdf0 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -157,18 +157,18 @@ MODULE_PARM_DESC(interrupt_out_interval, "Interrupt out interval in ms");
 #define LEGO_USB_TOWER_REQUEST_GET_VERSION	0xFD
 
 struct tower_reset_reply {
-	__le16 size;		/* little-endian */
+	__le16 size;
 	__u8 err_code;
 	__u8 spare;
 };
 
 struct tower_get_version_reply {
-	__le16 size;		/* little-endian */
+	__le16 size;
 	__u8 err_code;
 	__u8 spare;
 	__u8 major;
 	__u8 minor;
-	__le16 build_no;		/* little-endian */
+	__le16 build_no;
 };
 
 
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 12/14] USB: legousbtower: clean up runaway white space
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
                   ` (10 preceding siblings ...)
  2019-11-05  8:41 ` [PATCH 11/14] USB: legousbtower: drop redundant endianness comments Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 13/14] USB: legousbtower: drop superfluous brackets Johan Hovold
  2019-11-05  8:41 ` [PATCH 14/14] USB: legousbtower: drop superfluous newlines Johan Hovold
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

Drop space between function identifiers and opening parenthesis, which
was no longer even used consistently within the driver.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 172 ++++++++++++++++----------------
 1 file changed, 87 insertions(+), 85 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 03f6861dfdf0..6f34b3802332 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -178,7 +178,7 @@ static const struct usb_device_id tower_table[] = {
 	{ }					/* Terminating entry */
 };
 
-MODULE_DEVICE_TABLE (usb, tower_table);
+MODULE_DEVICE_TABLE(usb, tower_table);
 
 #define LEGO_USB_TOWER_MINOR_BASE	160
 
@@ -218,20 +218,20 @@ struct lego_usb_tower {
 
 
 /* local function prototypes */
-static ssize_t tower_read	(struct file *file, char __user *buffer, size_t count, loff_t *ppos);
-static ssize_t tower_write	(struct file *file, const char __user *buffer, size_t count, loff_t *ppos);
-static inline void tower_delete (struct lego_usb_tower *dev);
-static int tower_open		(struct inode *inode, struct file *file);
-static int tower_release	(struct inode *inode, struct file *file);
-static __poll_t tower_poll	(struct file *file, poll_table *wait);
-static loff_t tower_llseek	(struct file *file, loff_t off, int whence);
+static ssize_t tower_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos);
+static ssize_t tower_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos);
+static inline void tower_delete(struct lego_usb_tower *dev);
+static int tower_open(struct inode *inode, struct file *file);
+static int tower_release(struct inode *inode, struct file *file);
+static __poll_t tower_poll(struct file *file, poll_table *wait);
+static loff_t tower_llseek(struct file *file, loff_t off, int whence);
 
-static void tower_check_for_read_packet (struct lego_usb_tower *dev);
-static void tower_interrupt_in_callback (struct urb *urb);
-static void tower_interrupt_out_callback (struct urb *urb);
+static void tower_check_for_read_packet(struct lego_usb_tower *dev);
+static void tower_interrupt_in_callback(struct urb *urb);
+static void tower_interrupt_out_callback(struct urb *urb);
 
-static int  tower_probe	(struct usb_interface *interface, const struct usb_device_id *id);
-static void tower_disconnect	(struct usb_interface *interface);
+static int  tower_probe(struct usb_interface *interface, const struct usb_device_id *id);
+static void tower_disconnect(struct usb_interface *interface);
 
 
 /* file operations needed when we register this driver */
@@ -286,23 +286,23 @@ static inline void lego_usb_tower_debug_data(struct device *dev,
 /**
  *	tower_delete
  */
-static inline void tower_delete (struct lego_usb_tower *dev)
+static inline void tower_delete(struct lego_usb_tower *dev)
 {
 	/* free data structures */
 	usb_free_urb(dev->interrupt_in_urb);
 	usb_free_urb(dev->interrupt_out_urb);
-	kfree (dev->read_buffer);
-	kfree (dev->interrupt_in_buffer);
-	kfree (dev->interrupt_out_buffer);
+	kfree(dev->read_buffer);
+	kfree(dev->interrupt_in_buffer);
+	kfree(dev->interrupt_out_buffer);
 	usb_put_dev(dev->udev);
-	kfree (dev);
+	kfree(dev);
 }
 
 
 /**
  *	tower_open
  */
-static int tower_open (struct inode *inode, struct file *file)
+static int tower_open(struct inode *inode, struct file *file)
 {
 	struct lego_usb_tower *dev = NULL;
 	int subminor;
@@ -321,7 +321,7 @@ static int tower_open (struct inode *inode, struct file *file)
 	nonseekable_open(inode, file);
 	subminor = iminor(inode);
 
-	interface = usb_find_interface (&tower_driver, subminor);
+	interface = usb_find_interface(&tower_driver, subminor);
 
 	if (!interface) {
 		pr_err("error, can't find device for minor %d\n", subminor);
@@ -349,15 +349,15 @@ static int tower_open (struct inode *inode, struct file *file)
 	}
 
 	/* reset the tower */
-	result = usb_control_msg (dev->udev,
-				  usb_rcvctrlpipe(dev->udev, 0),
-				  LEGO_USB_TOWER_REQUEST_RESET,
-				  USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE,
-				  0,
-				  0,
-				  reset_reply,
-				  sizeof(*reset_reply),
-				  1000);
+	result = usb_control_msg(dev->udev,
+				 usb_rcvctrlpipe(dev->udev, 0),
+				 LEGO_USB_TOWER_REQUEST_RESET,
+				 USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE,
+				 0,
+				 0,
+				 reset_reply,
+				 sizeof(*reset_reply),
+				 1000);
 	if (result < 0) {
 		dev_err(&dev->udev->dev,
 			"LEGO USB Tower reset control request failed\n");
@@ -368,19 +368,19 @@ static int tower_open (struct inode *inode, struct file *file)
 	/* initialize in direction */
 	dev->read_buffer_length = 0;
 	dev->read_packet_length = 0;
-	usb_fill_int_urb (dev->interrupt_in_urb,
-			  dev->udev,
-			  usb_rcvintpipe(dev->udev, dev->interrupt_in_endpoint->bEndpointAddress),
-			  dev->interrupt_in_buffer,
-			  usb_endpoint_maxp(dev->interrupt_in_endpoint),
-			  tower_interrupt_in_callback,
-			  dev,
-			  dev->interrupt_in_interval);
+	usb_fill_int_urb(dev->interrupt_in_urb,
+			 dev->udev,
+			 usb_rcvintpipe(dev->udev, dev->interrupt_in_endpoint->bEndpointAddress),
+			 dev->interrupt_in_buffer,
+			 usb_endpoint_maxp(dev->interrupt_in_endpoint),
+			 tower_interrupt_in_callback,
+			 dev,
+			 dev->interrupt_in_interval);
 
 	dev->interrupt_in_done = 0;
 	mb();
 
-	retval = usb_submit_urb (dev->interrupt_in_urb, GFP_KERNEL);
+	retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
 	if (retval) {
 		dev_err(&dev->udev->dev,
 			"Couldn't submit interrupt_in_urb %d\n", retval);
@@ -403,7 +403,7 @@ static int tower_open (struct inode *inode, struct file *file)
 /**
  *	tower_release
  */
-static int tower_release (struct inode *inode, struct file *file)
+static int tower_release(struct inode *inode, struct file *file)
 {
 	struct lego_usb_tower *dev;
 	int retval = 0;
@@ -422,13 +422,14 @@ static int tower_release (struct inode *inode, struct file *file)
 
 		/* unlock here as tower_delete frees dev */
 		mutex_unlock(&dev->lock);
-		tower_delete (dev);
+		tower_delete(dev);
 		goto exit;
 	}
 
 	/* wait until write transfer is finished */
 	if (dev->interrupt_out_busy) {
-		wait_event_interruptible_timeout (dev->write_wait, !dev->interrupt_out_busy, 2 * HZ);
+		wait_event_interruptible_timeout(dev->write_wait, !dev->interrupt_out_busy,
+						 2 * HZ);
 	}
 
 	/* shutdown transfers */
@@ -450,23 +451,23 @@ static int tower_release (struct inode *inode, struct file *file)
  *      until it has been there unchanged for at least
  *      dev->packet_timeout_jiffies, or until the buffer is full.
  */
-static void tower_check_for_read_packet (struct lego_usb_tower *dev)
+static void tower_check_for_read_packet(struct lego_usb_tower *dev)
 {
-	spin_lock_irq (&dev->read_buffer_lock);
+	spin_lock_irq(&dev->read_buffer_lock);
 	if (!packet_timeout
 	    || time_after(jiffies, dev->read_last_arrival + dev->packet_timeout_jiffies)
 	    || dev->read_buffer_length == read_buffer_size) {
 		dev->read_packet_length = dev->read_buffer_length;
 	}
 	dev->interrupt_in_done = 0;
-	spin_unlock_irq (&dev->read_buffer_lock);
+	spin_unlock_irq(&dev->read_buffer_lock);
 }
 
 
 /**
  *	tower_poll
  */
-static __poll_t tower_poll (struct file *file, poll_table *wait)
+static __poll_t tower_poll(struct file *file, poll_table *wait)
 {
 	struct lego_usb_tower *dev;
 	__poll_t mask = 0;
@@ -494,7 +495,7 @@ static __poll_t tower_poll (struct file *file, poll_table *wait)
 /**
  *	tower_llseek
  */
-static loff_t tower_llseek (struct file *file, loff_t off, int whence)
+static loff_t tower_llseek(struct file *file, loff_t off, int whence)
 {
 	return -ESPIPE;		/* unseekable */
 }
@@ -503,7 +504,7 @@ static loff_t tower_llseek (struct file *file, loff_t off, int whence)
 /**
  *	tower_read
  */
-static ssize_t tower_read (struct file *file, char __user *buffer, size_t count, loff_t *ppos)
+static ssize_t tower_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
 {
 	struct lego_usb_tower *dev;
 	size_t bytes_to_read;
@@ -536,7 +537,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
 	}
 
 	/* wait for data */
-	tower_check_for_read_packet (dev);
+	tower_check_for_read_packet(dev);
 	while (dev->read_packet_length == 0) {
 		if (file->f_flags & O_NONBLOCK) {
 			retval = -EAGAIN;
@@ -553,28 +554,28 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
 			timeout = jiffies + msecs_to_jiffies(read_timeout);
 		}
 		/* check for read timeout */
-		if (read_timeout && time_after (jiffies, timeout)) {
+		if (read_timeout && time_after(jiffies, timeout)) {
 			retval = -ETIMEDOUT;
 			goto unlock_exit;
 		}
-		tower_check_for_read_packet (dev);
+		tower_check_for_read_packet(dev);
 	}
 
 	/* copy the data from read_buffer into userspace */
 	bytes_to_read = min(count, dev->read_packet_length);
 
-	if (copy_to_user (buffer, dev->read_buffer, bytes_to_read)) {
+	if (copy_to_user(buffer, dev->read_buffer, bytes_to_read)) {
 		retval = -EFAULT;
 		goto unlock_exit;
 	}
 
-	spin_lock_irq (&dev->read_buffer_lock);
+	spin_lock_irq(&dev->read_buffer_lock);
 	dev->read_buffer_length -= bytes_to_read;
 	dev->read_packet_length -= bytes_to_read;
 	for (i=0; i<dev->read_buffer_length; i++) {
 		dev->read_buffer[i] = dev->read_buffer[i+bytes_to_read];
 	}
-	spin_unlock_irq (&dev->read_buffer_lock);
+	spin_unlock_irq(&dev->read_buffer_lock);
 
 	retval = bytes_to_read;
 
@@ -590,7 +591,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
 /**
  *	tower_write
  */
-static ssize_t tower_write (struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
+static ssize_t tower_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
 {
 	struct lego_usb_tower *dev;
 	size_t bytes_to_write;
@@ -622,7 +623,8 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
 			retval = -EAGAIN;
 			goto unlock_exit;
 		}
-		retval = wait_event_interruptible (dev->write_wait, !dev->interrupt_out_busy);
+		retval = wait_event_interruptible(dev->write_wait,
+						  !dev->interrupt_out_busy);
 		if (retval) {
 			goto unlock_exit;
 		}
@@ -633,7 +635,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
 	dev_dbg(&dev->udev->dev, "%s: count = %zd, bytes_to_write = %zd\n",
 		__func__, count, bytes_to_write);
 
-	if (copy_from_user (dev->interrupt_out_buffer, buffer, bytes_to_write)) {
+	if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
 		retval = -EFAULT;
 		goto unlock_exit;
 	}
@@ -651,7 +653,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
 	dev->interrupt_out_busy = 1;
 	wmb();
 
-	retval = usb_submit_urb (dev->interrupt_out_urb, GFP_KERNEL);
+	retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);
 	if (retval) {
 		dev->interrupt_out_busy = 0;
 		dev_err(&dev->udev->dev,
@@ -672,7 +674,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
 /**
  *	tower_interrupt_in_callback
  */
-static void tower_interrupt_in_callback (struct urb *urb)
+static void tower_interrupt_in_callback(struct urb *urb)
 {
 	struct lego_usb_tower *dev = urb->context;
 	int status = urb->status;
@@ -698,9 +700,9 @@ static void tower_interrupt_in_callback (struct urb *urb)
 	if (urb->actual_length > 0) {
 		spin_lock_irqsave(&dev->read_buffer_lock, flags);
 		if (dev->read_buffer_length + urb->actual_length < read_buffer_size) {
-			memcpy (dev->read_buffer + dev->read_buffer_length,
-				dev->interrupt_in_buffer,
-				urb->actual_length);
+			memcpy(dev->read_buffer + dev->read_buffer_length,
+			       dev->interrupt_in_buffer,
+			       urb->actual_length);
 			dev->read_buffer_length += urb->actual_length;
 			dev->read_last_arrival = jiffies;
 			dev_dbg(&dev->udev->dev, "%s: received %d bytes\n",
@@ -720,14 +722,14 @@ static void tower_interrupt_in_callback (struct urb *urb)
 	}
 exit:
 	dev->interrupt_in_done = 1;
-	wake_up_interruptible (&dev->read_wait);
+	wake_up_interruptible(&dev->read_wait);
 }
 
 
 /**
  *	tower_interrupt_out_callback
  */
-static void tower_interrupt_out_callback (struct urb *urb)
+static void tower_interrupt_out_callback(struct urb *urb)
 {
 	struct lego_usb_tower *dev = urb->context;
 	int status = urb->status;
@@ -755,7 +757,7 @@ static void tower_interrupt_out_callback (struct urb *urb)
  *	Called by the usb core when a new device is connected that it thinks
  *	this driver might be interested in.
  */
-static int tower_probe (struct usb_interface *interface, const struct usb_device_id *id)
+static int tower_probe(struct usb_interface *interface, const struct usb_device_id *id)
 {
 	struct device *idev = &interface->dev;
 	struct usb_device *udev = interface_to_usbdev(interface);
@@ -771,11 +773,11 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
 
 	mutex_init(&dev->lock);
 	dev->udev = usb_get_dev(udev);
-	spin_lock_init (&dev->read_buffer_lock);
+	spin_lock_init(&dev->read_buffer_lock);
 	dev->packet_timeout_jiffies = msecs_to_jiffies(packet_timeout);
 	dev->read_last_arrival = jiffies;
-	init_waitqueue_head (&dev->read_wait);
-	init_waitqueue_head (&dev->write_wait);
+	init_waitqueue_head(&dev->read_wait);
+	init_waitqueue_head(&dev->write_wait);
 
 	result = usb_find_common_endpoints_reverse(interface->cur_altsetting,
 			NULL, NULL,
@@ -787,16 +789,16 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
 		goto error;
 	}
 
-	dev->read_buffer = kmalloc (read_buffer_size, GFP_KERNEL);
+	dev->read_buffer = kmalloc(read_buffer_size, GFP_KERNEL);
 	if (!dev->read_buffer)
 		goto error;
-	dev->interrupt_in_buffer = kmalloc (usb_endpoint_maxp(dev->interrupt_in_endpoint), GFP_KERNEL);
+	dev->interrupt_in_buffer = kmalloc(usb_endpoint_maxp(dev->interrupt_in_endpoint), GFP_KERNEL);
 	if (!dev->interrupt_in_buffer)
 		goto error;
 	dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
 	if (!dev->interrupt_in_urb)
 		goto error;
-	dev->interrupt_out_buffer = kmalloc (write_buffer_size, GFP_KERNEL);
+	dev->interrupt_out_buffer = kmalloc(write_buffer_size, GFP_KERNEL);
 	if (!dev->interrupt_out_buffer)
 		goto error;
 	dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
@@ -813,15 +815,15 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
 	}
 
 	/* get the firmware version and log it */
-	result = usb_control_msg (udev,
-				  usb_rcvctrlpipe(udev, 0),
-				  LEGO_USB_TOWER_REQUEST_GET_VERSION,
-				  USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE,
-				  0,
-				  0,
-				  get_version_reply,
-				  sizeof(*get_version_reply),
-				  1000);
+	result = usb_control_msg(udev,
+				 usb_rcvctrlpipe(udev, 0),
+				 LEGO_USB_TOWER_REQUEST_GET_VERSION,
+				 USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE,
+				 0,
+				 0,
+				 get_version_reply,
+				 sizeof(*get_version_reply),
+				 1000);
 	if (result != sizeof(*get_version_reply)) {
 		if (result >= 0)
 			result = -EIO;
@@ -836,9 +838,9 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
 		 le16_to_cpu(get_version_reply->build_no));
 
 	/* we can register the device now, as it is ready */
-	usb_set_intfdata (interface, dev);
+	usb_set_intfdata(interface, dev);
 
-	retval = usb_register_dev (interface, &tower_class);
+	retval = usb_register_dev(interface, &tower_class);
 
 	if (retval) {
 		/* something prevented us from registering this driver */
@@ -868,17 +870,17 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
  *
  *	Called by the usb core when the device is removed from the system.
  */
-static void tower_disconnect (struct usb_interface *interface)
+static void tower_disconnect(struct usb_interface *interface)
 {
 	struct lego_usb_tower *dev;
 	int minor;
 
-	dev = usb_get_intfdata (interface);
+	dev = usb_get_intfdata(interface);
 
 	minor = dev->minor;
 
 	/* give back our minor and prevent further open() */
-	usb_deregister_dev (interface, &tower_class);
+	usb_deregister_dev(interface, &tower_class);
 
 	/* stop I/O */
 	usb_poison_urb(dev->interrupt_in_urb);
@@ -889,7 +891,7 @@ static void tower_disconnect (struct usb_interface *interface)
 	/* if the device is not opened, then we clean up right now */
 	if (!dev->open_count) {
 		mutex_unlock(&dev->lock);
-		tower_delete (dev);
+		tower_delete(dev);
 	} else {
 		dev->disconnected = 1;
 		/* wake up pollers */
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 13/14] USB: legousbtower: drop superfluous brackets
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
                   ` (11 preceding siblings ...)
  2019-11-05  8:41 ` [PATCH 12/14] USB: legousbtower: clean up runaway white space Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  2019-11-05  8:41 ` [PATCH 14/14] USB: legousbtower: drop superfluous newlines Johan Hovold
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

Drop superfluous brackets around single-line blocks.

Also add missing white space around operators in a for-expression being
modified.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 6f34b3802332..6b7ea80d5876 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -481,12 +481,10 @@ static __poll_t tower_poll(struct file *file, poll_table *wait)
 	poll_wait(file, &dev->write_wait, wait);
 
 	tower_check_for_read_packet(dev);
-	if (dev->read_packet_length > 0) {
+	if (dev->read_packet_length > 0)
 		mask |= EPOLLIN | EPOLLRDNORM;
-	}
-	if (!dev->interrupt_out_busy) {
+	if (!dev->interrupt_out_busy)
 		mask |= EPOLLOUT | EPOLLWRNORM;
-	}
 
 	return mask;
 }
@@ -532,9 +530,8 @@ static ssize_t tower_read(struct file *file, char __user *buffer, size_t count,
 		goto unlock_exit;
 	}
 
-	if (read_timeout) {
+	if (read_timeout)
 		timeout = jiffies + msecs_to_jiffies(read_timeout);
-	}
 
 	/* wait for data */
 	tower_check_for_read_packet(dev);
@@ -544,9 +541,8 @@ static ssize_t tower_read(struct file *file, char __user *buffer, size_t count,
 			goto unlock_exit;
 		}
 		retval = wait_event_interruptible_timeout(dev->read_wait, dev->interrupt_in_done, dev->packet_timeout_jiffies);
-		if (retval < 0) {
+		if (retval < 0)
 			goto unlock_exit;
-		}
 
 		/* reset read timeout during read or write activity */
 		if (read_timeout
@@ -572,9 +568,8 @@ static ssize_t tower_read(struct file *file, char __user *buffer, size_t count,
 	spin_lock_irq(&dev->read_buffer_lock);
 	dev->read_buffer_length -= bytes_to_read;
 	dev->read_packet_length -= bytes_to_read;
-	for (i=0; i<dev->read_buffer_length; i++) {
+	for (i = 0; i < dev->read_buffer_length; i++)
 		dev->read_buffer[i] = dev->read_buffer[i+bytes_to_read];
-	}
 	spin_unlock_irq(&dev->read_buffer_lock);
 
 	retval = bytes_to_read;
@@ -625,9 +620,8 @@ static ssize_t tower_write(struct file *file, const char __user *buffer, size_t
 		}
 		retval = wait_event_interruptible(dev->write_wait,
 						  !dev->interrupt_out_busy);
-		if (retval) {
+		if (retval)
 			goto unlock_exit;
-		}
 	}
 
 	/* write the data into interrupt_out_buffer from userspace */
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 14/14] USB: legousbtower: drop superfluous newlines
  2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
                   ` (12 preceding siblings ...)
  2019-11-05  8:41 ` [PATCH 13/14] USB: legousbtower: drop superfluous brackets Johan Hovold
@ 2019-11-05  8:41 ` Johan Hovold
  13 siblings, 0 replies; 15+ messages in thread
From: Johan Hovold @ 2019-11-05  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Juergen Stuber, legousb-devel, linux-usb, Johan Hovold

Drop some superfluous newlines before conditionals which made the code
harder to read.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/misc/legousbtower.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 6b7ea80d5876..ab4b98b04115 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -312,7 +312,6 @@ static int tower_open(struct inode *inode, struct file *file)
 	int result;
 
 	reset_reply = kmalloc(sizeof(*reset_reply), GFP_KERNEL);
-
 	if (!reset_reply) {
 		retval = -ENOMEM;
 		goto exit;
@@ -322,7 +321,6 @@ static int tower_open(struct inode *inode, struct file *file)
 	subminor = iminor(inode);
 
 	interface = usb_find_interface(&tower_driver, subminor);
-
 	if (!interface) {
 		pr_err("error, can't find device for minor %d\n", subminor);
 		retval = -ENODEV;
@@ -409,7 +407,6 @@ static int tower_release(struct inode *inode, struct file *file)
 	int retval = 0;
 
 	dev = file->private_data;
-
 	if (dev == NULL) {
 		retval = -ENODEV;
 		goto exit;
@@ -802,7 +799,6 @@ static int tower_probe(struct usb_interface *interface, const struct usb_device_
 	dev->interrupt_out_interval = interrupt_out_interval ? interrupt_out_interval : dev->interrupt_out_endpoint->bInterval;
 
 	get_version_reply = kmalloc(sizeof(*get_version_reply), GFP_KERNEL);
-
 	if (!get_version_reply) {
 		retval = -ENOMEM;
 		goto error;
@@ -835,7 +831,6 @@ static int tower_probe(struct usb_interface *interface, const struct usb_device_
 	usb_set_intfdata(interface, dev);
 
 	retval = usb_register_dev(interface, &tower_class);
-
 	if (retval) {
 		/* something prevented us from registering this driver */
 		dev_err(idev, "Not able to get a minor for this device.\n");
-- 
2.23.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, back to index

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-05  8:41 [PATCH 00/14] USB: legousbtower: misc cleanups Johan Hovold
2019-11-05  8:41 ` [PATCH 01/14] USB: legousbtower: drop redundant MODULE_LICENSE ifdef Johan Hovold
2019-11-05  8:41 ` [PATCH 02/14] USB: legousbtower: drop redundant NULL check Johan Hovold
2019-11-05  8:41 ` [PATCH 03/14] USB: legousbtower: zero driver data at allocation Johan Hovold
2019-11-05  8:41 ` [PATCH 04/14] USB: legousbtower: drop redundant open_count check Johan Hovold
2019-11-05  8:41 ` [PATCH 05/14] USB: legousbtower: drop noisy disconnect messages Johan Hovold
2019-11-05  8:41 ` [PATCH 06/14] USB: legousbtower: drop redundant interrupt-in running flag Johan Hovold
2019-11-05  8:41 ` [PATCH 07/14] USB: legousbtower: stop interrupt-out URB unconditionally Johan Hovold
2019-11-05  8:41 ` [PATCH 08/14] USB: legousbtower: remove tower_abort_transfers() Johan Hovold
2019-11-05  8:41 ` [PATCH 09/14] USB: legousbtower: clean up pointer declarations in driver data Johan Hovold
2019-11-05  8:41 ` [PATCH 10/14] USB: legousbtower: drop unnecessary packed attributes Johan Hovold
2019-11-05  8:41 ` [PATCH 11/14] USB: legousbtower: drop redundant endianness comments Johan Hovold
2019-11-05  8:41 ` [PATCH 12/14] USB: legousbtower: clean up runaway white space Johan Hovold
2019-11-05  8:41 ` [PATCH 13/14] USB: legousbtower: drop superfluous brackets Johan Hovold
2019-11-05  8:41 ` [PATCH 14/14] USB: legousbtower: drop superfluous newlines Johan Hovold

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git