[PATCH] usb: typec: Register supported alternate modes in typec_register_port()
From: Guenter Roeck
Date: Thu Jun 02 2016 - 13:09:50 EST
By registering supported alternate modes when registering the port, we
automatically get the correct directory hierarchie in the class device.
Change-Id: I543da5f4ce922ded0532e6b0a0fdb8bc55cb5a80
Signed-off-by: Guenter Roeck <groeck@xxxxxxxxxxxx>
---
drivers/usb/type-c/typec.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/type-c/typec.c b/drivers/usb/type-c/typec.c
index 41ad955..22ee7eb 100644
--- a/drivers/usb/type-c/typec.c
+++ b/drivers/usb/type-c/typec.c
@@ -892,14 +892,22 @@ struct typec_port *typec_register_port(struct device *dev,
typec_init_roles(port);
ret = device_register(&port->dev);
- if (ret) {
- ida_simple_remove(&typec_index_ida, id);
- put_device(&port->dev);
- kfree(port);
- return ERR_PTR(ret);
- }
+ if (ret)
+ goto reg_err;
+
+ ret = typec_register_altmodes(&port->dev, cap->alt_modes);
+ if (ret)
+ goto alt_err;
return port;
+
+alt_err:
+ device_unregister(&port->dev);
+reg_err:
+ ida_simple_remove(&typec_index_ida, id);
+ put_device(&port->dev);
+ kfree(port);
+ return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(typec_register_port);
@@ -908,6 +916,7 @@ void typec_unregister_port(struct typec_port *port)
if (port->connected)
typec_disconnect(port);
+ typec_unregister_altmodes(port->cap->alt_modes);
device_unregister(&port->dev);
}
EXPORT_SYMBOL_GPL(typec_unregister_port);
--
2.1.2