powerpc/imc-pmu: Add a null pointer check in update_events_in_group()
authorKunwu Chan <chentao@kylinos.cn>
Sun, 26 Nov 2023 09:37:19 +0000 (17:37 +0800)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 13 Dec 2023 11:19:43 +0000 (22:19 +1100)
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Fixes: 885dcd709ba9 ("powerpc/perf: Add nest IMC PMU support")
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20231126093719.1440305-1-chentao@kylinos.cn
arch/powerpc/perf/imc-pmu.c

index 5d12ca386c1fcbb1e464379c76031075ee4bd7bc..8664a7d297ad8188eb4842abd2ccc106005324fb 100644 (file)
@@ -299,6 +299,8 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu)
        attr_group->attrs = attrs;
        do {
                ev_val_str = kasprintf(GFP_KERNEL, "event=0x%x", pmu->events[i].value);
+               if (!ev_val_str)
+                       continue;
                dev_str = device_str_attr_create(pmu->events[i].name, ev_val_str);
                if (!dev_str)
                        continue;
@@ -306,6 +308,8 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu)
                attrs[j++] = dev_str;
                if (pmu->events[i].scale) {
                        ev_scale_str = kasprintf(GFP_KERNEL, "%s.scale", pmu->events[i].name);
+                       if (!ev_scale_str)
+                               continue;
                        dev_str = device_str_attr_create(ev_scale_str, pmu->events[i].scale);
                        if (!dev_str)
                                continue;
@@ -315,6 +319,8 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu)
 
                if (pmu->events[i].unit) {
                        ev_unit_str = kasprintf(GFP_KERNEL, "%s.unit", pmu->events[i].name);
+                       if (!ev_unit_str)
+                               continue;
                        dev_str = device_str_attr_create(ev_unit_str, pmu->events[i].unit);
                        if (!dev_str)
                                continue;