]> Gentwo Git Trees - linux/.git/commit
iommu/vt-d: Replace snprintf with scnprintf in dmar_latency_snapshot()
authorSeyediman Seyedarab <ImanDevel@gmail.com>
Thu, 18 Sep 2025 05:01:58 +0000 (13:01 +0800)
committerJoerg Roedel <joerg.roedel@amd.com>
Fri, 19 Sep 2025 07:43:19 +0000 (09:43 +0200)
commit75c02a037609f34db17e91be195cedb33b61bae0
treed75e5581fa83275576f4bbabc24f8e024a00f9fd
parent1b237f190eb3d36f52dffe07a40b5eb210280e00
iommu/vt-d: Replace snprintf with scnprintf in dmar_latency_snapshot()

snprintf() returns the number of bytes that would have been written, not
the number actually written. Using this for offset tracking can cause
buffer overruns if truncation occurs.

Replace snprintf() with scnprintf() to ensure the offset stays within
bounds.

Since scnprintf() never returns a negative value, and zero is not possible
in this context because 'bytes' starts at 0 and 'size - bytes' is
DEBUG_BUFFER_SIZE in the first call, which is large enough to hold the
string literals used, the return value is always positive. An integer
overflow is also completely out of reach here due to the small and fixed
buffer size. The error check in latency_show_one() is therefore
unnecessary. Remove it and make dmar_latency_snapshot() return void.

Signed-off-by: Seyediman Seyedarab <ImanDevel@gmail.com>
Link: https://lore.kernel.org/r/20250731225048.131364-1-ImanDevel@gmail.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
drivers/iommu/intel/debugfs.c
drivers/iommu/intel/perf.c
drivers/iommu/intel/perf.h