Skip to contentSkip to conversation

Fix default q_len for usb_f_printer gadget driver

PATCH In review Michael R Sweet 2 participants 4 messages Oct 30, 2020 – Dec 10, 2020 1 message not in the archive USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix default q_len for usb_f_printer gadget driver

The usb_f_printer gadget driver uses a default q_len value of *0* which prevents any IO from occurring. Moreover, once the driver is instantiated it is impossible to change the q_len value.

The following patch uses a default q_len value of 10 which matches the legacy g_printer gadget driver. This minimizes the possibility that you end up with a non-working printer gadget. It is still possible to set the q_len to a different value using the configfs path of the same name.

---
 drivers/usb/gadget/function/f_printer.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/usb/gadget/function/f_printer.c +5 -0
index 9c7ed2539ff7..4f3161005e4f 100644
@@ -50,6 +50,8 @@
 #define GET_PORT_STATUS		1
 #define SOFT_RESET		2
 
+#define DEFAULT_Q_LEN		10 /* same as legacy g_printer gadget */
+
 static int major, minors;
 static struct class *usb_gadget_class;
 static DEFINE_IDA(printer_ida);
@@ -1317,6 +1319,9 @@ static struct usb_function_instance *gprinter_alloc_inst(void)
 	opts->func_inst.free_func_inst = gprinter_free_inst;
 	ret = &opts->func_inst;
 
+	/* Make sure q_len is initialized, otherwise the bound device can't support read/write! */
+	opts->q_len = DEFAULT_Q_LEN;
+
 	mutex_lock(&printer_ida_lock);
 
 	if (ida_is_empty(&printer_ida)) {
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Michael R Sweet

The usb_f_printer gadget driver uses a default q_len value of *0* which prevents any IO from occurring. Moreover, once the driver is instantiated it is impossible to change the q_len value.

The following patch uses a default q_len value of 10 which matches the legacy g_printer gadget driver. This minimizes the possibility that you end up with a non-working printer gadget. It is still possible to set the q_len to a different value using the configfs path of the same name.

Peter

Quoted 30 lines
---
 drivers/usb/gadget/function/f_printer.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/usb/gadget/function/f_printer.c +5 -0
index 9c7ed2539ff7..4f3161005e4f 100644
@@ -50,6 +50,8 @@
 #define GET_PORT_STATUS		1
 #define SOFT_RESET		2
 
+#define DEFAULT_Q_LEN		10 /* same as legacy g_printer gadget */
+
 static int major, minors;
 static struct class *usb_gadget_class;
 static DEFINE_IDA(printer_ida);
@@ -1317,6 +1319,9 @@ static struct usb_function_instance *gprinter_alloc_inst(void)
 	opts->func_inst.free_func_inst = gprinter_free_inst;
 	ret = &opts->func_inst;
 
+	/* Make sure q_len is initialized, otherwise the bound device can't support read/write! */
+	opts->q_len = DEFAULT_Q_LEN;
+
 	mutex_lock(&printer_ida_lock);
 
 	if (ida_is_empty(&printer_ida)) {
Signature · 1 line
2.17.1
Signature · 2 lines
Thanks,
Peter Chen
#2 lore raw
In reply to Michael R Sweet

Hi,

I submitted this a month ago, and aside from Peter Chen's "reviewed by" response I haven't heard anything nor seen it get merged. I know you are all really busy and I don't want to be a pest - is there something else I need to do to advance this patch?

Thanks!

Quoted 40 lines · Michael R Sweet

The usb_f_printer gadget driver uses a default q_len value of *0* which prevents any IO from occurring. Moreover, once the driver is instantiated it is impossible to change the q_len value.

The following patch uses a default q_len value of 10 which matches the legacy g_printer gadget driver. This minimizes the possibility that you end up with a non-working printer gadget. It is still possible to set the q_len to a different value using the configfs path of the same name.

---
drivers/usb/gadget/function/f_printer.c | 5 +++++

1 file changed, 5 insertions(+)
drivers/usb/gadget/function/f_printer.c +5 -1
index 9c7ed2539ff7..4f3161005e4f 100644
@@ -50,6 +50,8 @@
 #define GET_PORT_STATUS		1
 #define SOFT_RESET		2
 
+#define DEFAULT_Q_LEN		10 /* same as legacy g_printer gadget */
+
 static int major, minors;
 static struct class *usb_gadget_class;
 static DEFINE_IDA(printer_ida);
@@ -1317,6 +1319,9 @@ static struct usb_function_instance *gprinter_alloc_inst(void)
 	opts->func_inst.free_func_inst = gprinter_free_inst;
 	ret = &opts->func_inst;
 
+	/* Make sure q_len is initialized, otherwise the bound device can't support read/write! */
+	opts->q_len = DEFAULT_Q_LEN;
+
 	mutex_lock(&printer_ida_lock);
 
 	if (ida_is_empty(&printer_ida)) {
--
Quoted 2 lines

2.17.1

________________________
Michael Sweet

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 4 lines · Michael Sweet

Peter,

I know you had signed off on this patch at the end of October, but I haven't seen anything happen with it since then. As this is the first patch I've submitted, I don't know what else I need to do, if anything, to get it merged into the kernel sources?

Add Greg and Felipe.

Hi Michael,

Yes, I added my Reviewed-by tag at the end of Oct, but I am not the maintainer for USB Gadget, so I can't add it to my tree.

Felipe is the maintainer of USB Gadget, the accepted patch will go to his tree, and merge into the kernel.

Peter

Quoted 57 lines

Thanks!

Quoted 46 lines

Begin forwarded message:

From: Michael R Sweet <[email protected]>
Subject: [PATCH] Fix default q_len for usb_f_printer gadget driver
Date: October 30, 2020 at 6:34:19 PM EDT
To: Felipe Balbi <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>, [email protected], [email protected], [email protected]

The usb_f_printer gadget driver uses a default q_len value of *0* which prevents any IO from occurring. Moreover, once the driver is instantiated it is impossible to change the q_len value.

The following patch uses a default q_len value of 10 which matches the legacy g_printer gadget driver. This minimizes the possibility that you end up with a non-working printer gadget. It is still possible to set the q_len to a different value using the configfs path of the same name.

---
drivers/usb/gadget/function/f_printer.c | 5 +++++

1 file changed, 5 insertions(+)
drivers/usb/gadget/function/f_printer.c +5 -1
index 9c7ed2539ff7..4f3161005e4f 100644
@@ -50,6 +50,8 @@
 #define GET_PORT_STATUS		1
 #define SOFT_RESET		2
 
+#define DEFAULT_Q_LEN		10 /* same as legacy g_printer gadget */
+
 static int major, minors;
 static struct class *usb_gadget_class;
 static DEFINE_IDA(printer_ida);
@@ -1317,6 +1319,9 @@ static struct usb_function_instance *gprinter_alloc_inst(void)
 	opts->func_inst.free_func_inst = gprinter_free_inst;
 	ret = &opts->func_inst;
 
+	/* Make sure q_len is initialized, otherwise the bound device can't support read/write! */
+	opts->q_len = DEFAULT_Q_LEN;
+
 	mutex_lock(&printer_ida_lock);
 
 	if (ida_is_empty(&printer_ida)) {
--
Quoted 2 lines

2.17.1

________________________
Michael Sweet

Signature · 2 lines
Thanks,
Peter Chen