Re: [PATCH 20/29] usb: gadget: composite: add req_match method to usb_function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



W dniu 02.03.2015 o 23:03, Bin Liu pisze:
Hi,

On Mon, Feb 23, 2015 at 9:02 AM, Andrzej Pietrasiewicz
<andrzej.p@xxxxxxxxxxx> wrote:
Non-standard requests can encode the actual interface number in a
non-standard way. For example composite_setup() assumes
that it is w_index && 0xFF, but the printer function encodes the interface
number in a context-dependet way (either w_index or w_index >> 8).
This can lead to such requests being directed to wrong functions.

This patch adds req_match() method to usb_function. Its purpose is to
verify that a given request can be handled by a given function.
If any function within a configuration provides the method and it returns
true, then it is assumed that the right function is found.

If a function uses req_match(), it should try as hard as possible to
determine if the request is meant for it.

If no functions in a configuration provide req_match or none of them
returns true, then fall back to the usual approach.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@xxxxxxxxxxx>
---
  drivers/usb/gadget/composite.c | 7 ++++++-
  include/linux/usb/composite.h  | 3 +++
  2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 9fb9231..07cee80 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1758,6 +1758,11 @@ unknown:
                  * take such requests too, if that's ever needed:  to work
                  * in config 0, etc.
                  */
+               list_for_each_entry(f, &cdev->config->functions, list)
+                       if (f->req_match && f->req_match(f, ctrl))
+                               break;

In this loop, if f->req_match is NULL, or f->req_match() returns
false, f becomes non-NULL at the end of the loop, which causes kernel
panic later.

+               if (&f->list != &cdev->config->functions)
+                       goto try_fun_setup;

The following change fixes it.

+               list_for_each_entry(f, &cdev->config->functions, list)
+                       if (f->req_match && f->req_match(f, ctrl))
+                               goto try_fun_setup;
+
+               f = NULL;
+

Right. Thanks!

AP

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux