diff mbox

[U-Boot,3/3] dm: usb: Add a remove() method for USB keyboards

Message ID 1451854231-20916-3-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Jan. 3, 2016, 8:50 p.m. UTC
At present USB keyboards are not properly removed with driver model. Add the
code to handle this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/usb_kbd.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Comments

Marek Vasut Jan. 3, 2016, 9:22 p.m. UTC | #1
On Sunday, January 03, 2016 at 09:50:31 PM, Simon Glass wrote:
> At present USB keyboards are not properly removed with driver model. Add
> the code to handle this.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut
Joe Hershberger Jan. 4, 2016, 4:04 a.m. UTC | #2
Hi Simon,

On Sun, Jan 3, 2016 at 2:50 PM, Simon Glass <sjg@chromium.org> wrote:
> At present USB keyboards are not properly removed with driver model. Add the
> code to handle this.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>

Is this supposed to fix the crash that I was reporting details about
in the USB keyboard sandbox tests?

-Joe
Simon Glass Jan. 4, 2016, 4:08 a.m. UTC | #3
Hi Joe,

On Jan 3, 2016 9:04 PM, "Joe Hershberger" <joe.hershberger@gmail.com> wrote:
>
> Hi Simon,
>
> On Sun, Jan 3, 2016 at 2:50 PM, Simon Glass <sjg@chromium.org> wrote:
> > At present USB keyboards are not properly removed with driver model.
Add the
> > code to handle this.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
>
> Is this supposed to fix the crash that I was reporting details about
> in the USB keyboard sandbox tests?

Yes, with the other patches.

>
> -Joe

Regards,
Simon
Simon Glass Jan. 7, 2016, 7:23 p.m. UTC | #4
On 3 January 2016 at 21:08, Simon Glass <sjg@chromium.org> wrote:
> Hi Joe,
>
> On Jan 3, 2016 9:04 PM, "Joe Hershberger" <joe.hershberger@gmail.com> wrote:
>>
>> Hi Simon,
>>
>> On Sun, Jan 3, 2016 at 2:50 PM, Simon Glass <sjg@chromium.org> wrote:
>> > At present USB keyboards are not properly removed with driver model. Add
>> > the
>> > code to handle this.
>> >
>> > Signed-off-by: Simon Glass <sjg@chromium.org>
>>
>> Is this supposed to fix the crash that I was reporting details about
>> in the USB keyboard sandbox tests?
>
> Yes, with the other patches.
>
>>
>> -Joe

Fixed up a typo and:

Applied to u-boot-dm/master.
diff mbox

Patch

diff --git a/common/usb_kbd.c b/common/usb_kbd.c
index 9617a48..7bcab1c 100644
--- a/common/usb_kbd.c
+++ b/common/usb_kbd.c
@@ -611,6 +611,41 @@  static int usb_kbd_probe(struct udevice *dev)
 	return ret;
 }
 
+static int usb_kbd_remove(struct udevice *dev)
+{
+	struct usb_device *udev = dev_get_parent_priv(dev);
+	struct usb_kbd_pdata *data;
+	struct stdio_dev *sdev;
+	int ret;
+
+	sdev = stdio_get_by_name(DEVNAME);
+	if (!sdev) {
+		ret = -ENXIO;
+		goto err;
+	}
+	data = udev->privptr;
+	if (stdio_deregister_dev(sdev, true)) {
+		ret = -EPERM;
+		goto err;
+	}
+#ifdef CONFIG_CONSOLE_MUX
+	if (iomux_doenv(stdin, getenv("stdin"))) {
+		ret = -ENOLINK;
+		goto err;
+	}
+#endif
+#ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE
+	destroy_int_queue(usb_kbd_dev, data->intq);
+#endif
+	free(data->new);
+	free(data);
+
+	return 0;
+err:
+	printf("%s: warning, ret=%d", __func__, ret);
+	return ret;
+}
+
 static const struct udevice_id usb_kbd_ids[] = {
 	{ .compatible = "usb-keyboard" },
 	{ }
@@ -621,6 +656,7 @@  U_BOOT_DRIVER(usb_kbd) = {
 	.id	= UCLASS_KEYBOARD,
 	.of_match = usb_kbd_ids,
 	.probe = usb_kbd_probe,
+	.remove = usb_kbd_remove,
 };
 
 static const struct usb_device_id kbd_id_table[] = {