* [PATCH 1/6] usb: hub: Use more accurate struct name
@ 2019-10-10 8:14 Jules Maselbas
2019-10-10 8:14 ` [PATCH 2/6] usb: hub: Only clear port reset status if set Jules Maselbas
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Jules Maselbas @ 2019-10-10 8:14 UTC (permalink / raw)
To: barebox; +Cc: Jules Maselbas
Both structures usb_hub_status and usb_port_status have the same
fields, only the name differ.
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
drivers/usb/core/hub.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index d01a01607..91a938567 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -62,7 +62,7 @@ static int usb_get_port_status(struct usb_device *dev, int port, void *data)
{
return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port,
- data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT);
+ data, sizeof(struct usb_port_status), USB_CNTL_TIMEOUT);
}
--
2.21.0.196.g041f5ea
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/6] usb: hub: Only clear port reset status if set
2019-10-10 8:14 [PATCH 1/6] usb: hub: Use more accurate struct name Jules Maselbas
@ 2019-10-10 8:14 ` Jules Maselbas
2019-10-10 8:15 ` [PATCH 3/6] usb: string: Use dma_alloc instead of a local buffer Jules Maselbas
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Jules Maselbas @ 2019-10-10 8:14 UTC (permalink / raw)
To: barebox; +Cc: Jules Maselbas
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
drivers/usb/core/hub.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 91a938567..910a87021 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -158,7 +158,8 @@ int hub_port_reset(struct usb_device *hub, int port, struct usb_device *usb)
return -1;
}
- usb_clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_RESET);
+ if (portstatus & USB_PORT_STAT_C_RESET)
+ usb_clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_RESET);
if (portstatus & USB_PORT_STAT_HIGH_SPEED)
usb->speed = USB_SPEED_HIGH;
--
2.21.0.196.g041f5ea
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/6] usb: string: Use dma_alloc instead of a local buffer
2019-10-10 8:14 [PATCH 1/6] usb: hub: Use more accurate struct name Jules Maselbas
2019-10-10 8:14 ` [PATCH 2/6] usb: hub: Only clear port reset status if set Jules Maselbas
@ 2019-10-10 8:15 ` Jules Maselbas
2019-10-10 8:15 ` [PATCH 4/6] usb: string: Use le16_to_cpu for langid Jules Maselbas
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Jules Maselbas @ 2019-10-10 8:15 UTC (permalink / raw)
To: barebox; +Cc: Jules Maselbas
Stack allocated buffer can cause difficulties for some SoCs
use dma_alloc as done in usb_new_device.
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
drivers/usb/core/usb.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index d29cd1328..e14b89b5e 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -902,7 +902,6 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid,
*/
int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
{
- unsigned char mybuf[USB_BUFSIZ];
unsigned char *tbuf;
int err;
unsigned int u, idx;
@@ -910,7 +909,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
if (size <= 0 || !buf || !index)
return -1;
buf[0] = 0;
- tbuf = &mybuf[0];
+ tbuf = dma_alloc(USB_BUFSIZ);
/* get langid for strings if it's not yet known */
if (!dev->have_langid) {
@@ -918,10 +917,12 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
if (err < 0) {
pr_debug("error getting string descriptor 0 " \
"(error=%lx)\n", dev->status);
- return -1;
+ err = -1;
+ goto error;
} else if (tbuf[0] < 4) {
pr_debug("string descriptor 0 too short\n");
- return -1;
+ err = -1;
+ goto error;
} else {
dev->have_langid = -1;
dev->string_langid = tbuf[2] | (tbuf[3] << 8);
@@ -934,7 +935,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
err = usb_string_sub(dev, dev->string_langid, index, tbuf);
if (err < 0)
- return err;
+ goto error;
size--; /* leave room for trailing NULL char in output buffer */
for (idx = 0, u = 2; u < err; u += 2) {
@@ -947,6 +948,10 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
}
buf[idx] = 0;
err = idx;
+
+error:
+ dma_free(tbuf);
+
return err;
}
--
2.21.0.196.g041f5ea
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 4/6] usb: string: Use le16_to_cpu for langid
2019-10-10 8:14 [PATCH 1/6] usb: hub: Use more accurate struct name Jules Maselbas
2019-10-10 8:14 ` [PATCH 2/6] usb: hub: Only clear port reset status if set Jules Maselbas
2019-10-10 8:15 ` [PATCH 3/6] usb: string: Use dma_alloc instead of a local buffer Jules Maselbas
@ 2019-10-10 8:15 ` Jules Maselbas
2019-10-10 20:41 ` Andrey Smirnov
2019-10-14 11:42 ` Sascha Hauer
2019-10-10 8:15 ` [PATCH 5/6] usb: string: size_t is unsigned Jules Maselbas
2019-10-10 8:15 ` [PATCH 6/6] usb: string: Minor changes Jules Maselbas
4 siblings, 2 replies; 9+ messages in thread
From: Jules Maselbas @ 2019-10-10 8:15 UTC (permalink / raw)
To: barebox; +Cc: Jules Maselbas
This might fix an endianness bug when the cpu is big-endian
as the string_langid will be converted with `cpu_to_le16` when
sending a control message to get a string descriptor.
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
drivers/usb/core/usb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index e14b89b5e..5dc7993ac 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -925,7 +925,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
goto error;
} else {
dev->have_langid = -1;
- dev->string_langid = tbuf[2] | (tbuf[3] << 8);
+ dev->string_langid = le16_to_cpu(*((__le16 *)&buf[2]));
/* always use the first langid listed */
pr_debug("USB device number %d default " \
"language ID 0x%x\n",
--
2.21.0.196.g041f5ea
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 5/6] usb: string: size_t is unsigned
2019-10-10 8:14 [PATCH 1/6] usb: hub: Use more accurate struct name Jules Maselbas
` (2 preceding siblings ...)
2019-10-10 8:15 ` [PATCH 4/6] usb: string: Use le16_to_cpu for langid Jules Maselbas
@ 2019-10-10 8:15 ` Jules Maselbas
2019-10-10 8:15 ` [PATCH 6/6] usb: string: Minor changes Jules Maselbas
4 siblings, 0 replies; 9+ messages in thread
From: Jules Maselbas @ 2019-10-10 8:15 UTC (permalink / raw)
To: barebox; +Cc: Jules Maselbas
Testing if size_t is negative is not needed as size_t is unsigned.
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
drivers/usb/core/usb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 5dc7993ac..e34cb5bf2 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -906,7 +906,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
int err;
unsigned int u, idx;
- if (size <= 0 || !buf || !index)
+ if (!size || !buf || !index)
return -1;
buf[0] = 0;
tbuf = dma_alloc(USB_BUFSIZ);
--
2.21.0.196.g041f5ea
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 6/6] usb: string: Minor changes
2019-10-10 8:14 [PATCH 1/6] usb: hub: Use more accurate struct name Jules Maselbas
` (3 preceding siblings ...)
2019-10-10 8:15 ` [PATCH 5/6] usb: string: size_t is unsigned Jules Maselbas
@ 2019-10-10 8:15 ` Jules Maselbas
4 siblings, 0 replies; 9+ messages in thread
From: Jules Maselbas @ 2019-10-10 8:15 UTC (permalink / raw)
To: barebox; +Cc: Jules Maselbas
This is mostly cosmetic changes except it adds a test in case
dma_alloc failed, the boolean have_langid will will now take the
value 1 when set (instead of -1) and now characters with a value
above 0x7f (outside ASCII range) will also be converted to '?'.
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
drivers/usb/core/usb.c | 51 +++++++++++++++++++++---------------------
include/usb/usb.h | 2 +-
2 files changed, 26 insertions(+), 27 deletions(-)
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index e34cb5bf2..cdcab6082 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -900,31 +900,32 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid,
* Get string index and translate it to ascii.
* returns string length (> 0) or error (< 0)
*/
-int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
+int usb_string(struct usb_device *dev, int index, char *str, size_t size)
{
- unsigned char *tbuf;
- int err;
- unsigned int u, idx;
+ unsigned char *buf;
+ unsigned int i, u;
+ int ret;
+
+ buf = dma_alloc(USB_BUFSIZ);
- if (!size || !buf || !index)
+ if (!size || !str || !buf || !index)
return -1;
- buf[0] = 0;
- tbuf = dma_alloc(USB_BUFSIZ);
+ str[0] = 0;
/* get langid for strings if it's not yet known */
if (!dev->have_langid) {
- err = usb_string_sub(dev, 0, 0, tbuf);
- if (err < 0) {
+ ret = usb_string_sub(dev, 0, 0, buf);
+ if (ret < 0) {
pr_debug("error getting string descriptor 0 " \
"(error=%lx)\n", dev->status);
- err = -1;
+ ret = -1;
goto error;
- } else if (tbuf[0] < 4) {
+ } else if (buf[0] < 4) {
pr_debug("string descriptor 0 too short\n");
- err = -1;
+ ret = -1;
goto error;
} else {
- dev->have_langid = -1;
+ dev->have_langid = 1;
dev->string_langid = le16_to_cpu(*((__le16 *)&buf[2]));
/* always use the first langid listed */
pr_debug("USB device number %d default " \
@@ -933,26 +934,24 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
}
}
- err = usb_string_sub(dev, dev->string_langid, index, tbuf);
- if (err < 0)
+ ret = usb_string_sub(dev, dev->string_langid, index, buf);
+ if (ret < 0)
goto error;
- size--; /* leave room for trailing NULL char in output buffer */
- for (idx = 0, u = 2; u < err; u += 2) {
- if (idx >= size)
- break;
- if (tbuf[u+1]) /* high byte */
- buf[idx++] = '?'; /* non-ASCII character */
+ size--; /* leave room for trailing NULL char in output buffer */
+ for (i = 0, u = 2; u < ret && i < size; i++, u += 2) {
+ if (buf[u] & 0x80 || buf[u + 1]) /* non-ASCII character */
+ str[i] = '?';
else
- buf[idx++] = tbuf[u];
+ str[i] = buf[u];
}
- buf[idx] = 0;
- err = idx;
+ str[i] = 0;
+ ret = i;
error:
- dma_free(tbuf);
+ dma_free(buf);
- return err;
+ return ret;
}
int usb_driver_register(struct usb_driver *drv)
diff --git a/include/usb/usb.h b/include/usb/usb.h
index 4698308df..e9e708867 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -181,7 +181,7 @@ int usb_get_class_descriptor(struct usb_device *dev, int ifnum,
unsigned char type, unsigned char id, void *buf,
int size);
int usb_clear_halt(struct usb_device *dev, int pipe);
-int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
+int usb_string(struct usb_device *dev, int index, char *str, size_t size);
int usb_set_interface(struct usb_device *dev, int interface, int alternate);
void usb_rescan(void);
--
2.21.0.196.g041f5ea
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/6] usb: string: Use le16_to_cpu for langid
2019-10-10 8:15 ` [PATCH 4/6] usb: string: Use le16_to_cpu for langid Jules Maselbas
@ 2019-10-10 20:41 ` Andrey Smirnov
2019-10-14 11:42 ` Sascha Hauer
1 sibling, 0 replies; 9+ messages in thread
From: Andrey Smirnov @ 2019-10-10 20:41 UTC (permalink / raw)
To: Jules Maselbas; +Cc: Barebox List
On Thu, Oct 10, 2019 at 1:15 AM Jules Maselbas <jmaselbas@kalray.eu> wrote:
>
> This might fix an endianness bug when the cpu is big-endian
> as the string_langid will be converted with `cpu_to_le16` when
> sending a control message to get a string descriptor.
>
> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
> ---
> drivers/usb/core/usb.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> index e14b89b5e..5dc7993ac 100644
> --- a/drivers/usb/core/usb.c
> +++ b/drivers/usb/core/usb.c
> @@ -925,7 +925,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
> goto error;
> } else {
> dev->have_langid = -1;
> - dev->string_langid = tbuf[2] | (tbuf[3] << 8);
> + dev->string_langid = le16_to_cpu(*((__le16 *)&buf[2]));
Very minor, but looks like le16_to_cpup() might be a better fit here.
Thanks,
Andrey Smirnov
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/6] usb: string: Use le16_to_cpu for langid
2019-10-10 8:15 ` [PATCH 4/6] usb: string: Use le16_to_cpu for langid Jules Maselbas
2019-10-10 20:41 ` Andrey Smirnov
@ 2019-10-14 11:42 ` Sascha Hauer
2019-10-14 15:09 ` Jules Maselbas
1 sibling, 1 reply; 9+ messages in thread
From: Sascha Hauer @ 2019-10-14 11:42 UTC (permalink / raw)
To: Jules Maselbas; +Cc: barebox
On Thu, Oct 10, 2019 at 10:15:01AM +0200, Jules Maselbas wrote:
> This might fix an endianness bug when the cpu is big-endian
> as the string_langid will be converted with `cpu_to_le16` when
> sending a control message to get a string descriptor.
>
> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
> ---
> drivers/usb/core/usb.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> index e14b89b5e..5dc7993ac 100644
> --- a/drivers/usb/core/usb.c
> +++ b/drivers/usb/core/usb.c
> @@ -925,7 +925,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
> goto error;
> } else {
> dev->have_langid = -1;
> - dev->string_langid = tbuf[2] | (tbuf[3] << 8);
> + dev->string_langid = le16_to_cpu(*((__le16 *)&buf[2]));
You also changed from tbuf to buf. Is this intentional?
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/6] usb: string: Use le16_to_cpu for langid
2019-10-14 11:42 ` Sascha Hauer
@ 2019-10-14 15:09 ` Jules Maselbas
0 siblings, 0 replies; 9+ messages in thread
From: Jules Maselbas @ 2019-10-14 15:09 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
> > --- a/drivers/usb/core/usb.c
> > +++ b/drivers/usb/core/usb.c
> > @@ -925,7 +925,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
> > goto error;
> > } else {
> > dev->have_langid = -1;
> > - dev->string_langid = tbuf[2] | (tbuf[3] << 8);
> > + dev->string_langid = le16_to_cpu(*((__le16 *)&buf[2]));
>
> You also changed from tbuf to buf. Is this intentional?
Good catch,
No this is not intentional it should still be `tbuf` here, `buf` name
must be used when applying patch number 6, here it will cause an error
as buf is a pointer the output string not the result of the usb request.
Jules
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2019-10-14 15:10 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-10 8:14 [PATCH 1/6] usb: hub: Use more accurate struct name Jules Maselbas
2019-10-10 8:14 ` [PATCH 2/6] usb: hub: Only clear port reset status if set Jules Maselbas
2019-10-10 8:15 ` [PATCH 3/6] usb: string: Use dma_alloc instead of a local buffer Jules Maselbas
2019-10-10 8:15 ` [PATCH 4/6] usb: string: Use le16_to_cpu for langid Jules Maselbas
2019-10-10 20:41 ` Andrey Smirnov
2019-10-14 11:42 ` Sascha Hauer
2019-10-14 15:09 ` Jules Maselbas
2019-10-10 8:15 ` [PATCH 5/6] usb: string: size_t is unsigned Jules Maselbas
2019-10-10 8:15 ` [PATCH 6/6] usb: string: Minor changes Jules Maselbas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox