From: David Yang Date: Tue, 12 Oct 2021 11:16:49 +0000 (+0800) Subject: samples/bpf: Fix application of sizeof to pointer X-Git-Tag: v6.6.17~8953^2~2^2~50 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b599015f044df53e93ad0a2957b615bc1a26bf73;p=platform%2Fkernel%2Flinux-rpi.git samples/bpf: Fix application of sizeof to pointer The coccinelle check report: "./samples/bpf/xdp_redirect_cpu_user.c:397:32-38: ERROR: application of sizeof to pointer" Using the "strlen" to fix it. Reported-by: Zeal Robot Signed-off-by: David Yang Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20211012111649.983253-1-davidcomponentone@gmail.com --- diff --git a/samples/bpf/xdp_redirect_cpu_user.c b/samples/bpf/xdp_redirect_cpu_user.c index 6e25fba..d84e694 100644 --- a/samples/bpf/xdp_redirect_cpu_user.c +++ b/samples/bpf/xdp_redirect_cpu_user.c @@ -325,7 +325,6 @@ int main(int argc, char **argv) int add_cpu = -1; int ifindex = -1; int *cpu, i, opt; - char *ifname; __u32 qsize; int n_cpus; @@ -393,9 +392,8 @@ int main(int argc, char **argv) fprintf(stderr, "-d/--dev name too long\n"); goto end_cpu; } - ifname = (char *)&ifname_buf; - safe_strncpy(ifname, optarg, sizeof(ifname)); - ifindex = if_nametoindex(ifname); + safe_strncpy(ifname_buf, optarg, strlen(ifname_buf)); + ifindex = if_nametoindex(ifname_buf); if (!ifindex) ifindex = strtoul(optarg, NULL, 0); if (!ifindex) {