Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/25/22 02:23, Christoph Hellwig wrote:
On Fri, Jun 24, 2022 at 12:57:56PM -0700, Bart Van Assche wrote:
BTW, I discovered the code in the tracing infrastructure
that makes sparse unhappy:

#define is_signed_type(type) (((type)(-1)) < (type)1)

Sparse reports four warnings for that expression if 'type' is a bitwise
type. Two of these warnings can be suppressed by changing 'type' into
'__force type'. I have not yet found a way to suppress all the sparse
warnings triggered by the is_signed_type() macro for bitwise types.

Yeah, that is a bit of a mess.  Rasmus, Steven - any good idea how
we can make the trace even macros fit for sparse?  Maybe just drop the
is_signed_type check for __CHECKER__ ?

How about the patch below?


Subject: [PATCH] tracing: Suppress sparse warnings triggered by
 is_signed_type()

Using a __bitwise type in a tracing __field() definition triggers four
sparse warnings in stage 4 of expanding the TRACE_EVENT() macro. These
warnings are triggered by the is_signed_type() macro implementation.
Since there is no known way of checking signedness of a bitwise type
without triggering sparse warnings, disable signedness checking when
verifying code with sparse.

Suggested-by: Christoph Hellwig <hch@xxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
Cc: Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>
Cc: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
---
 include/linux/trace_events.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index e6e95a9f07a5..f7b2a5467361 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -814,7 +814,19 @@ extern int trace_add_event_call(struct trace_event_call *call);
 extern int trace_remove_event_call(struct trace_event_call *call);
 extern int trace_event_get_offsets(struct trace_event_call *call);

+/*
+ * There is no known way to check signedness of __bitwise types without
+ * triggering a sparse warning. Hence the #ifdef __CHECKER__.
+ *
+ * There is another definition of is_signed_type() in <linux/overflow.h>.
+ * Hence undefine is_signed_type() before redefining it.
+ */
+#undef is_signed_type
+#ifdef __CHECKER__
+#define is_signed_type(type)	0
+#else
 #define is_signed_type(type)	(((type)(-1)) < (type)1)
+#endif

 int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
 int trace_set_clr_event(const char *system, const char *event, int set);



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux