Skip to contentSkip to conversation

power: cpupower: utils: Add malloc return value check

PATCH New Li kunyu 1 participant 1 message Oct 19, 2022 CPU power monitoring

lore
Share & tools
lore

Li kunyu

author
#0 lore raw

PATCH v2 1/1 power: cpupower: utils: Add malloc return value check

Add the check and judgment statement of malloc return value.

---
v2: Remove unlikely() check

 tools/power/cpupower/utils/helpers/misc.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/power/cpupower/utils/helpers/misc.c +4 -0
index 36dbd0562240..083d5a6bb74e 100644
@@ -139,6 +139,8 @@ void print_online_cpus(void)
 
 	str_len = online_cpus->size * 5;
 	online_cpus_str = malloc(sizeof(char) * str_len);
+	if (!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 = malloc(sizeof(char) * str_len);
+	if (!offline_cpus_str)
+		return;
 
 	if (!bitmask_isallclear(offline_cpus)) {
 		bitmask_displaylist(offline_cpus_str, str_len, offline_cpus);
Signature · 1 line
2.18.2