From: Markus Elfring <Markus.Elfring@web.de>
To: Wander Lairson Costa <wander@redhat.com>,
kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org,
kernel-janitors@vger.kernel.org,
Brendan Higgins <brendan.higgins@linux.dev>,
David Gow <davidgow@google.com>, Rae Moar <rmoar@google.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] kunit: avoid memory leak on device register error
Date: Thu, 18 Apr 2024 17:24:47 +0200 [thread overview]
Message-ID: <9ff84256-c7d2-48e5-b06b-09a993db2c39@web.de> (raw)
In-Reply-To: <20240418131754.58217-3-wander@redhat.com>
> If the device register fails, free the allocated memory before
> returning.
* I suggest to use the word “registration” (instead of “register”)
in the commit message.
* Would you like to add the tag “Fixes” accordingly?
> +++ 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);
> return ERR_PTR(err);
> }
Common error handling code can be used instead
if an additional label would be applied for a corresponding jump target.
How do you think about to increase the application of scope-based resource management here?
Regards,
Markus
next prev parent reply other threads:[~2024-04-18 15:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-18 13:17 [PATCH 0/2] kunit: fix minor error path mistakes Wander Lairson Costa
2024-04-18 13:17 ` [PATCH 1/2] kunit: unregister the device on error Wander Lairson Costa
2024-04-18 15:00 ` Markus Elfring
2024-04-18 15:21 ` Wander Lairson Costa
2024-04-18 13:17 ` [PATCH 2/2] kunit: avoid memory leak on device register error Wander Lairson Costa
2024-04-18 15:24 ` Markus Elfring [this message]
2024-04-18 17:18 ` Wander Lairson Costa
2024-04-18 18:08 ` [ " 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=9ff84256-c7d2-48e5-b06b-09a993db2c39@web.de \
--to=markus.elfring@web.de \
--cc=brendan.higgins@linux.dev \
--cc=davidgow@google.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=rmoar@google.com \
--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