mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] ASoC: soc-card: soc-card-test: Fix some error handling in init()
@ 2024-04-12 12:07 Dan Carpenter
  2024-04-12 13:02 ` Richard Fitzgerald
  2024-04-15  2:26 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2024-04-12 12:07 UTC (permalink / raw)
  To: Richard Fitzgerald
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	linux-sound, linux-kernel, kernel-janitors

There are two issues here:
1) The get_device() needs a matching put_device() on error paths.
2) The "if (!ret)" was supposed to be "if (ret)".

I re-arranged the code a bit to do the allocation before the
get_device().

Fixes: ef7784e41db7 ("ASoC: soc-card: Add KUnit test case for snd_soc_card_get_kcontrol")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
v2: add a put_device()
v3: move the kunit_kzalloc() to avoid a second put_device().  Btw,
    kunit_kzalloc() is cleaned up automatically.

 sound/soc/soc-card-test.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/sound/soc/soc-card-test.c b/sound/soc/soc-card-test.c
index 075c52fe82e5..e4a4b101d743 100644
--- a/sound/soc/soc-card-test.c
+++ b/sound/soc/soc-card-test.c
@@ -134,22 +134,24 @@ static int soc_card_test_case_init(struct kunit *test)
 
 	test->priv = priv;
 
+	priv->card = kunit_kzalloc(test, sizeof(*priv->card), GFP_KERNEL);
+	if (!priv->card)
+		return -ENOMEM;
+
 	priv->card_dev = kunit_device_register(test, "sound-soc-card-test");
 	priv->card_dev = get_device(priv->card_dev);
 	if (!priv->card_dev)
 		return -ENODEV;
 
-	priv->card = kunit_kzalloc(test, sizeof(*priv->card), GFP_KERNEL);
-	if (!priv->card)
-		return -ENOMEM;
-
 	priv->card->name = "soc-card-test";
 	priv->card->dev = priv->card_dev;
 	priv->card->owner = THIS_MODULE;
 
 	ret = snd_soc_register_card(priv->card);
-	if (!ret)
+	if (ret) {
+		put_device(priv->card_dev);
 		return ret;
+	}
 
 	return 0;
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] ASoC: soc-card: soc-card-test: Fix some error handling in init()
  2024-04-12 12:07 [PATCH v3] ASoC: soc-card: soc-card-test: Fix some error handling in init() Dan Carpenter
@ 2024-04-12 13:02 ` Richard Fitzgerald
  2024-04-15  2:26 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Fitzgerald @ 2024-04-12 13:02 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	linux-sound, linux-kernel, kernel-janitors

On 12/04/2024 13:07, Dan Carpenter wrote:
> There are two issues here:
> 1) The get_device() needs a matching put_device() on error paths.
> 2) The "if (!ret)" was supposed to be "if (ret)".
> 
> I re-arranged the code a bit to do the allocation before the
> get_device().
> 
> Fixes: ef7784e41db7 ("ASoC: soc-card: Add KUnit test case for snd_soc_card_get_kcontrol")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> v2: add a put_device()
> v3: move the kunit_kzalloc() to avoid a second put_device().  Btw,
>      kunit_kzalloc() is cleaned up automatically.
> 
>   sound/soc/soc-card-test.c | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/sound/soc/soc-card-test.c b/sound/soc/soc-card-test.c
> index 075c52fe82e5..e4a4b101d743 100644
> --- a/sound/soc/soc-card-test.c
> +++ b/sound/soc/soc-card-test.c
> @@ -134,22 +134,24 @@ static int soc_card_test_case_init(struct kunit *test)
>   
>   	test->priv = priv;
>   
> +	priv->card = kunit_kzalloc(test, sizeof(*priv->card), GFP_KERNEL);
> +	if (!priv->card)
> +		return -ENOMEM;
> +
>   	priv->card_dev = kunit_device_register(test, "sound-soc-card-test");
>   	priv->card_dev = get_device(priv->card_dev);
>   	if (!priv->card_dev)
>   		return -ENODEV;
>   
> -	priv->card = kunit_kzalloc(test, sizeof(*priv->card), GFP_KERNEL);
> -	if (!priv->card)
> -		return -ENOMEM;
> -
>   	priv->card->name = "soc-card-test";
>   	priv->card->dev = priv->card_dev;
>   	priv->card->owner = THIS_MODULE;
>   
>   	ret = snd_soc_register_card(priv->card);
> -	if (!ret)
> +	if (ret) {
> +		put_device(priv->card_dev);
>   		return ret;
> +	}
>   
>   	return 0;
>   }
Reviewed-by: Richard Fitzgerald <rf@opensource.cirrus.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] ASoC: soc-card: soc-card-test: Fix some error handling in init()
  2024-04-12 12:07 [PATCH v3] ASoC: soc-card: soc-card-test: Fix some error handling in init() Dan Carpenter
  2024-04-12 13:02 ` Richard Fitzgerald
@ 2024-04-15  2:26 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2024-04-15  2:26 UTC (permalink / raw)
  To: Richard Fitzgerald, Dan Carpenter
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, linux-sound,
	linux-kernel, kernel-janitors

On Fri, 12 Apr 2024 15:07:01 +0300, Dan Carpenter wrote:
> There are two issues here:
> 1) The get_device() needs a matching put_device() on error paths.
> 2) The "if (!ret)" was supposed to be "if (ret)".
> 
> I re-arranged the code a bit to do the allocation before the
> get_device().
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: soc-card: soc-card-test: Fix some error handling in init()
      commit: a8cad4a4e431e250edc05242a8ca1be6e4b33749

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-15  2:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-12 12:07 [PATCH v3] ASoC: soc-card: soc-card-test: Fix some error handling in init() Dan Carpenter
2024-04-12 13:02 ` Richard Fitzgerald
2024-04-15  2:26 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®