Thread (1 message) 1 message, 1 author, 2020-06-09

Re: [PATCH] bpf: alloc_record_per_cpu Add null check after malloc

From: Jesper Dangaard Brouer <hidden>
Date: 2020-06-09 06:50:35
Also in: bpf, lkml

On Sat, 6 Jun 2020 19:59:48 -0400
gaurav singh [off-list ref] wrote:
Hi,

The memset call is made right after malloc call. To fix this, add the null
check right after malloc and then do memset.

Please find the patch below.
The fix in your patch seem correct (although there are more places),
but the way you send/submit the patch is wrong.  The patch itself also
mangle whitespaces.

You can read the guide:

 https://www.kernel.org/doc/html/latest/process/submitting-patches.html
 https://www.kernel.org/doc/html/latest/process/index.html

--Jesper

quoted hunk
Thanks and regards,
Gaurav.


From 552b7df0e12572737929c60478b5dca2a40f4ad9 Mon Sep 17 00:00:00 2001
From: Gaurav Singh <redacted>
Date: Sat, 6 Jun 2020 19:57:48 -0400
Subject: [PATCH] bpf: alloc_record_per_cpu Add null check after malloc

Signed-off-by: Gaurav Singh <redacted>
---
 samples/bpf/xdp_rxq_info_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/bpf/xdp_rxq_info_user.c
b/samples/bpf/xdp_rxq_info_user.c
index 4fe47502ebed..490b07b7df78 100644
--- a/samples/bpf/xdp_rxq_info_user.c
+++ b/samples/bpf/xdp_rxq_info_user.c
@@ -202,11 +202,11 @@ static struct datarec *alloc_record_per_cpu(void)

  size = sizeof(struct datarec) * nr_cpus;
  array = malloc(size);
- memset(array, 0, size);
  if (!array) {
  fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus);
  exit(EXIT_FAIL_MEM);
  }
+ memset(array, 0, size);
  return array;
 }


-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help