From: David Hildenbrand <david@redhat.com>
To: davidcomponentone@gmail.com, akpm@linux-foundation.org
Cc: shuah@kernel.org, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Zeal Robot <zealci@zte.com.cn>
Subject: Re: [PATCH] Fix application of sizeof to pointer
Date: Tue, 12 Oct 2021 09:01:29 +0200 [thread overview]
Message-ID: <3ee52f17-0357-a99a-352e-424bfcc07f27@redhat.com> (raw)
In-Reply-To: <20211012030116.184027-1-davidcomponentone@gmail.com>
On 12.10.21 05:01, davidcomponentone@gmail.com wrote:
> From: David Yang <davidcomponentone@gmail.com>
>
> The coccinelle check report:
> "./tools/testing/selftests/vm/split_huge_page_test.c:344:36-42:
> ERROR: application of sizeof to pointer"
> Using the "strlen" to fix it.
>
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: David Yang <davidcomponentone@gmail.com>
> ---
> tools/testing/selftests/vm/split_huge_page_test.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/vm/split_huge_page_test.c b/tools/testing/selftests/vm/split_huge_page_test.c
> index 1af16d2c2a0a..52497b7b9f1d 100644
> --- a/tools/testing/selftests/vm/split_huge_page_test.c
> +++ b/tools/testing/selftests/vm/split_huge_page_test.c
> @@ -341,7 +341,7 @@ void split_file_backed_thp(void)
> }
>
> /* write something to the file, so a file-backed THP can be allocated */
> - num_written = write(fd, tmpfs_loc, sizeof(tmpfs_loc));
> + num_written = write(fd, tmpfs_loc, strlen(tmpfs_loc) + 1);
> close(fd);
>
> if (num_written < 1) {
>
I think the code really just wants to write anything to the file that
will be >= 1, which is also the case with this weird usage of sizeof.
As an alternative, I think we can just write anything else to the file
num_written = write(fd, (void *)&fd, sizeof(fd));
or
num_written = write(fd, "1", 1);
If I am not wrong/
--
Thanks,
David / dhildenb
prev parent reply other threads:[~2021-10-12 7:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-12 3:01 davidcomponentone
2021-10-12 7:01 ` David Hildenbrand [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=3ee52f17-0357-a99a-352e-424bfcc07f27@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=davidcomponentone@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shuah@kernel.org \
--cc=zealci@zte.com.cn \
/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