Re: [PATCHv4 1/4] usb: Provide usb_speed_string() function

From: Michal Nazarewicz
Date: Mon Aug 22 2011 - 15:42:41 EST


On Mon, 22 Aug 2011 19:28:46 +0200, Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote:

On Mon, 22 Aug 2011, Michal Nazarewicz wrote:

From: Michal Nazarewicz <mina86@xxxxxxxxxx>

In a few places in the kernel, the code prints
a human-readable USB device speed (eg. "high speed").
This involves a switch statement sometimes wrapped
around in ({ ... }) block leading to code repetition.

To mitigate this issue, this commit introduces
usb_speed_string() function, which returns
a human-readable name of provided speed.

It also changes a few places switch was used to use
this new function. This changes a bit the way the
speed is printed in few instances at the same time
standardising it.

--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -51,3 +51,6 @@ obj-$(CONFIG_USB_MUSB_HDRC) += musb/
obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs/
obj-$(CONFIG_USB_OTG_UTILS) += otg/
obj-$(CONFIG_USB_GADGET) += gadget/
+
+obj-$(CONFIG_USB) += common.o
+obj-$(CONFIG_USB_GADGET) += common.o

Will this cause problems? For example, what if CONFIG_USB is Y and
CONFIG_USB_GADGET is M?

Hmm, I haven't thought about that.

Also, it seems a little silly to have an entire kernel module devoted
to a single, little function.

Agreed. And again, I haven't thought about compiling as a module which
would result in a major overkill.

This is a symptom of the difficulty of
sharing code between the host-side and gadget-side USB stacks.

Agreed.

I'm open to any suggestions on how this could be solved.

Sticking the function to the header file as static inline seems
like bit... âbloatyâ.

If this is not easily solvable, I'll probably just drop this patch
for now.

--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +-----<email/xmpp: mnazarewicz@xxxxxxxxxx>-----ooO--(_)--Ooo--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/