mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>, <linux-sound@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <kernel-janitors@vger.kernel.org>
Subject: Re: [PATCH v3] ASoC: soc-card: soc-card-test: Fix some error handling in init()
Date: Fri, 12 Apr 2024 14:02:20 +0100	[thread overview]
Message-ID: <b66339af-1e07-4509-9fd8-12a927618172@opensource.cirrus.com> (raw)
In-Reply-To: <450dd21a-b24b-48ba-9aa4-c02e4617852f@moroto.mountain>

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>

  reply	other threads:[~2024-04-12 13:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12 12:07 Dan Carpenter
2024-04-12 13:02 ` Richard Fitzgerald [this message]
2024-04-15  2:26 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b66339af-1e07-4509-9fd8-12a927618172@opensource.cirrus.com \
    --to=rf@opensource.cirrus.com \
    --cc=broonie@kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®