Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: Zhang Chujun <zhangchujun@cmss.chinamobile.com>
Cc: dmaengine@vger.kernel.org, linux-kselftest@vger.kernel.org,
	vkoul@kernel.org, Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] dma_map_benchmark: fix incorrect array access in printf
Date: Wed, 19 Nov 2025 15:02:01 -0700	[thread overview]
Message-ID: <3da29510-0441-4abd-aaa9-bd085844876b@linuxfoundation.org> (raw)
In-Reply-To: <20251107015604.2029-1-zhangchujun@cmss.chinamobile.com>

On 11/6/25 18:55, Zhang Chujun wrote:
> 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.
> 

Applied to linux-kselftest next for Linux 6.19-rc1

thanks,
-- Shuah

      reply	other threads:[~2025-11-19 22:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-06  3:30 [PATCH] selftests/dma: fix invalid array access in printf Zhang Chujun
2025-11-07  0:24 ` Shuah Khan
2025-11-07  1:55   ` [PATCH] dma_map_benchmark: fix incorrect " Zhang Chujun
2025-11-19 22:02     ` Shuah Khan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3da29510-0441-4abd-aaa9-bd085844876b@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=vkoul@kernel.org \
    --cc=zhangchujun@cmss.chinamobile.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox