Yes, this is perfect. *shiver* I can't believe I made the code so leaky.
Sorry for that, it's a copy-paste problem.
Thanks for fixing it.
> Oops, more memory leak fixes:
>
> > diff -Nru a/drivers/usb/usb.c b/drivers/usb/usb.c
> > --- a/drivers/usb/usb.c Wed Jan 23 13:20:28 2002
> > +++ b/drivers/usb/usb.c Wed Jan 23 13:20:28 2002
> > @@ -2513,6 +2513,49 @@
> > return err;
> > }
> >
> > +/**
> > + * usb_make_path - returns device path in the hub tree
> > + * @dev: the device whose path is being constructed
> > + * @buf: where to put the string
> > + * @size: how big is "buf"?
> > + *
> > + * Returns length of the string (>= 0) or out of memory status (< 0).
> > + */
> > +int usb_make_path(struct usb_device *dev, char *buf, size_t size)
> > +{
> > + struct usb_device *pdev = dev->parent;
> > + char *tmp;
> > + char *port;
> > + int i;
> > +
> > + if (!(port = kmalloc(size, GFP_KERNEL)))
> > + return -ENOMEM;
> > + if (!(tmp = kmalloc(size, GFP_KERNEL))) {
> > + kfree(port);
> > + return -ENOMEM;
> > + }
> > +
> > + *port = 0;
> > +
> > + while (pdev) {
> > + for (i = 0; i < pdev->maxchild; i++)
> > + if (pdev->children[i] == dev)
> > + break;
> > +
> > + if (pdev->children[i] != dev)
> > + return -1;
>
> Should be:
> if (pdev->children[i] != dev) {
> kfree(port);
> kfree(tmp);
> return -ENODEV;
> }
>
> > +
> > + strcpy(tmp, port);
> > + snprintf(port, size, strlen(port) ? "%d.%s" : "%d", i + 1, tmp);
> > +
> > + dev = pdev;
> > + pdev = dev->parent;
> > + }
> > +
> > + snprintf(buf, size, "usb%d:%s", dev->bus->busnum, port);
>
> And add:
> kfree(port);
> kfree(tmp);
>
> > + return strlen(buf);
> > +}
>
>
> Does that look better?
>
> thanks,
>
> greg k-h
-- Vojtech Pavlik SuSE Labs - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/