From: Markus Elfring <Markus.Elfring@web.de>
To: Kunwu Chan <chentao@kylinos.cn>,
linux-amlogic@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
kernel-janitors@vger.kernel.org,
Jerome Brunet <jbrunet@baylibre.com>,
Kevin Hilman <khilman@baylibre.com>,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
Neil Armstrong <neil.armstrong@linaro.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] meson-mx-socinfo: Fix possible null-pointer dereference issues in meson_mx_socinfo_init
Date: Fri, 19 Jan 2024 10:06:02 +0100 [thread overview]
Message-ID: <a5f974aa-826d-421b-bfe2-bb6c9b43ea9a@web.de> (raw)
In-Reply-To: <20240119074635.265218-1-chentao@kylinos.cn>
> In meson_mx_socinfo_revision, kasprintf() returns a pointer
> to dynamically allocated memory which can be NULL upon failure.
>
> Similarly, the kstrdup_const in the meson_mx_socinfo_soc_id
> returns a null pointer when it fails. Ensure the allocation was successful
> by checking the pointer validity. Avoid null pointer dereference issues.
Would you like to add the tag “Fixes” for the completion of the error handling
in this function implementation?
…
> +++ b/drivers/soc/amlogic/meson-mx-socinfo.c
> @@ -160,6 +160,12 @@ static int __init meson_mx_socinfo_init(void)
> metal_rev);
> soc_dev_attr->soc_id = meson_mx_socinfo_soc_id(major_ver, metal_rev);
>
> + if (!soc_dev_attr->revision || !soc_dev_attr->soc_id) {
I suggest to split such a check for null pointers.
> + kfree_const(soc_dev_attr->revision);
> + kfree_const(soc_dev_attr->soc_id);
> + kfree(soc_dev_attr);
> + return -ENOMEM;
> + }
> soc_dev = soc_device_register(soc_dev_attr);
> if (IS_ERR(soc_dev)) {
> kfree_const(soc_dev_attr->revision);
Please use a goto chain for better exception handling.
https://wiki.sei.cmu.edu/confluence/display/c/MEM12-C.+Consider+using+a+goto+chain+when+leaving+a+function+on+error+when+using+and+releasing+resources
Regards,
Markus
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
prev parent reply other threads:[~2024-01-19 9:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-19 7:46 Kunwu Chan
2024-01-19 9:06 ` Markus Elfring [this message]
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=a5f974aa-826d-421b-bfe2-bb6c9b43ea9a@web.de \
--to=markus.elfring@web.de \
--cc=chentao@kylinos.cn \
--cc=jbrunet@baylibre.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=khilman@baylibre.com \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=neil.armstrong@linaro.org \
/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®