2020-06-28 01:51:08

by Zhang, Qiang

[permalink] [raw]
Subject: [PATCH] usb: gadget: function: printer: The device interface is reset and should return error code

From: Zqiang <[email protected]>

After the device is disconnected from the host side, the interface of
the device is reset. If the userspace operates the device again,
an error code should be returned.

Signed-off-by: Zqiang <[email protected]>
---
drivers/usb/gadget/function/f_printer.c | 36 +++++++++++++++++++++++++
1 file changed, 36 insertions(+)

diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c
index 9c7ed2539ff7..2b45a61e4213 100644
--- a/drivers/usb/gadget/function/f_printer.c
+++ b/drivers/usb/gadget/function/f_printer.c
@@ -338,6 +338,11 @@ printer_open(struct inode *inode, struct file *fd)

spin_lock_irqsave(&dev->lock, flags);

+ if (dev->interface < 0) {
+ spin_unlock_irqrestore(&dev->lock, flags);
+ return -ENODEV;
+ }
+
if (!dev->printer_cdev_open) {
dev->printer_cdev_open = 1;
fd->private_data = dev;
@@ -430,6 +435,12 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
mutex_lock(&dev->lock_printer_io);
spin_lock_irqsave(&dev->lock, flags);

+ if (dev->interface < 0) {
+ spin_unlock_irqrestore(&dev->lock, flags);
+ mutex_unlock(&dev->lock_printer_io);
+ return -ENODEV;
+ }
+
/* We will use this flag later to check if a printer reset happened
* after we turn interrupts back on.
*/
@@ -561,6 +572,12 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
mutex_lock(&dev->lock_printer_io);
spin_lock_irqsave(&dev->lock, flags);

+ if (dev->interface < 0) {
+ spin_unlock_irqrestore(&dev->lock, flags);
+ mutex_unlock(&dev->lock_printer_io);
+ return -ENODEV;
+ }
+
/* Check if a printer reset happens while we have interrupts on */
dev->reset_printer = 0;

@@ -667,6 +684,13 @@ printer_fsync(struct file *fd, loff_t start, loff_t end, int datasync)

inode_lock(inode);
spin_lock_irqsave(&dev->lock, flags);
+
+ if (dev->interface < 0) {
+ spin_unlock_irqrestore(&dev->lock, flags);
+ inode_unlock(inode);
+ return -ENODEV;
+ }
+
tx_list_empty = (likely(list_empty(&dev->tx_reqs)));
spin_unlock_irqrestore(&dev->lock, flags);

@@ -689,6 +713,13 @@ printer_poll(struct file *fd, poll_table *wait)

mutex_lock(&dev->lock_printer_io);
spin_lock_irqsave(&dev->lock, flags);
+
+ if (dev->interface < 0) {
+ spin_unlock_irqrestore(&dev->lock, flags);
+ mutex_unlock(&dev->lock_printer_io);
+ return EPOLLERR | EPOLLHUP;
+ }
+
setup_rx_reqs(dev);
spin_unlock_irqrestore(&dev->lock, flags);
mutex_unlock(&dev->lock_printer_io);
@@ -722,6 +753,11 @@ printer_ioctl(struct file *fd, unsigned int code, unsigned long arg)

spin_lock_irqsave(&dev->lock, flags);

+ if (dev->interface < 0) {
+ spin_unlock_irqrestore(&dev->lock, flags);
+ return -ENODEV;
+ }
+
switch (code) {
case GADGET_GET_PRINTER_STATUS:
status = (int)dev->printer_status;
--
2.24.1


2020-06-28 13:43:57

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH] usb: gadget: function: printer: The device interface is reset and should return error code

I suggest to choose a more succinct patch subject.


> After the device is disconnected from the host side, the interface of
> the device is reset. If the userspace operates the device again,
> an error code should be returned.

Please use an imperative wording for the commit message.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=719fdd32921fb7e3208db8832d32ae1c2d68900f#n151


> Signed-off-by: Zqiang <[email protected]>

Did you really specify your real name here?

Regards,
Markus

2020-06-28 14:14:27

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] usb: gadget: function: printer: The device interface is reset and should return error code

On Sun, Jun 28, 2020 at 03:43:10PM +0200, Markus Elfring wrote:
> I suggest to choose a more succinct patch subject.
>
>
> > After the device is disconnected from the host side, the interface of
> > the device is reset. If the userspace operates the device again,
> > an error code should be returned.
>
> Please use an imperative wording for the commit message.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=719fdd32921fb7e3208db8832d32ae1c2d68900f#n151
>
>
> > Signed-off-by: Zqiang <[email protected]>
>
> Did you really specify your real name here?
>
> Regards,
> Markus

Hi,

This is the semi-friendly patch-bot of Greg Kroah-Hartman.

Markus, you seem to have sent a nonsensical or otherwise pointless
review comment to a patch submission on a Linux kernel developer mailing
list. I strongly suggest that you not do this anymore. Please do not
bother developers who are actively working to produce patches and
features with comments that, in the end, are a waste of time.

Patch submitter, please ignore Markus's suggestion; you do not need to
follow it at all. The person/bot/AI that sent it is being ignored by
almost all Linux kernel maintainers for having a persistent pattern of
behavior of producing distracting and pointless commentary, and
inability to adapt to feedback. Please feel free to also ignore emails
from them.

thanks,

greg k-h's patch email bot

2020-06-30 01:22:23

by Zhang, Qiang

[permalink] [raw]
Subject: 回复: [PATCH] usb: gadget: function: printer: The device interface is reset and should ret urn error code

Hi Felipe,

Please check this patch and make suggestions .

Thanks
Zqiang

________________________________________
??????: [email protected] <[email protected]> ???? [email protected] <[email protected]>
????ʱ??: 2020??6??28?? 9:57
?ռ???: [email protected]
????: [email protected]; [email protected]; [email protected]
????: [PATCH] usb: gadget: function: printer: The device interface is reset and should return error code

From: Zqiang <[email protected]>

After the device is disconnected from the host side, the interface of
the device is reset. If the userspace operates the device again,
an error code should be returned.

Signed-off-by: Zqiang <[email protected]>
---
drivers/usb/gadget/function/f_printer.c | 36 +++++++++++++++++++++++++
1 file changed, 36 insertions(+)

diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c
index 9c7ed2539ff7..2b45a61e4213 100644
--- a/drivers/usb/gadget/function/f_printer.c
+++ b/drivers/usb/gadget/function/f_printer.c
@@ -338,6 +338,11 @@ printer_open(struct inode *inode, struct file *fd)

spin_lock_irqsave(&dev->lock, flags);

+ if (dev->interface < 0) {
+ spin_unlock_irqrestore(&dev->lock, flags);
+ return -ENODEV;
+ }
+
if (!dev->printer_cdev_open) {
dev->printer_cdev_open = 1;
fd->private_data = dev;
@@ -430,6 +435,12 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
mutex_lock(&dev->lock_printer_io);
spin_lock_irqsave(&dev->lock, flags);

+ if (dev->interface < 0) {
+ spin_unlock_irqrestore(&dev->lock, flags);
+ mutex_unlock(&dev->lock_printer_io);
+ return -ENODEV;
+ }
+
/* We will use this flag later to check if a printer reset happened
* after we turn interrupts back on.
*/
@@ -561,6 +572,12 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
mutex_lock(&dev->lock_printer_io);
spin_lock_irqsave(&dev->lock, flags);

+ if (dev->interface < 0) {
+ spin_unlock_irqrestore(&dev->lock, flags);
+ mutex_unlock(&dev->lock_printer_io);
+ return -ENODEV;
+ }
+
/* Check if a printer reset happens while we have interrupts on */
dev->reset_printer = 0;

@@ -667,6 +684,13 @@ printer_fsync(struct file *fd, loff_t start, loff_t end, int datasync)

inode_lock(inode);
spin_lock_irqsave(&dev->lock, flags);
+
+ if (dev->interface < 0) {
+ spin_unlock_irqrestore(&dev->lock, flags);
+ inode_unlock(inode);
+ return -ENODEV;
+ }
+
tx_list_empty = (likely(list_empty(&dev->tx_reqs)));
spin_unlock_irqrestore(&dev->lock, flags);

@@ -689,6 +713,13 @@ printer_poll(struct file *fd, poll_table *wait)

mutex_lock(&dev->lock_printer_io);
spin_lock_irqsave(&dev->lock, flags);
+
+ if (dev->interface < 0) {
+ spin_unlock_irqrestore(&dev->lock, flags);
+ mutex_unlock(&dev->lock_printer_io);
+ return EPOLLERR | EPOLLHUP;
+ }
+
setup_rx_reqs(dev);
spin_unlock_irqrestore(&dev->lock, flags);
mutex_unlock(&dev->lock_printer_io);
@@ -722,6 +753,11 @@ printer_ioctl(struct file *fd, unsigned int code, unsigned long arg)

spin_lock_irqsave(&dev->lock, flags);

+ if (dev->interface < 0) {
+ spin_unlock_irqrestore(&dev->lock, flags);
+ return -ENODEV;
+ }
+
switch (code) {
case GADGET_GET_PRINTER_STATUS:
status = (int)dev->printer_status;
--
2.24.1