Linux CXL
 help / color / mirror / Atom feed
* [PATCH] [PATCH] cxl: trace: Fix macro safety in CXL_EVT_TP_fast_assign
@ 2025-04-21 18:45 shaikh.kamal
  2025-04-21 19:12 ` Steven Rostedt
  2025-04-23 21:52 ` Ira Weiny
  0 siblings, 2 replies; 5+ messages in thread
From: shaikh.kamal @ 2025-04-21 18:45 UTC (permalink / raw)
  To: dan.j.williams
  Cc: shaikh.kamal, Davidlohr Bueso, Jonathan Cameron, Dave Jiang,
	Alison Schofield, Vishal Verma, Ira Weiny, Shiju Jose,
	Fabio M. De Francesco, Steven Rostedt (Google), Smita Koralahalli,
	linux-cxl, linux-kernel

Fix checkpatch.pl detected error
The CXL_EVT_TP_fast_assign macro assigns multiple fields, but does not
wrap the body in a `do { ... } while (0)` block. This can lead to
unexpected behavior when used in conditional branches.

Add checks to ensure cxlmd is valid before accessing its fields.

Signed-off-by: shaikh.kamal <shaikhkamal2012@gmail.com>
---
 drivers/cxl/core/trace.h | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/cxl/core/trace.h b/drivers/cxl/core/trace.h
index 25ebfbc1616c..a1a1014ee1fe 100644
--- a/drivers/cxl/core/trace.h
+++ b/drivers/cxl/core/trace.h
@@ -249,18 +249,24 @@ TRACE_EVENT(cxl_overflow,
 	__field(u8, hdr_maint_op_class)				\
 	__field(u8, hdr_maint_op_sub_class)
 
-#define CXL_EVT_TP_fast_assign(cxlmd, l, hdr)					\
-	__assign_str(memdev);				\
-	__assign_str(host);			\
-	__entry->log = (l);							\
-	__entry->serial = (cxlmd)->cxlds->serial;				\
-	__entry->hdr_length = (hdr).length;					\
-	__entry->hdr_flags = get_unaligned_le24((hdr).flags);			\
-	__entry->hdr_handle = le16_to_cpu((hdr).handle);			\
-	__entry->hdr_related_handle = le16_to_cpu((hdr).related_handle);	\
-	__entry->hdr_timestamp = le64_to_cpu((hdr).timestamp);			\
-	__entry->hdr_maint_op_class = (hdr).maint_op_class;			\
-	__entry->hdr_maint_op_sub_class = (hdr).maint_op_sub_class
+#define CXL_EVT_TP_fast_assign(cxlmd, l, hdr) \
+	do { \
+		if (!(cxlmd)) { \
+			pr_err("Invalid arguments to CXL_EVT_TP_fast_assign\n"); \
+			break; \
+		} \
+		__assign_str(memdev); \
+		__assign_str(host); \
+		__entry->log = (l); \
+		__entry->serial = (cxlmd)->cxlds->serial; \
+		__entry->hdr_length = (hdr).length; \
+		__entry->hdr_flags = get_unaligned_le24((hdr).flags); \
+		__entry->hdr_handle = le16_to_cpu((hdr).handle); \
+		__entry->hdr_related_handle = le16_to_cpu((hdr).related_handle); \
+		__entry->hdr_timestamp = le64_to_cpu((hdr).timestamp); \
+		__entry->hdr_maint_op_class = (hdr).maint_op_class; \
+		__entry->hdr_maint_op_sub_class = (hdr).maint_op_sub_class; \
+	} while (0)
 
 #define CXL_EVT_TP_printk(fmt, ...) \
 	TP_printk("memdev=%s host=%s serial=%lld log=%s : time=%llu uuid=%pUb "	\
-- 
2.43.0


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

end of thread, other threads:[~2025-04-24 15:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-21 18:45 [PATCH] [PATCH] cxl: trace: Fix macro safety in CXL_EVT_TP_fast_assign shaikh.kamal
2025-04-21 19:12 ` Steven Rostedt
2025-04-24 15:47   ` shaikh kamaluddin
2025-04-23 21:52 ` Ira Weiny
2025-04-24 15:48   ` shaikh kamaluddin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox