On Mon, May 04, 2026 at 12:35:58PM -0400, Aaron Merey wrote:
> Hi Mark,
> 
> On Mon, May 4, 2026 at 11:55 AM Mark Wielaard <[email protected]> wrote:
> >
> >         * libebl/eblinitreg_sample.c (ebl_sample_perf_regs_mapping):
> >         Return false when calloc fails.
> >
> > Signed-off-by: Mark Wielaard <[email protected]>
> 
> LGTM.

Thanks. But reading it over again I think we also shouldn't set
cached_perf_regs_mask if cached_regs_mapping is NULL. Because we check
that just above. It is unlikely that after the calloc fail we get back
at ebl_sample_perf_regs_mapping, but better to keep things as
consistent as possible just in case.

How about the attached?

Cheers,

Mark
>From 45e3efe96adb16ba958868f1e6f46d57cda2640b Mon Sep 17 00:00:00 2001
From: Mark Wielaard <[email protected]>
Date: Mon, 4 May 2026 17:55:03 +0200
Subject: [PATCH] libebl: Handle calloc failure in ebl_sample_perf_regs_mapping

        * libebl/eblinitreg_sample.c (ebl_sample_perf_regs_mapping):
        Return false when calloc fails and only set
        cached_perf_regs_mask on success.

Signed-off-by: Mark Wielaard <[email protected]>
---
 libebl/eblinitreg_sample.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libebl/eblinitreg_sample.c b/libebl/eblinitreg_sample.c
index 2b5a278a72eb..feba2c64b2e8 100644
--- a/libebl/eblinitreg_sample.c
+++ b/libebl/eblinitreg_sample.c
@@ -110,8 +110,10 @@ ebl_sample_perf_regs_mapping (Ebl *ebl,
 
   if (ebl->cached_regs_mapping != NULL)
     free (ebl->cached_regs_mapping);
-  ebl->cached_perf_regs_mask = perf_regs_mask;
   ebl->cached_regs_mapping = (int *)calloc (count, sizeof(int));
+  if (ebl->cached_regs_mapping == NULL)
+    return false;
+  ebl->cached_perf_regs_mask = perf_regs_mask;
   ebl->cached_n_regs_mapping = count;
 
   int j, k; uint64_t bit;
-- 
2.53.0

Reply via email to