Skip to content
/ linux Public

Commit 62b650c

Browse files
k1832Sasha Levin
authored andcommitted
scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale() trace event
[ Upstream commit 9672ed3 ] The ufs_mtk_clk_scale() trace event currently stores the address of the name string directly via __field(const char *, name). This pointer may become invalid after the module is unloaded, causing page faults when the trace buffer is subsequently accessed. This can occur because the MediaTek UFS driver can be configured as a loadable module (tristate in Kconfig), meaning the name string passed to the trace event may reside in module memory that becomes invalid after module unload. Fix this by using __string() and __assign_str() to copy the string contents into the ring buffer instead of storing the pointer. This ensures the trace data remains valid regardless of module state. This change increases the memory usage for each ftrace entry by a few bytes (clock names are typically 7-15 characters like "ufs_sel" or "ufs_sel_max_src") compared to storing an 8-byte pointer. Note that this change does not affect anything unless all of the following conditions are met: - CONFIG_SCSI_UFS_MEDIATEK is enabled - ftrace tracing is enabled - The ufs_mtk_clk_scale event is enabled in ftrace Signed-off-by: Keita Morisaki <keita.morisaki@tier4.jp> Reviewed-by: Peter Wang <peter.wang@mediatek.com> Link: https://patch.msgid.link/20260202024526.122515-1-keita.morisaki@tier4.jp Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 25c429d commit 62b650c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/ufs/host/ufs-mediatek-trace.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ TRACE_EVENT(ufs_mtk_clk_scale,
3333
TP_ARGS(name, scale_up, clk_rate),
3434

3535
TP_STRUCT__entry(
36-
__field(const char*, name)
36+
__string(name, name)
3737
__field(bool, scale_up)
3838
__field(unsigned long, clk_rate)
3939
),
4040

4141
TP_fast_assign(
42-
__entry->name = name;
42+
__assign_str(name);
4343
__entry->scale_up = scale_up;
4444
__entry->clk_rate = clk_rate;
4545
),
4646

4747
TP_printk("ufs: clk (%s) scaled %s @ %lu",
48-
__entry->name,
48+
__get_str(name),
4949
__entry->scale_up ? "up" : "down",
5050
__entry->clk_rate)
5151
);

0 commit comments

Comments
 (0)