[PATCH 1/8] usb: typec: ucsi: yoga-c630: fix error and remove paths

Dmitry Baryshkov posted 8 patches 3 months, 2 weeks ago
[PATCH 1/8] usb: typec: ucsi: yoga-c630: fix error and remove paths
Posted by Dmitry Baryshkov 3 months, 2 weeks ago
Fix memory leak and call ucsi_destroy() from the driver's remove
function and probe's error path in order to remove debugfs files and
free the memory. Also call yoga_c630_ec_unregister_notify() in the
probe's error path.

Fixes: 2ea6d07efe53 ("usb: typec: ucsi: add Lenovo Yoga C630 glue driver")
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
---
 drivers/usb/typec/ucsi/ucsi_yoga_c630.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c
index d33e3f2dd1d80f7b49d9c5e7355fb14a97c74dd5..47e8dd5b255b2b306dd9c3d6ac8c3b896954981a 100644
--- a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c
+++ b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c
@@ -133,17 +133,30 @@ static int yoga_c630_ucsi_probe(struct auxiliary_device *adev,
 
 	ret = yoga_c630_ec_register_notify(ec, &uec->nb);
 	if (ret)
-		return ret;
+		goto err_destroy;
+
+	ret = ucsi_register(uec->ucsi);
+	if (ret)
+		goto err_unregister;
+
+	return 0;
 
-	return ucsi_register(uec->ucsi);
+err_unregister:
+	yoga_c630_ec_unregister_notify(uec->ec, &uec->nb);
+
+err_destroy:
+	ucsi_destroy(uec->ucsi);
+
+	return ret;
 }
 
 static void yoga_c630_ucsi_remove(struct auxiliary_device *adev)
 {
 	struct yoga_c630_ucsi *uec = auxiliary_get_drvdata(adev);
 
-	yoga_c630_ec_unregister_notify(uec->ec, &uec->nb);
 	ucsi_unregister(uec->ucsi);
+	yoga_c630_ec_unregister_notify(uec->ec, &uec->nb);
+	ucsi_destroy(uec->ucsi);
 }
 
 static const struct auxiliary_device_id yoga_c630_ucsi_id_table[] = {

-- 
2.39.5
Re: [PATCH 1/8] usb: typec: ucsi: yoga-c630: fix error and remove paths
Posted by Heikki Krogerus 3 months, 2 weeks ago
On Sat, Jun 21, 2025 at 09:12:56PM +0300, Dmitry Baryshkov wrote:
> Fix memory leak and call ucsi_destroy() from the driver's remove
> function and probe's error path in order to remove debugfs files and
> free the memory. Also call yoga_c630_ec_unregister_notify() in the
> probe's error path.
> 
> Fixes: 2ea6d07efe53 ("usb: typec: ucsi: add Lenovo Yoga C630 glue driver")
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/ucsi/ucsi_yoga_c630.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c
> index d33e3f2dd1d80f7b49d9c5e7355fb14a97c74dd5..47e8dd5b255b2b306dd9c3d6ac8c3b896954981a 100644
> --- a/drivers/usb/typec/ucsi/ucsi_yoga_c630.c
> +++ b/drivers/usb/typec/ucsi/ucsi_yoga_c630.c
> @@ -133,17 +133,30 @@ static int yoga_c630_ucsi_probe(struct auxiliary_device *adev,
>  
>  	ret = yoga_c630_ec_register_notify(ec, &uec->nb);
>  	if (ret)
> -		return ret;
> +		goto err_destroy;
> +
> +	ret = ucsi_register(uec->ucsi);
> +	if (ret)
> +		goto err_unregister;
> +
> +	return 0;
>  
> -	return ucsi_register(uec->ucsi);
> +err_unregister:
> +	yoga_c630_ec_unregister_notify(uec->ec, &uec->nb);
> +
> +err_destroy:
> +	ucsi_destroy(uec->ucsi);
> +
> +	return ret;
>  }
>  
>  static void yoga_c630_ucsi_remove(struct auxiliary_device *adev)
>  {
>  	struct yoga_c630_ucsi *uec = auxiliary_get_drvdata(adev);
>  
> -	yoga_c630_ec_unregister_notify(uec->ec, &uec->nb);
>  	ucsi_unregister(uec->ucsi);
> +	yoga_c630_ec_unregister_notify(uec->ec, &uec->nb);
> +	ucsi_destroy(uec->ucsi);
>  }
>  
>  static const struct auxiliary_device_id yoga_c630_ucsi_id_table[] = {
> 
> -- 
> 2.39.5

-- 
heikki