From: Naman Jain <namjain@linux.microsoft.com>
To: Markus Elfring <Markus.Elfring@web.de>,
linux-hyperv@vger.kernel.org, x86@kernel.org,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Dexuan Cui <decui@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
"K. Y. Srinivasan" <kys@microsoft.com>,
Long Li <longli@microsoft.com>,
Mukesh Rathor <mrathor@linux.microsoft.com>,
Thomas Gleixner <tglx@linutronix.de>,
Wei Liu <wei.liu@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org,
Miaoqian Lin <linmq006@gmail.com>
Subject: Re: [PATCH] x86/hyperv: Use pointer from memcpy() call for assignment in hv_crash_setup_trampdata()
Date: Fri, 31 Oct 2025 18:02:22 +0530 [thread overview]
Message-ID: <33545bb5-6307-413c-b692-e7bebce58edb@linux.microsoft.com> (raw)
In-Reply-To: <17da2cdc-7fdd-43d1-91d5-36425615588a@web.de>
On 10/31/2025 3:14 PM, Markus Elfring wrote:
> …>> +++ b/arch/x86/hyperv/hv_crash.c
>>> @@ -464,9 +464,7 @@ static int hv_crash_setup_trampdata(u64 trampoline_va)
>>> return -1;
>>> }
>>> - dest = (void *)trampoline_va;
>>> - memcpy(dest, &hv_crash_asm32, size);
>>> -
>>> + dest = memcpy((void *)trampoline_va, &hv_crash_asm32, size);
>>> dest += size;
>>> dest = (void *)round_up((ulong)dest, 16);
>>> tramp = (struct hv_crash_tramp_data *)dest;
>>
>>
>> I tried running spatch Coccinelle checks on this file, but could not get it to flag this improvement.
>
> The proposed source code transformation is not supported by a coccicheck script so far.
>
>
>> Do you mind sharing more details on the issue reproduction please.
>
> Would you like to take another look at corresponding development discussions?
>
> Example:
> [RFC] Increasing usage of direct pointer assignments from memcpy() calls with SmPL?
> https://lore.kernel.org/cocci/ddc8654a-9505-451f-87ad-075bfa646381@web.de/
> https://sympa.inria.fr/sympa/arc/cocci/2025-10/msg00049.html
>
>
>> I am OK with this change,
>
> Thanks for a bit of positive feedback.
>
>
>> though it may cost code readability a little bit.
>
> Would you complain about other variable assignments in such a direction?
>
> Regards,
> Markus
The only thing which concerns readability IMO is that it is based on the
assumption that the person reading the code is aware of the return value
of memcpy. Now, it is debatable if that is something which can be
considered trivial. I don't have a strong opinion there, but would
prefer it in its current form.
Also, we could have optimized it further by writing it as below, but we
are not doing that for a reason as we want to keep the code simpler to
read and understand. The same may apply here as well.
dest = memcpy((void *)trampoline_va, &hv_crash_asm32, size) + size;
Regards,
Naman
next prev parent reply other threads:[~2025-10-31 12:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-31 8:33 [PATCH] x86/hyperv: Use pointer from memcpy() call for assignment in hv_crash_setup_trampdata() Markus Elfring
2025-10-31 9:28 ` Naman Jain
2025-10-31 9:37 ` Julia Lawall
2025-10-31 9:44 ` Markus Elfring
2025-10-31 12:32 ` Naman Jain [this message]
2025-10-31 18:26 ` Wei Liu
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=33545bb5-6307-413c-b692-e7bebce58edb@linux.microsoft.com \
--to=namjain@linux.microsoft.com \
--cc=Markus.Elfring@web.de \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=hpa@zytor.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kys@microsoft.com \
--cc=linmq006@gmail.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longli@microsoft.com \
--cc=mingo@redhat.com \
--cc=mrathor@linux.microsoft.com \
--cc=tglx@linutronix.de \
--cc=wei.liu@kernel.org \
--cc=x86@kernel.org \
/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