The printf statement attempts to print the DMA direction string using the syntax 'dir[directions]', which is an invalid array access. The variable 'dir' is an integer, and 'directions' is a char pointer array. This incorrect syntax should be 'directions[dir]', using 'dir' as the index into the 'directions' array. Fix this by correcting the array access from 'dir[directions]' to 'directions[dir]'.
Signed-off-by: Zhang Chujun zhangchujun@cmss.chinamobile.com
diff --git a/tools/testing/selftests/dma/dma_map_benchmark.c b/tools/testing/selftests/dma/dma_map_benchmark.c index b12f1f9babf8..b925756373ce 100644 --- a/tools/testing/selftests/dma/dma_map_benchmark.c +++ b/tools/testing/selftests/dma/dma_map_benchmark.c @@ -118,7 +118,7 @@ int main(int argc, char **argv) }
printf("dma mapping benchmark: threads:%d seconds:%d node:%d dir:%s granule: %d\n", - threads, seconds, node, dir[directions], granule); + threads, seconds, node, directions[dir], granule); printf("average map latency(us):%.1f standard deviation:%.1f\n", map.avg_map_100ns/10.0, map.map_stddev/10.0); printf("average unmap latency(us):%.1f standard deviation:%.1f\n",
On 11/5/25 20:30, Zhang Chujun wrote:
The printf statement attempts to print the DMA direction string using the syntax 'dir[directions]', which is an invalid array access. The variable 'dir' is an integer, and 'directions' is a char pointer array. This incorrect syntax should be 'directions[dir]', using 'dir' as the index into the 'directions' array. Fix this by correcting the array access from 'dir[directions]' to 'directions[dir]'.
Signed-off-by: Zhang Chujun zhangchujun@cmss.chinamobile.com
diff --git a/tools/testing/selftests/dma/dma_map_benchmark.c b/tools/testing/selftests/dma/dma_map_benchmark.c index b12f1f9babf8..b925756373ce 100644 --- a/tools/testing/selftests/dma/dma_map_benchmark.c +++ b/tools/testing/selftests/dma/dma_map_benchmark.c @@ -118,7 +118,7 @@ int main(int argc, char **argv) } printf("dma mapping benchmark: threads:%d seconds:%d node:%d dir:%s granule: %d\n",
threads, seconds, node, dir[directions], granule);
printf("average map latency(us):%.1f standard deviation:%.1f\n", map.avg_map_100ns/10.0, map.map_stddev/10.0); printf("average unmap latency(us):%.1f standard deviation:%.1f\n",threads, seconds, node, directions[dir], granule);
Looks like you sent the same patch again. I replied to your previous patch asking you how you found this problem. It looks like a needed change. Compiler doesn't complain about it which is strange.
thanks, -- Shuah
On Tue, Nov 05, 2025 at 08:30:00PM +0800, Zhang Chujun wrote:
The printf statement attempts to print the DMA direction string using the syntax 'dir[directions]', which is an invalid array access. The variable 'dir' is an integer, and 'directions' is a char pointer array. This incorrect syntax should be 'directions[dir]', using 'dir' as the index into the 'directions' array. Fix this by correcting the array access from 'dir[directions]' to 'directions[dir]'.
Hi Shuah,
Thanks for your patience.
I found this issue while carefully reading the code in `dma_map_benchmark.c`. The expression `dir[directions]` stood out because `dir` is an integer (enum or int), while `directions` is a string array ��� so using `dir` as the index into `directions` is the correct form. Although C allows `a[b]` and `b[a]` syntactically due to pointer arithmetic, in this context `dir[directions]` is logically wrong and would print an unexpected (likely garbage) string, since it treats the address of the string array as an array indexed by a small integer.
The compiler doesn���t warn because `dir[directions]` is technically valid C (equivalent to `*(directions + dir)`), but semantically it���s backwards and breaks the intended output.
Sorry for sending the patch twice, I���ll make sure to follow the proper mailing list guidelines going forward.
Best regards, Zhang Chujun
linux-kselftest-mirror@lists.linaro.org