ChangeSet 1.1673.8.10, 2004/03/25 15:56:56-08:00, david-b@pacbell.net [PATCH] USB: fix osdl bugid 481 (USB boot messages) Some boot-time messages were obnoxiously long because they used "old-style" diagnostics. OSDL bugid 481 Get rid of most remaining "old style" diagnostics from usbcore. Most messages use driver model style diagnostics. Messages that don't have an associated device use the standard kernel printk wrappers and label themselves as from "usbcore". (Except that there's no such wrapper for KERN_ERR.) This doesn't touch usbfs, "config.c" (Alan's patches do this), or usb_reset_device() (needs a more substantial overhaul). Or any other USB drivers (notably HID). drivers/usb/core/hcd-pci.c | 17 ++++++++++------- drivers/usb/core/hcd.c | 10 +++++++--- drivers/usb/core/hub.c | 17 ++++++++--------- drivers/usb/core/message.c | 18 +++++++++++------- drivers/usb/core/usb.c | 35 ++++++++++++++++++++++------------- drivers/usb/core/usb.h | 3 +++ 6 files changed, 61 insertions(+), 39 deletions(-) diff -Nru a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c --- a/drivers/usb/core/hcd-pci.c Wed Apr 14 14:39:36 2004 +++ b/drivers/usb/core/hcd-pci.c Wed Apr 14 14:39:36 2004 @@ -80,7 +80,8 @@ return -ENODEV; if (!dev->irq) { - err ("Found HC with no IRQ. Check BIOS/PCI %s setup!", + dev_err (&dev->dev, + "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", pci_name(dev)); return -ENODEV; } @@ -90,16 +91,17 @@ resource = pci_resource_start (dev, 0); len = pci_resource_len (dev, 0); if (!request_mem_region (resource, len, driver->description)) { - dbg ("controller already in use"); + dev_dbg (&dev->dev, "controller already in use\n"); return -EBUSY; } base = ioremap_nocache (resource, len); if (base == NULL) { - dbg ("error mapping memory"); + dev_dbg (&dev->dev, "error mapping memory\n"); retval = -EFAULT; clean_1: release_mem_region (resource, len); - err ("init %s fail, %d", pci_name(dev), retval); + dev_err (&dev->dev, "init %s fail, %d\n", + pci_name(dev), retval); return retval; } @@ -116,7 +118,7 @@ break; } if (region == PCI_ROM_RESOURCE) { - dbg ("no i/o regions available"); + dev_dbg (&dev->dev, "no i/o regions available\n"); return -EBUSY; } base = (void *) resource; @@ -127,7 +129,7 @@ hcd = driver->hcd_alloc (); if (hcd == NULL){ - dbg ("hcd alloc fail"); + dev_dbg (&dev->dev, "hcd alloc fail\n"); retval = -ENOMEM; clean_2: if (driver->flags & HCD_MEMORY) { @@ -135,7 +137,8 @@ goto clean_1; } else { release_region (resource, len); - err ("init %s fail, %d", pci_name(dev), retval); + dev_err (&dev->dev, "init %s fail, %d\n", + pci_name(dev), retval); return retval; } } diff -Nru a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c --- a/drivers/usb/core/hcd.c Wed Apr 14 14:39:36 2004 +++ b/drivers/usb/core/hcd.c Wed Apr 14 14:39:36 2004 @@ -42,6 +42,8 @@ #include #include + +#include "usb.h" #include "hcd.h" @@ -678,8 +680,10 @@ if (busnum < USB_MAXBUS) { set_bit (busnum, busmap.busmap); bus->busnum = busnum; - } else - warn ("too many buses"); + } else { + printk (KERN_ERR "%s: too many buses\n", usbcore_name); + return -E2BIG; + } snprintf(bus->class_dev.class_id, BUS_ID_SIZE, "usb%d", busnum); bus->class_dev.class = &usb_host_class; @@ -804,7 +808,7 @@ tmp = HS_USECS_ISO (bytecount); return tmp; default: - dbg ("bogus device speed!"); + pr_debug ("%s: bogus device speed!\n", usbcore_name); return -1; } } diff -Nru a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c --- a/drivers/usb/core/hub.c Wed Apr 14 14:39:36 2004 +++ b/drivers/usb/core/hub.c Wed Apr 14 14:39:36 2004 @@ -212,8 +212,7 @@ spin_lock_irqsave (&hub->tt.lock, flags); if (status) - err ("usb-%s-%s clear tt %d (%04x) error %d", - dev->bus->bus_name, dev->devpath, + dev_err (&dev->dev, "clear tt %d (%04x) error %d\n", clear->tt, clear->devinfo, status); kfree (clear); } @@ -244,8 +243,7 @@ * there can be many TTs per hub). even if they're uncommon. */ if ((clear = kmalloc (sizeof *clear, SLAB_ATOMIC)) == 0) { - err ("can't save CLEAR_TT_BUFFER state for hub at usb-%s-%s", - dev->bus->bus_name, tt->hub->devpath); + dev_err (&dev->dev, "can't save CLEAR_TT_BUFFER state\n"); /* FIXME recover somehow ... RESET_TT? */ return; } @@ -596,7 +594,7 @@ hub = kmalloc(sizeof(*hub), GFP_KERNEL); if (!hub) { - err("couldn't kmalloc hub struct"); + dev_dbg (hubdev(dev), "couldn't kmalloc hub struct\n"); return -ENOMEM; } @@ -700,7 +698,7 @@ } } - err("cannot disconnect hub %s", dev->devpath); + dev_err(&dev->dev, "cannot disconnect hub!\n"); } static int hub_port_status(struct usb_device *dev, int port, @@ -1145,7 +1143,7 @@ refrigerator(PF_IOTHREAD); } while (!signal_pending(current)); - dbg("hub_thread exiting"); + pr_debug ("%s: khubd exiting\n", usbcore_name); complete_and_exit(&khubd_exited, 0); } @@ -1176,7 +1174,8 @@ pid_t pid; if (usb_register(&hub_driver) < 0) { - err("Unable to register USB hub driver"); + printk(KERN_ERR "%s: can't register hub driver\n", + usbcore_name); return -1; } @@ -1189,7 +1188,7 @@ /* Fall through if kernel_thread failed */ usb_deregister(&hub_driver); - err("failed to start hub_thread"); + printk(KERN_ERR "%s: can't start khubd\n", usbcore_name); return -1; } diff -Nru a/drivers/usb/core/message.c b/drivers/usb/core/message.c --- a/drivers/usb/core/message.c Wed Apr 14 14:39:36 2004 +++ b/drivers/usb/core/message.c Wed Apr 14 14:39:36 2004 @@ -935,7 +935,8 @@ iface = usb_ifnum_to_if(dev, interface); if (!iface) { - warn("selecting invalid interface %d", interface); + dev_dbg(&dev->dev, "selecting invalid interface %d\n", + interface); return -EINVAL; } @@ -953,8 +954,9 @@ * request if the interface only has one alternate setting. */ if (ret == -EPIPE && iface->num_altsetting == 1) { - dbg("manual set_interface for dev %d, iface %d, alt %d", - dev->devnum, interface, alternate); + dev_dbg(&dev->dev, + "manual set_interface for iface %d, alt %d\n", + interface, alternate); manual = 1; } else if (ret < 0) return ret; @@ -1233,18 +1235,20 @@ if (!dev->have_langid) { err = usb_get_string(dev, 0, 0, tbuf, 4); if (err < 0) { - err("error getting string descriptor 0 (error=%d)", err); + dev_err (&dev->dev, + "string descriptor 0 read error: %d\n", + err); goto errout; } else if (err < 4 || tbuf[0] < 4) { - err("string descriptor 0 too short"); + dev_err (&dev->dev, "string descriptor 0 too short\n"); err = -EINVAL; goto errout; } else { dev->have_langid = -1; dev->string_langid = tbuf[2] | (tbuf[3]<< 8); /* always use the first langid listed */ - dbg("USB device number %d default language ID 0x%x", - dev->devnum, dev->string_langid); + dev_dbg (&dev->dev, "default language 0x%04x\n", + dev->string_langid); } } diff -Nru a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c --- a/drivers/usb/core/usb.c Wed Apr 14 14:39:36 2004 +++ b/drivers/usb/core/usb.c Wed Apr 14 14:39:36 2004 @@ -58,6 +58,8 @@ extern void usb_host_cleanup(void); +const char *usbcore_name = "usbcore"; + int nousb; /* Disable USB when built into kernel image */ /* Not honored on modular build */ @@ -158,11 +160,12 @@ retval = driver_register(&new_driver->driver); if (!retval) { - info("registered new driver %s", new_driver->name); + pr_info("%s: registered new driver %s\n", + usbcore_name, new_driver->name); usbfs_update_special(); } else { - err("problem %d when registering driver %s", - retval, new_driver->name); + printk(KERN_ERR "%s: error %d registering driver %s\n", + usbcore_name, retval, new_driver->name); } return retval; @@ -181,7 +184,7 @@ */ void usb_deregister(struct usb_driver *driver) { - info("deregistering driver %s", driver->name); + pr_info("%s: deregistering driver %s\n", usbcore_name, driver->name); driver_unregister (&driver->driver); @@ -587,11 +590,12 @@ int i = 0; int length = 0; - dbg ("%s", __FUNCTION__); - if (!dev) return -ENODEV; + /* driver is often null here; dev_dbg() would oops */ + pr_debug ("usb %s: hotplug\n", dev->bus_id); + /* Must check driver_data here, as on remove driver is always NULL */ if ((dev->driver == &usb_generic_driver) || (dev->driver_data == &usb_generic_driver_data)) @@ -601,11 +605,11 @@ usb_dev = interface_to_usbdev (intf); if (usb_dev->devnum < 0) { - dbg ("device already deleted ??"); + pr_debug ("usb %s: already deleted?\n", dev->bus_id); return -ENODEV; } if (!usb_dev->bus) { - dbg ("bus already removed?"); + pr_debug ("usb %s: bus removed?\n", dev->bus_id); return -ENODEV; } @@ -827,14 +831,14 @@ struct usb_device *ret_dev = NULL; int child; - dbg("looking at vendor %d, product %d", + dev_dbg(&dev->dev, "check for vendor %04x, product %04x ...\n", dev->descriptor.idVendor, dev->descriptor.idProduct); /* see if this device matches */ if ((dev->descriptor.idVendor == vendor_id) && (dev->descriptor.idProduct == product_id)) { - dbg ("found the device!"); + dev_dbg (&dev->dev, "matched this device!\n"); ret_dev = usb_get_dev(dev); goto exit; } @@ -909,7 +913,8 @@ * extra field of the interface and endpoint descriptor structs. */ -int __usb_get_extra_descriptor(char *buffer, unsigned size, unsigned char type, void **ptr) +int __usb_get_extra_descriptor(char *buffer, unsigned size, + unsigned char type, void **ptr) { struct usb_descriptor_header *header; @@ -917,7 +922,11 @@ header = (struct usb_descriptor_header *)buffer; if (header->bLength < 2) { - err("invalid descriptor length of %d", header->bLength); + printk(KERN_ERR + "%s: bogus descriptor, type %d length %d\n", + usbcore_name, + header->bDescriptorType, + header->bLength); return -1; } @@ -1568,7 +1577,7 @@ static int __init usb_init(void) { if (nousb) { - info("USB support disabled\n"); + pr_info ("%s: USB support disabled\n", usbcore_name); return 0; } diff -Nru a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h --- a/drivers/usb/core/usb.h Wed Apr 14 14:39:36 2004 +++ b/drivers/usb/core/usb.h Wed Apr 14 14:39:36 2004 @@ -17,3 +17,6 @@ extern int usb_get_device_descriptor(struct usb_device *dev, unsigned int size); + +/* for labeling diagnostics */ +extern const char *usbcore_name;