[PATCH] mfd: cgbc-core: Fix error handling paths in cgbc_init_device()

Christophe JAILLET posted 1 patch 1 year, 3 months ago
There is a newer version of this series
drivers/mfd/cgbc-core.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
[PATCH] mfd: cgbc-core: Fix error handling paths in cgbc_init_device()
Posted by Christophe JAILLET 1 year, 3 months ago
If an error occurs after a cgbc_session_request() call, it should be
balanced by a corresponding cgbc_session_release(), as already done in the
remove function.

Fixes: 6f1067cfbee7 ("mfd: Add Congatec Board Controller driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only
---
 drivers/mfd/cgbc-core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
index 93004a6b29c1..7771d010eb2e 100644
--- a/drivers/mfd/cgbc-core.c
+++ b/drivers/mfd/cgbc-core.c
@@ -321,9 +321,19 @@ static int cgbc_init_device(struct cgbc_device_data *cgbc)
 
 	ret = cgbc_get_version(cgbc);
 	if (ret)
-		return ret;
+		goto release_session;
+
+	ret = mfd_add_devices(cgbc->dev, -1, cgbc_devs, ARRAY_SIZE(cgbc_devs),
+			      NULL, 0, NULL);
+	if (ret)
+		goto release_session;
+
+	return 0;
+
+release_session:
+	cgbc_session_release(cgbc);
+	return ret;
 
-	return mfd_add_devices(cgbc->dev, -1, cgbc_devs, ARRAY_SIZE(cgbc_devs), NULL, 0, NULL);
 }
 
 static int cgbc_probe(struct platform_device *pdev)
-- 
2.47.0
Re: [PATCH] mfd: cgbc-core: Fix error handling paths in cgbc_init_device()
Posted by Thomas Richard 1 year, 3 months ago
Hello Christophe,

On 10/26/24 12:32, Christophe JAILLET wrote:
> If an error occurs after a cgbc_session_request() call, it should be
> balanced by a corresponding cgbc_session_release(), as already done in the
> remove function.
> 
> Fixes: 6f1067cfbee7 ("mfd: Add Congatec Board Controller driver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only
> ---
>  drivers/mfd/cgbc-core.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
> index 93004a6b29c1..7771d010eb2e 100644
> --- a/drivers/mfd/cgbc-core.c
> +++ b/drivers/mfd/cgbc-core.c
> @@ -321,9 +321,19 @@ static int cgbc_init_device(struct cgbc_device_data *cgbc)
>  
>  	ret = cgbc_get_version(cgbc);
>  	if (ret)
> -		return ret;
> +		goto release_session;
> +
> +	ret = mfd_add_devices(cgbc->dev, -1, cgbc_devs, ARRAY_SIZE(cgbc_devs),
> +			      NULL, 0, NULL);
> +	if (ret)
> +		goto release_session;
> +
> +	return 0;
> +
> +release_session:
> +	cgbc_session_release(cgbc);
> +	return ret;
>  
> -	return mfd_add_devices(cgbc->dev, -1, cgbc_devs, ARRAY_SIZE(cgbc_devs), NULL, 0, NULL);
>  }

nitpick: useless blank line before the close brace.

Reviewed-by: Thomas Richard <thomas.richard@bootlin.com>

Regards,

Thomas