From patchwork Fri Sep 6 07:31:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 1158814 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46Pq4l1Tfdz9s7T for ; Fri, 6 Sep 2019 17:31:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391822AbfIFHbu (ORCPT ); Fri, 6 Sep 2019 03:31:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52088 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732504AbfIFHbt (ORCPT ); Fri, 6 Sep 2019 03:31:49 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BD8C38980FA; Fri, 6 Sep 2019 07:31:49 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.205.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2E27600CC; Fri, 6 Sep 2019 07:31:47 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Yonghong Song , Martin KaFai Lau Subject: [PATCH 1/7] libbpf: Use const cast for btf_int_* functions Date: Fri, 6 Sep 2019 09:31:38 +0200 Message-Id: <20190906073144.31068-2-jolsa@kernel.org> In-Reply-To: <20190906073144.31068-1-jolsa@kernel.org> References: <20190906073144.31068-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Fri, 06 Sep 2019 07:31:49 +0000 (UTC) Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org I'm getting following errors when compiling with -Wcast-qual: bpf/btf.h: In function ‘__u8 btf_int_offset(const btf_type*)’: bpf/btf.h:244:40: warning: cast from type ‘const btf_type*’ to type ‘__u32*’ {aka ‘unsigned int*’} casts away qualifiers [-Wcast-qual] 244 | return BTF_INT_OFFSET(*(__u32 *)(t + 1)); | ^ The argument is const so the cast to following __u32 pointer should be const as well. Signed-off-by: Jiri Olsa --- tools/lib/bpf/btf.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 9cb44b4fbf60..952e3496467d 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -236,17 +236,17 @@ static inline bool btf_is_datasec(const struct btf_type *t) static inline __u8 btf_int_encoding(const struct btf_type *t) { - return BTF_INT_ENCODING(*(__u32 *)(t + 1)); + return BTF_INT_ENCODING(*(const __u32 *)(t + 1)); } static inline __u8 btf_int_offset(const struct btf_type *t) { - return BTF_INT_OFFSET(*(__u32 *)(t + 1)); + return BTF_INT_OFFSET(*(const __u32 *)(t + 1)); } static inline __u8 btf_int_bits(const struct btf_type *t) { - return BTF_INT_BITS(*(__u32 *)(t + 1)); + return BTF_INT_BITS(*(const __u32 *)(t + 1)); } static inline struct btf_array *btf_array(const struct btf_type *t) From patchwork Fri Sep 6 07:31:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 1158817 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46Pq4n6wKCz9s7T for ; Fri, 6 Sep 2019 17:31:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404145AbfIFHbw (ORCPT ); Fri, 6 Sep 2019 03:31:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45096 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732504AbfIFHbw (ORCPT ); Fri, 6 Sep 2019 03:31:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5CFC335C1; Fri, 6 Sep 2019 07:31:51 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.205.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1ECE0600CC; Fri, 6 Sep 2019 07:31:49 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Yonghong Song , Martin KaFai Lau Subject: [PATCH 2/7] libbpf: Return const btf_array from btf_array inline function Date: Fri, 6 Sep 2019 09:31:39 +0200 Message-Id: <20190906073144.31068-3-jolsa@kernel.org> In-Reply-To: <20190906073144.31068-1-jolsa@kernel.org> References: <20190906073144.31068-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 06 Sep 2019 07:31:52 +0000 (UTC) Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org I'm getting following errors when compiling with -Wcast-qual: bpf/btf.h: In function ‘btf_array* btf_array(const btf_type*)’: bpf/btf.h:254:35: warning: cast from type ‘const btf_type*’ to type ‘btf_array*’ casts away qualifiers [-Wcast-qual] 254 | return (struct btf_array *)(t + 1); | ^ The argument is const so the cast to following struct btf_array pointer should be const as well. Casting the const away in btf.c calls where it's correctly used without const in deduplication code. Signed-off-by: Jiri Olsa --- tools/lib/bpf/btf.c | 4 ++-- tools/lib/bpf/btf.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 1aa189a9112a..d6327bcc713a 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -2587,7 +2587,7 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id) break; case BTF_KIND_ARRAY: { - struct btf_array *info = btf_array(t); + struct btf_array *info = (struct btf_array *) btf_array(t); ref_type_id = btf_dedup_ref_type(d, info->type); if (ref_type_id < 0) @@ -2782,7 +2782,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id) break; case BTF_KIND_ARRAY: { - struct btf_array *arr_info = btf_array(t); + struct btf_array *arr_info = (struct btf_array *) btf_array(t); r = btf_dedup_remap_type_id(d, arr_info->type); if (r < 0) diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 952e3496467d..6bbf5772aa61 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -249,9 +249,9 @@ static inline __u8 btf_int_bits(const struct btf_type *t) return BTF_INT_BITS(*(const __u32 *)(t + 1)); } -static inline struct btf_array *btf_array(const struct btf_type *t) +static inline const struct btf_array *btf_array(const struct btf_type *t) { - return (struct btf_array *)(t + 1); + return (const struct btf_array *)(t + 1); } static inline struct btf_enum *btf_enum(const struct btf_type *t) From patchwork Fri Sep 6 07:31:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 1158819 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46Pq4r2Qprz9sN1 for ; Fri, 6 Sep 2019 17:31:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404521AbfIFHbz (ORCPT ); Fri, 6 Sep 2019 03:31:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47358 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732504AbfIFHby (ORCPT ); Fri, 6 Sep 2019 03:31:54 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E5144369CC; Fri, 6 Sep 2019 07:31:53 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.205.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30AEA600CC; Fri, 6 Sep 2019 07:31:52 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Yonghong Song , Martin KaFai Lau Subject: [PATCH 3/7] libbpf: Return const btf_enum from btf_enum inline function Date: Fri, 6 Sep 2019 09:31:40 +0200 Message-Id: <20190906073144.31068-4-jolsa@kernel.org> In-Reply-To: <20190906073144.31068-1-jolsa@kernel.org> References: <20190906073144.31068-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 06 Sep 2019 07:31:54 +0000 (UTC) Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org I'm getting following errors when compiling with -Wcast-qual: bpf/btf.h: In function ‘btf_enum* btf_enum(const btf_type*)’: bpf/btf.h:259:34: warning: cast from type ‘const btf_type*’ to type ‘btf_enum*’ casts away qualifier 259 | return (struct btf_enum *)(t + 1); | ^ The argument is const so the cast to following struct btf_enum pointer should be const as well. Casting the const away in btf.c call where it's correctly used without const in deduplication code. Signed-off-by: Jiri Olsa --- tools/lib/bpf/btf.c | 2 +- tools/lib/bpf/btf.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index d6327bcc713a..5a39e9506760 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -1475,7 +1475,7 @@ static int btf_for_each_str_off(struct btf_dedup *d, str_off_fn_t fn, void *ctx) break; } case BTF_KIND_ENUM: { - struct btf_enum *m = btf_enum(t); + struct btf_enum *m = (struct btf_enum *) btf_enum(t); __u16 vlen = btf_vlen(t); for (j = 0; j < vlen; j++) { diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 6bbf5772aa61..3b3216fa348f 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -254,9 +254,9 @@ static inline const struct btf_array *btf_array(const struct btf_type *t) return (const struct btf_array *)(t + 1); } -static inline struct btf_enum *btf_enum(const struct btf_type *t) +static inline const struct btf_enum *btf_enum(const struct btf_type *t) { - return (struct btf_enum *)(t + 1); + return (const struct btf_enum *)(t + 1); } static inline struct btf_member *btf_members(const struct btf_type *t) From patchwork Fri Sep 6 07:31:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 1158820 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46Pq4s4GG0z9s7T for ; Fri, 6 Sep 2019 17:31:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404543AbfIFHb4 (ORCPT ); Fri, 6 Sep 2019 03:31:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59922 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404541AbfIFHb4 (ORCPT ); Fri, 6 Sep 2019 03:31:56 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 08F0218C8934; Fri, 6 Sep 2019 07:31:56 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.205.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 432C9600CC; Fri, 6 Sep 2019 07:31:54 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Yonghong Song , Martin KaFai Lau Subject: [PATCH 4/7] libbpf: Return const btf_member from btf_members inline function Date: Fri, 6 Sep 2019 09:31:41 +0200 Message-Id: <20190906073144.31068-5-jolsa@kernel.org> In-Reply-To: <20190906073144.31068-1-jolsa@kernel.org> References: <20190906073144.31068-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Fri, 06 Sep 2019 07:31:56 +0000 (UTC) Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org I'm getting following errors when compiling with -Wcast-qual: bpf/btf.h: In function ‘btf_member* btf_members(const btf_type*)’: bpf/btf.h:264:36: warning: cast from type ‘const btf_type*’ to type ‘btf_member*’ casts away qualifiers [-Wcast-qual] 264 | return (struct btf_member *)(t + 1); | ^ The argument is const so the cast to following struct btf_member pointer should be const as well. Casting the const away in btf.c call where it's correctly used without const in deduplication code. Signed-off-by: Jiri Olsa --- tools/lib/bpf/btf.c | 4 ++-- tools/lib/bpf/btf.h | 4 ++-- tools/lib/bpf/libbpf.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 5a39e9506760..560d1ae33675 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -1463,7 +1463,7 @@ static int btf_for_each_str_off(struct btf_dedup *d, str_off_fn_t fn, void *ctx) switch (btf_kind(t)) { case BTF_KIND_STRUCT: case BTF_KIND_UNION: { - struct btf_member *m = btf_members(t); + struct btf_member *m = (struct btf_member *) btf_members(t); __u16 vlen = btf_vlen(t); for (j = 0; j < vlen; j++) { @@ -2797,7 +2797,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id) case BTF_KIND_STRUCT: case BTF_KIND_UNION: { - struct btf_member *member = btf_members(t); + struct btf_member *member = (struct btf_member *) btf_members(t); __u16 vlen = btf_vlen(t); for (i = 0; i < vlen; i++) { diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 3b3216fa348f..cd1bd018ba8b 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -259,9 +259,9 @@ static inline const struct btf_enum *btf_enum(const struct btf_type *t) return (const struct btf_enum *)(t + 1); } -static inline struct btf_member *btf_members(const struct btf_type *t) +static inline const struct btf_member *btf_members(const struct btf_type *t) { - return (struct btf_member *)(t + 1); + return (const struct btf_member *)(t + 1); } /* Get bit offset of a member with specified index. */ diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 2233f919dd88..7d3d6284dd2e 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1389,7 +1389,7 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj) } else if (!has_datasec && btf_is_datasec(t)) { /* replace DATASEC with STRUCT */ const struct btf_var_secinfo *v = btf_var_secinfos(t); - struct btf_member *m = btf_members(t); + struct btf_member *m = (struct btf_member *) btf_members(t); struct btf_type *vt; char *name; From patchwork Fri Sep 6 07:31:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 1158823 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46Pq4y0TwCz9s7T for ; Fri, 6 Sep 2019 17:32:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404554AbfIFHcA (ORCPT ); Fri, 6 Sep 2019 03:32:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55664 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404547AbfIFHb6 (ORCPT ); Fri, 6 Sep 2019 03:31:58 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 953C11DA5; Fri, 6 Sep 2019 07:31:58 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.205.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F9C760126; Fri, 6 Sep 2019 07:31:56 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Yonghong Song , Martin KaFai Lau Subject: [PATCH 5/7] libbpf: Return const btf_param from btf_params inline function Date: Fri, 6 Sep 2019 09:31:42 +0200 Message-Id: <20190906073144.31068-6-jolsa@kernel.org> In-Reply-To: <20190906073144.31068-1-jolsa@kernel.org> References: <20190906073144.31068-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Fri, 06 Sep 2019 07:31:58 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org I'm getting following errors when compiling with -Wcast-qual: bpf/btf.h: In function ‘btf_param* btf_params(const btf_type*)’: bpf/btf.h:291:35: warning: cast from type ‘const btf_type*’ to type ‘btf_param*’ casts away qualifiers [-Wcast-qual] 291 | return (struct btf_param *)(t + 1); | ^ The argument is const so the cast to following struct btf_param pointer should be const as well. Casting the const away in btf.c call where it's correctly used without const in deduplication code. Signed-off-by: Jiri Olsa --- tools/lib/bpf/btf.c | 6 +++--- tools/lib/bpf/btf.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 560d1ae33675..b5121c79fd9f 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -1487,7 +1487,7 @@ static int btf_for_each_str_off(struct btf_dedup *d, str_off_fn_t fn, void *ctx) break; } case BTF_KIND_FUNC_PROTO: { - struct btf_param *m = btf_params(t); + struct btf_param *m = (struct btf_param *) btf_params(t); __u16 vlen = btf_vlen(t); for (j = 0; j < vlen; j++) { @@ -2622,7 +2622,7 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id) t->type = ref_type_id; vlen = btf_vlen(t); - param = btf_params(t); + param = (struct btf_param *) btf_params(t); for (i = 0; i < vlen; i++) { ref_type_id = btf_dedup_ref_type(d, param->type); if (ref_type_id < 0) @@ -2811,7 +2811,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id) } case BTF_KIND_FUNC_PROTO: { - struct btf_param *param = btf_params(t); + struct btf_param *param = (struct btf_param *) btf_params(t); __u16 vlen = btf_vlen(t); r = btf_dedup_remap_type_id(d, t->type); diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index cd1bd018ba8b..2817cf7ce2ee 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -286,9 +286,9 @@ static inline __u32 btf_member_bitfield_size(const struct btf_type *t, return kflag ? BTF_MEMBER_BITFIELD_SIZE(m->offset) : 0; } -static inline struct btf_param *btf_params(const struct btf_type *t) +static inline const struct btf_param *btf_params(const struct btf_type *t) { - return (struct btf_param *)(t + 1); + return (const struct btf_param *)(t + 1); } static inline struct btf_var *btf_var(const struct btf_type *t) From patchwork Fri Sep 6 07:31:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 1158825 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46Pq4y6DwBz9sNT for ; Fri, 6 Sep 2019 17:32:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730485AbfIFHcB (ORCPT ); Fri, 6 Sep 2019 03:32:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40936 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404555AbfIFHcB (ORCPT ); Fri, 6 Sep 2019 03:32:01 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0CF6E307D851; Fri, 6 Sep 2019 07:32:01 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.205.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E2B3600CC; Fri, 6 Sep 2019 07:31:59 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Yonghong Song , Martin KaFai Lau Subject: [PATCH 6/7] libbpf: Return const btf_var from btf_var inline function Date: Fri, 6 Sep 2019 09:31:43 +0200 Message-Id: <20190906073144.31068-7-jolsa@kernel.org> In-Reply-To: <20190906073144.31068-1-jolsa@kernel.org> References: <20190906073144.31068-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 06 Sep 2019 07:32:01 +0000 (UTC) Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org I'm getting following errors when compiling with -Wcast-qual: bpf/btf.h: In function ‘btf_var* btf_var(const btf_type*)’: bpf/btf.h:296:33: warning: cast from type ‘const btf_type*’ to type ‘btf_var*’ casts away qualifiers [-Wcast-qual] 296 | return (struct btf_var *)(t + 1); | ^ The argument is const so the cast to following struct btf_var pointer should be const as well. Signed-off-by: Jiri Olsa --- tools/lib/bpf/btf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 2817cf7ce2ee..480dbe780fa7 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -291,9 +291,9 @@ static inline const struct btf_param *btf_params(const struct btf_type *t) return (const struct btf_param *)(t + 1); } -static inline struct btf_var *btf_var(const struct btf_type *t) +static inline const struct btf_var *btf_var(const struct btf_type *t) { - return (struct btf_var *)(t + 1); + return (const struct btf_var *)(t + 1); } static inline struct btf_var_secinfo * From patchwork Fri Sep 6 07:31:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 1158827 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46Pq514Ytnz9s7T for ; Fri, 6 Sep 2019 17:32:05 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732586AbfIFHcE (ORCPT ); Fri, 6 Sep 2019 03:32:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36284 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404555AbfIFHcD (ORCPT ); Fri, 6 Sep 2019 03:32:03 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2CB67308AA11; Fri, 6 Sep 2019 07:32:03 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.205.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59D56600CC; Fri, 6 Sep 2019 07:32:01 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Yonghong Song , Martin KaFai Lau Subject: [PATCH 7/7] libbpf: Return const struct btf_var_secinfo from btf_var_secinfos inline function Date: Fri, 6 Sep 2019 09:31:44 +0200 Message-Id: <20190906073144.31068-8-jolsa@kernel.org> In-Reply-To: <20190906073144.31068-1-jolsa@kernel.org> References: <20190906073144.31068-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 06 Sep 2019 07:32:03 +0000 (UTC) Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org I'm getting following errors when compiling with -Wcast-qual: bpf/btf.h: In function ‘btf_var_secinfo* btf_var_secinfos(const btf_type*)’: bpf/btf.h:302:41: warning: cast from type ‘const btf_type*’ to type ‘btf_var_secinfo*’ casts away qualifiers [-Wcast-qual] 302 | return (struct btf_var_secinfo *)(t + 1); | ^ The argument is const so the cast to following struct btf_var_secinfo pointer should be const as well. Casting the const away in btf.c call where it's correctly used without const in deduplication code. Signed-off-by: Jiri Olsa --- tools/lib/bpf/btf.c | 5 +++-- tools/lib/bpf/btf.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index b5121c79fd9f..32527622792d 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -526,7 +526,8 @@ static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf, t->size = size; - for (i = 0, vsi = btf_var_secinfos(t); i < vars; i++, vsi++) { + for (i = 0, vsi = (struct btf_var_secinfo *) btf_var_secinfos(t); + i < vars; i++, vsi++) { t_var = btf__type_by_id(btf, vsi->type); var = btf_var(t_var); @@ -2830,7 +2831,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id) } case BTF_KIND_DATASEC: { - struct btf_var_secinfo *var = btf_var_secinfos(t); + struct btf_var_secinfo *var = (struct btf_var_secinfo *) btf_var_secinfos(t); __u16 vlen = btf_vlen(t); for (i = 0; i < vlen; i++) { diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 480dbe780fa7..ecccde0988b1 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -296,10 +296,10 @@ static inline const struct btf_var *btf_var(const struct btf_type *t) return (const struct btf_var *)(t + 1); } -static inline struct btf_var_secinfo * +static inline const struct btf_var_secinfo * btf_var_secinfos(const struct btf_type *t) { - return (struct btf_var_secinfo *)(t + 1); + return (const struct btf_var_secinfo *)(t + 1); } #ifdef __cplusplus