public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Wander Lairson Costa <wander@redhat.com>
Cc: Brendan Higgins <brendan.higgins@linux.dev>,
	David Gow <davidgow@google.com>, Rae Moar <rmoar@google.com>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Matti Vaittinen <mazziesaccount@gmail.com>,
	Maxime Ripard <mripard@kernel.org>,
	"open list:KERNEL UNIT TESTING FRAMEWORK (KUnit)"
	<linux-kselftest@vger.kernel.org>,
	"open list:KERNEL UNIT TESTING FRAMEWORK (KUnit)"
	<kunit-dev@googlegroups.com>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 2/2] kunit: avoid memory leak on device register error
Date: Fri, 19 Apr 2024 16:03:12 +0200	[thread overview]
Message-ID: <2024041919-unify-improve-d4a5@gregkh> (raw)
In-Reply-To: <20240419132504.9488-3-wander@redhat.com>

On Fri, Apr 19, 2024 at 10:25:02AM -0300, Wander Lairson Costa wrote:
> If the device register fails, free the allocated memory before
> returning.
> 
> Signed-off-by: Wander Lairson Costa <wander@redhat.com>
> Fixes: d03c720e03bd ("kunit: Add APIs for managing devices")
> ---
>  lib/kunit/device.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/lib/kunit/device.c b/lib/kunit/device.c
> index 25c81ed465fb..d8c09dcb3e79 100644
> --- a/lib/kunit/device.c
> +++ b/lib/kunit/device.c
> @@ -131,6 +131,7 @@ static struct kunit_device *kunit_device_register_internal(struct kunit *test,
>  	err = device_register(&kunit_dev->dev);
>  	if (err) {
>  		put_device(&kunit_dev->dev);
> +		kfree(kunit_dev);

This still looks wrong, the release function for the device should free
the memory here, not this kfree, as the reference count in the embedded
'struct device' handles the memory logic for the whole structure (if
not, then something is REALLY wrong...)

You _do_ have a release function for the device, right?  If not, you
should be getting loud messages in the kernel log when releasing a
device here.

thanks,

greg k-h

  reply	other threads:[~2024-04-19 14:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19 13:25 [PATCH v4 0/2] kunit: fix minor error path mistakes Wander Lairson Costa
2024-04-19 13:25 ` [PATCH v4 1/2] kunit: unregister the device on error Wander Lairson Costa
2024-04-19 14:04   ` Greg Kroah-Hartman
2024-04-19 16:32     ` Markus Elfring
2024-04-20  6:27       ` Greg Kroah-Hartman
2024-04-19 13:25 ` [PATCH v4 2/2] kunit: avoid memory leak on device register error Wander Lairson Costa
2024-04-19 14:03   ` Greg Kroah-Hartman [this message]
2024-04-19 14:11     ` Wander Lairson Costa
2024-04-23  8:00       ` David Gow
2024-04-19 16:18 ` [PATCH v4 0/2] kunit: fix minor error path mistakes Markus Elfring

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=2024041919-unify-improve-d4a5@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mazziesaccount@gmail.com \
    --cc=mripard@kernel.org \
    --cc=rmoar@google.com \
    --cc=skhan@linuxfoundation.org \
    --cc=wander@redhat.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