bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* (no subject)
@ 2020-06-09 11:38 Gaurav Singh
  2020-06-09 11:38 ` [PATCH] bpf: alloc_record_per_cpu Add null check after malloc Gaurav Singh
  0 siblings, 1 reply; 5+ messages in thread
From: Gaurav Singh @ 2020-06-09 11:38 UTC (permalink / raw)
  To: gaurav1086, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	John Fastabend, KP Singh, David S. Miller, Jakub Kicinski,
	Jesper Dangaard Brouer,
	open list:BPF (Safe dynamic programs and tools),
	open list:BPF (Safe dynamic programs and tools),
	open list

Please find the patch below.

Thanks and regards,
Gaurav.

From Gaurav Singh <gaurav1086@gmail.com> # This line is ignored.
From: Gaurav Singh <gaurav1086@gmail.com>
Reply-To: 
Subject: 
In-Reply-To: 



^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH] bpf: alloc_record_per_cpu Add null check after malloc
@ 2020-06-09 12:08 Gaurav Singh
  2020-06-09 12:23 ` Jesper Dangaard Brouer
  0 siblings, 1 reply; 5+ messages in thread
From: Gaurav Singh @ 2020-06-09 12:08 UTC (permalink / raw)
  To: gaurav1086, Alexei Starovoitov, Daniel Borkmann, David S. Miller,
	Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	KP Singh, open list:XDP (eXpress Data Path),
	open list:XDP (eXpress Data Path),
	open list

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

Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
---
 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;
 }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-09 12:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAFAFadDVe1Au2eJ8ho_cK1riwf9FDaGck3o+VEcKpqRgO5qXdA@mail.gmail.com>
2020-06-09  6:50 ` [PATCH] bpf: alloc_record_per_cpu Add null check after malloc Jesper Dangaard Brouer
2020-06-09 11:38 Gaurav Singh
2020-06-09 11:38 ` [PATCH] bpf: alloc_record_per_cpu Add null check after malloc Gaurav Singh
2020-06-09 11:55   ` Greg KH
2020-06-09 12:08 Gaurav Singh
2020-06-09 12:23 ` Jesper Dangaard Brouer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).