aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2019-02-13 13:25:53 -0500
committerAlexei Starovoitov <ast@kernel.org>2019-02-14 18:31:39 -0500
commit1ad9cbb890f059dd233868654bb9d9e4430b095c (patch)
tree2ab84aec12d5ef2766b9565ad86ebdfea5e96afb
parentfb405883c189dd30f2fab2b3e2c954f34f000ac3 (diff)
tools/bpf: replace bzero with memset
bzero() call is deprecated and superseded by memset(). Signed-off-by: Andrii Nakryiko <andriin@fb.com> Reported-by: David Laight <david.laight@aculab.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r--tools/lib/bpf/bpf.c48
-rw-r--r--tools/lib/bpf/btf.c5
-rw-r--r--tools/lib/bpf/libbpf.c5
3 files changed, 28 insertions, 30 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index a5261f39e2bd..9cd015574e83 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -22,7 +22,7 @@
22 */ 22 */
23 23
24#include <stdlib.h> 24#include <stdlib.h>
25#include <strings.h> 25#include <string.h>
26#include <memory.h> 26#include <memory.h>
27#include <unistd.h> 27#include <unistd.h>
28#include <asm/unistd.h> 28#include <asm/unistd.h>
@@ -228,7 +228,7 @@ int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr,
228 228
229 name_len = load_attr->name ? strlen(load_attr->name) : 0; 229 name_len = load_attr->name ? strlen(load_attr->name) : 0;
230 230
231 bzero(&attr, sizeof(attr)); 231 memset(&attr, 0, sizeof(attr));
232 attr.prog_type = load_attr->prog_type; 232 attr.prog_type = load_attr->prog_type;
233 attr.expected_attach_type = load_attr->expected_attach_type; 233 attr.expected_attach_type = load_attr->expected_attach_type;
234 attr.insn_cnt = (__u32)load_attr->insns_cnt; 234 attr.insn_cnt = (__u32)load_attr->insns_cnt;
@@ -340,7 +340,7 @@ int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns,
340{ 340{
341 union bpf_attr attr; 341 union bpf_attr attr;
342 342
343 bzero(&attr, sizeof(attr)); 343 memset(&attr, 0, sizeof(attr));
344 attr.prog_type = type; 344 attr.prog_type = type;
345 attr.insn_cnt = (__u32)insns_cnt; 345 attr.insn_cnt = (__u32)insns_cnt;
346 attr.insns = ptr_to_u64(insns); 346 attr.insns = ptr_to_u64(insns);
@@ -360,7 +360,7 @@ int bpf_map_update_elem(int fd, const void *key, const void *value,
360{ 360{
361 union bpf_attr attr; 361 union bpf_attr attr;
362 362
363 bzero(&attr, sizeof(attr)); 363 memset(&attr, 0, sizeof(attr));
364 attr.map_fd = fd; 364 attr.map_fd = fd;
365 attr.key = ptr_to_u64(key); 365 attr.key = ptr_to_u64(key);
366 attr.value = ptr_to_u64(value); 366 attr.value = ptr_to_u64(value);
@@ -373,7 +373,7 @@ int bpf_map_lookup_elem(int fd, const void *key, void *value)
373{ 373{
374 union bpf_attr attr; 374 union bpf_attr attr;
375 375
376 bzero(&attr, sizeof(attr)); 376 memset(&attr, 0, sizeof(attr));
377 attr.map_fd = fd; 377 attr.map_fd = fd;
378 attr.key = ptr_to_u64(key); 378 attr.key = ptr_to_u64(key);
379 attr.value = ptr_to_u64(value); 379 attr.value = ptr_to_u64(value);
@@ -385,7 +385,7 @@ int bpf_map_lookup_elem_flags(int fd, const void *key, void *value, __u64 flags)
385{ 385{
386 union bpf_attr attr; 386 union bpf_attr attr;
387 387
388 bzero(&attr, sizeof(attr)); 388 memset(&attr, 0, sizeof(attr));
389 attr.map_fd = fd; 389 attr.map_fd = fd;
390 attr.key = ptr_to_u64(key); 390 attr.key = ptr_to_u64(key);
391 attr.value = ptr_to_u64(value); 391 attr.value = ptr_to_u64(value);
@@ -398,7 +398,7 @@ int bpf_map_lookup_and_delete_elem(int fd, const void *key, void *value)
398{ 398{
399 union bpf_attr attr; 399 union bpf_attr attr;
400 400
401 bzero(&attr, sizeof(attr)); 401 memset(&attr, 0, sizeof(attr));
402 attr.map_fd = fd; 402 attr.map_fd = fd;
403 attr.key = ptr_to_u64(key); 403 attr.key = ptr_to_u64(key);
404 attr.value = ptr_to_u64(value); 404 attr.value = ptr_to_u64(value);
@@ -410,7 +410,7 @@ int bpf_map_delete_elem(int fd, const void *key)
410{ 410{
411 union bpf_attr attr; 411 union bpf_attr attr;
412 412
413 bzero(&attr, sizeof(attr)); 413 memset(&attr, 0, sizeof(attr));
414 attr.map_fd = fd; 414 attr.map_fd = fd;
415 attr.key = ptr_to_u64(key); 415 attr.key = ptr_to_u64(key);
416 416
@@ -421,7 +421,7 @@ int bpf_map_get_next_key(int fd, const void *key, void *next_key)
421{ 421{
422 union bpf_attr attr; 422 union bpf_attr attr;
423 423
424 bzero(&attr, sizeof(attr)); 424 memset(&attr, 0, sizeof(attr));
425 attr.map_fd = fd; 425 attr.map_fd = fd;
426 attr.key = ptr_to_u64(key); 426 attr.key = ptr_to_u64(key);
427 attr.next_key = ptr_to_u64(next_key); 427 attr.next_key = ptr_to_u64(next_key);
@@ -433,7 +433,7 @@ int bpf_obj_pin(int fd, const char *pathname)
433{ 433{
434 union bpf_attr attr; 434 union bpf_attr attr;
435 435
436 bzero(&attr, sizeof(attr)); 436 memset(&attr, 0, sizeof(attr));
437 attr.pathname = ptr_to_u64((void *)pathname); 437 attr.pathname = ptr_to_u64((void *)pathname);
438 attr.bpf_fd = fd; 438 attr.bpf_fd = fd;
439 439
@@ -444,7 +444,7 @@ int bpf_obj_get(const char *pathname)
444{ 444{
445 union bpf_attr attr; 445 union bpf_attr attr;
446 446
447 bzero(&attr, sizeof(attr)); 447 memset(&attr, 0, sizeof(attr));
448 attr.pathname = ptr_to_u64((void *)pathname); 448 attr.pathname = ptr_to_u64((void *)pathname);
449 449
450 return sys_bpf(BPF_OBJ_GET, &attr, sizeof(attr)); 450 return sys_bpf(BPF_OBJ_GET, &attr, sizeof(attr));
@@ -455,7 +455,7 @@ int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type,
455{ 455{
456 union bpf_attr attr; 456 union bpf_attr attr;
457 457
458 bzero(&attr, sizeof(attr)); 458 memset(&attr, 0, sizeof(attr));
459 attr.target_fd = target_fd; 459 attr.target_fd = target_fd;
460 attr.attach_bpf_fd = prog_fd; 460 attr.attach_bpf_fd = prog_fd;
461 attr.attach_type = type; 461 attr.attach_type = type;
@@ -468,7 +468,7 @@ int bpf_prog_detach(int target_fd, enum bpf_attach_type type)
468{ 468{
469 union bpf_attr attr; 469 union bpf_attr attr;
470 470
471 bzero(&attr, sizeof(attr)); 471 memset(&attr, 0, sizeof(attr));
472 attr.target_fd = target_fd; 472 attr.target_fd = target_fd;
473 attr.attach_type = type; 473 attr.attach_type = type;
474 474
@@ -479,7 +479,7 @@ int bpf_prog_detach2(int prog_fd, int target_fd, enum bpf_attach_type type)
479{ 479{
480 union bpf_attr attr; 480 union bpf_attr attr;
481 481
482 bzero(&attr, sizeof(attr)); 482 memset(&attr, 0, sizeof(attr));
483 attr.target_fd = target_fd; 483 attr.target_fd = target_fd;
484 attr.attach_bpf_fd = prog_fd; 484 attr.attach_bpf_fd = prog_fd;
485 attr.attach_type = type; 485 attr.attach_type = type;
@@ -493,7 +493,7 @@ int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags,
493 union bpf_attr attr; 493 union bpf_attr attr;
494 int ret; 494 int ret;
495 495
496 bzero(&attr, sizeof(attr)); 496 memset(&attr, 0, sizeof(attr));
497 attr.query.target_fd = target_fd; 497 attr.query.target_fd = target_fd;
498 attr.query.attach_type = type; 498 attr.query.attach_type = type;
499 attr.query.query_flags = query_flags; 499 attr.query.query_flags = query_flags;
@@ -514,7 +514,7 @@ int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size,
514 union bpf_attr attr; 514 union bpf_attr attr;
515 int ret; 515 int ret;
516 516
517 bzero(&attr, sizeof(attr)); 517 memset(&attr, 0, sizeof(attr));
518 attr.test.prog_fd = prog_fd; 518 attr.test.prog_fd = prog_fd;
519 attr.test.data_in = ptr_to_u64(data); 519 attr.test.data_in = ptr_to_u64(data);
520 attr.test.data_out = ptr_to_u64(data_out); 520 attr.test.data_out = ptr_to_u64(data_out);
@@ -539,7 +539,7 @@ int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr)
539 if (!test_attr->data_out && test_attr->data_size_out > 0) 539 if (!test_attr->data_out && test_attr->data_size_out > 0)
540 return -EINVAL; 540 return -EINVAL;
541 541
542 bzero(&attr, sizeof(attr)); 542 memset(&attr, 0, sizeof(attr));
543 attr.test.prog_fd = test_attr->prog_fd; 543 attr.test.prog_fd = test_attr->prog_fd;
544 attr.test.data_in = ptr_to_u64(test_attr->data_in); 544 attr.test.data_in = ptr_to_u64(test_attr->data_in);
545 attr.test.data_out = ptr_to_u64(test_attr->data_out); 545 attr.test.data_out = ptr_to_u64(test_attr->data_out);
@@ -559,7 +559,7 @@ int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id)
559 union bpf_attr attr; 559 union bpf_attr attr;
560 int err; 560 int err;
561 561
562 bzero(&attr, sizeof(attr)); 562 memset(&attr, 0, sizeof(attr));
563 attr.start_id = start_id; 563 attr.start_id = start_id;
564 564
565 err = sys_bpf(BPF_PROG_GET_NEXT_ID, &attr, sizeof(attr)); 565 err = sys_bpf(BPF_PROG_GET_NEXT_ID, &attr, sizeof(attr));
@@ -574,7 +574,7 @@ int bpf_map_get_next_id(__u32 start_id, __u32 *next_id)
574 union bpf_attr attr; 574 union bpf_attr attr;
575 int err; 575 int err;
576 576
577 bzero(&attr, sizeof(attr)); 577 memset(&attr, 0, sizeof(attr));
578 attr.start_id = start_id; 578 attr.start_id = start_id;
579 579
580 err = sys_bpf(BPF_MAP_GET_NEXT_ID, &attr, sizeof(attr)); 580 err = sys_bpf(BPF_MAP_GET_NEXT_ID, &attr, sizeof(attr));
@@ -588,7 +588,7 @@ int bpf_prog_get_fd_by_id(__u32 id)
588{ 588{
589 union bpf_attr attr; 589 union bpf_attr attr;
590 590
591 bzero(&attr, sizeof(attr)); 591 memset(&attr, 0, sizeof(attr));
592 attr.prog_id = id; 592 attr.prog_id = id;
593 593
594 return sys_bpf(BPF_PROG_GET_FD_BY_ID, &attr, sizeof(attr)); 594 return sys_bpf(BPF_PROG_GET_FD_BY_ID, &attr, sizeof(attr));
@@ -598,7 +598,7 @@ int bpf_map_get_fd_by_id(__u32 id)
598{ 598{
599 union bpf_attr attr; 599 union bpf_attr attr;
600 600
601 bzero(&attr, sizeof(attr)); 601 memset(&attr, 0, sizeof(attr));
602 attr.map_id = id; 602 attr.map_id = id;
603 603
604 return sys_bpf(BPF_MAP_GET_FD_BY_ID, &attr, sizeof(attr)); 604 return sys_bpf(BPF_MAP_GET_FD_BY_ID, &attr, sizeof(attr));
@@ -608,7 +608,7 @@ int bpf_btf_get_fd_by_id(__u32 id)
608{ 608{
609 union bpf_attr attr; 609 union bpf_attr attr;
610 610
611 bzero(&attr, sizeof(attr)); 611 memset(&attr, 0, sizeof(attr));
612 attr.btf_id = id; 612 attr.btf_id = id;
613 613
614 return sys_bpf(BPF_BTF_GET_FD_BY_ID, &attr, sizeof(attr)); 614 return sys_bpf(BPF_BTF_GET_FD_BY_ID, &attr, sizeof(attr));
@@ -619,7 +619,7 @@ int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len)
619 union bpf_attr attr; 619 union bpf_attr attr;
620 int err; 620 int err;
621 621
622 bzero(&attr, sizeof(attr)); 622 memset(&attr, 0, sizeof(attr));
623 attr.info.bpf_fd = prog_fd; 623 attr.info.bpf_fd = prog_fd;
624 attr.info.info_len = *info_len; 624 attr.info.info_len = *info_len;
625 attr.info.info = ptr_to_u64(info); 625 attr.info.info = ptr_to_u64(info);
@@ -635,7 +635,7 @@ int bpf_raw_tracepoint_open(const char *name, int prog_fd)
635{ 635{
636 union bpf_attr attr; 636 union bpf_attr attr;
637 637
638 bzero(&attr, sizeof(attr)); 638 memset(&attr, 0, sizeof(attr));
639 attr.raw_tracepoint.name = ptr_to_u64(name); 639 attr.raw_tracepoint.name = ptr_to_u64(name);
640 attr.raw_tracepoint.prog_fd = prog_fd; 640 attr.raw_tracepoint.prog_fd = prog_fd;
641 641
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 6953fedb88ff..ade1c32fb083 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -4,7 +4,6 @@
4#include <stdio.h> 4#include <stdio.h>
5#include <stdlib.h> 5#include <stdlib.h>
6#include <string.h> 6#include <string.h>
7#include <strings.h>
8#include <unistd.h> 7#include <unistd.h>
9#include <errno.h> 8#include <errno.h>
10#include <linux/err.h> 9#include <linux/err.h>
@@ -484,7 +483,7 @@ int btf__get_from_id(__u32 id, struct btf **btf)
484 goto exit_free; 483 goto exit_free;
485 } 484 }
486 485
487 bzero(ptr, last_size); 486 memset(ptr, 0, last_size);
488 btf_info.btf = ptr_to_u64(ptr); 487 btf_info.btf = ptr_to_u64(ptr);
489 err = bpf_obj_get_info_by_fd(btf_fd, &btf_info, &len); 488 err = bpf_obj_get_info_by_fd(btf_fd, &btf_info, &len);
490 489
@@ -498,7 +497,7 @@ int btf__get_from_id(__u32 id, struct btf **btf)
498 goto exit_free; 497 goto exit_free;
499 } 498 }
500 ptr = temp_ptr; 499 ptr = temp_ptr;
501 bzero(ptr, last_size); 500 memset(ptr, 0, last_size);
502 btf_info.btf = ptr_to_u64(ptr); 501 btf_info.btf = ptr_to_u64(ptr);
503 err = bpf_obj_get_info_by_fd(btf_fd, &btf_info, &len); 502 err = bpf_obj_get_info_by_fd(btf_fd, &btf_info, &len);
504 } 503 }
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index e3c39edfb9d3..6ef7e6e4cbd3 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -18,7 +18,6 @@
18#include <libgen.h> 18#include <libgen.h>
19#include <inttypes.h> 19#include <inttypes.h>
20#include <string.h> 20#include <string.h>
21#include <strings.h>
22#include <unistd.h> 21#include <unistd.h>
23#include <fcntl.h> 22#include <fcntl.h>
24#include <errno.h> 23#include <errno.h>
@@ -308,7 +307,7 @@ bpf_program__init(void *data, size_t size, char *section_name, int idx,
308 return -EINVAL; 307 return -EINVAL;
309 } 308 }
310 309
311 bzero(prog, sizeof(*prog)); 310 memset(prog, 0, sizeof(*prog));
312 311
313 prog->section_name = strdup(section_name); 312 prog->section_name = strdup(section_name);
314 if (!prog->section_name) { 313 if (!prog->section_name) {
@@ -1577,7 +1576,7 @@ bpf_program__load(struct bpf_program *prog,
1577 struct bpf_prog_prep_result result; 1576 struct bpf_prog_prep_result result;
1578 bpf_program_prep_t preprocessor = prog->preprocessor; 1577 bpf_program_prep_t preprocessor = prog->preprocessor;
1579 1578
1580 bzero(&result, sizeof(result)); 1579 memset(&result, 0, sizeof(result));
1581 err = preprocessor(prog, i, prog->insns, 1580 err = preprocessor(prog, i, prog->insns,
1582 prog->insns_cnt, &result); 1581 prog->insns_cnt, &result);
1583 if (err) { 1582 if (err) {