Re: [RFC/PATCH 2/3] usb: gadget: introduce UDC Class

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

 



On Fri, 13 May 2011 13:05:34 +0200, Felipe Balbi <balbi@xxxxxx> wrote:
+int usb_add_gadget(struct device *parent, struct usb_gadget *gadget)
+{
+	struct usb_udc		*udc;
+	unsigned long		flags;
+	int			ret = -ENOMEM;
+
+	udc = kzalloc(sizeof(*udc), GFP_KERNEL);
+	if (!udc)
+		goto err1;
+
+	device_initialize(&udc->dev);
+	udc->dev.release = usb_udc_release;
+	udc->dev.class = udc_class;
+	udc->dev.parent = parent;
+	ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj));
+	if (ret)
+		goto err2;
+
+	udc->gadget = gadget;
+
+	spin_lock_irqsave(&udc_lock, flags);
+	list_add_tail(&udc->list, &udc_list);
+	spin_unlock_irqrestore(&udc_lock, flags);
+
+	ret = device_add(&udc->dev);
+	if (ret)
+		goto err2;

On error, UDC is never removed from the list.

+
+	return 0;
+
+err2:
+	put_device(&udc->dev);
+

Memory is never freed.

+err1:
+	return ret;
+}
+EXPORT_SYMBOL_GPL(usb_add_gadget);

--
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-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