mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Li kunyu <kunyu@nfschina.com>
To: shuah@kernel.org
Cc: trenn@suse.com, ray.huang@amd.com, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, Li kunyu <kunyu@nfschina.com>
Subject: [PATCH] power: cpupower: utils: Add malloc return value check
Date: Fri, 14 Oct 2022 12:29:11 +0800	[thread overview]
Message-ID: <20221014042911.298308-1-kunyu@nfschina.com> (raw)

Add the check and judgment statement of malloc return value.

Signed-off-by: Li kunyu <kunyu@nfschina.com>
---
 tools/power/cpupower/utils/helpers/misc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c
index 9547b29254a7..eafdbd6d760c 100644
--- a/tools/power/cpupower/utils/helpers/misc.c
+++ b/tools/power/cpupower/utils/helpers/misc.c
@@ -139,6 +139,8 @@ void print_online_cpus(void)
 
 	str_len = online_cpus->size * 5;
 	online_cpus_str = (void *)malloc(sizeof(char) * str_len);
+	if (unlikely(!online_cpus_str))
+		return;
 
 	if (!bitmask_isallclear(online_cpus)) {
 		bitmask_displaylist(online_cpus_str, str_len, online_cpus);
@@ -157,6 +159,8 @@ void print_offline_cpus(void)
 
 	str_len = offline_cpus->size * 5;
 	offline_cpus_str = (void *)malloc(sizeof(char) * str_len);
+	if (unlikely(!offline_cpus_str))
+		return;
 
 	if (!bitmask_isallclear(offline_cpus)) {
 		bitmask_displaylist(offline_cpus_str, str_len, offline_cpus);
-- 
2.18.2


             reply	other threads:[~2022-10-14  4:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14  4:29 Li kunyu [this message]
2022-10-18 20:33 ` Shuah Khan

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=20221014042911.298308-1-kunyu@nfschina.com \
    --to=kunyu@nfschina.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=ray.huang@amd.com \
    --cc=shuah@kernel.org \
    --cc=trenn@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®