sparclinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Thorsten Blum <thorsten.blum@linux.dev>,
	"David S. Miller" <davem@davemloft.net>,
	Andreas Larsson <andreas@gaisler.com>,
	Sam Ravnborg <sam@ravnborg.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>, Arnd Bergmann <arnd@arndb.de>
Cc: linux-hardening@vger.kernel.org, sparclinux@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sparc: Replace one-element array with flexible array member
Date: Mon, 11 Nov 2024 14:20:12 -0600	[thread overview]
Message-ID: <83a95dfe-533b-468c-8dd4-439157c0e1cf@embeddedor.com> (raw)
In-Reply-To: <20241111200155.164621-3-thorsten.blum@linux.dev>



On 11/11/24 14:01, Thorsten Blum wrote:
> Replace the deprecated one-element array with a modern flexible array
> member in the struct hvtramp_descr.
> 
> Additionally, 15 unnecessary bytes are allocated for hdesc, but instead

15? unnecessary?

> of fixing the parentheses in the open-coded version, use struct_size()
> to calculate the correct number of bytes.
> 
> Link: https://github.com/KSPP/linux/issues/79
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>   arch/sparc/include/asm/hvtramp.h | 2 +-
>   arch/sparc/kernel/smp_64.c       | 4 +---
>   2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/sparc/include/asm/hvtramp.h b/arch/sparc/include/asm/hvtramp.h
> index 688ea43af0f5..ce2453ea4f2b 100644
> --- a/arch/sparc/include/asm/hvtramp.h
> +++ b/arch/sparc/include/asm/hvtramp.h
> @@ -17,7 +17,7 @@ struct hvtramp_descr {
>   	__u64			fault_info_va;
>   	__u64			fault_info_pa;
>   	__u64			thread_reg;
> -	struct hvtramp_mapping	maps[1];
> +	struct hvtramp_mapping	maps[];
>   };

It seems this struct is a candidate for `__counted_by()`

>   
>   void hv_cpu_startup(unsigned long hvdescr_pa);
> diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
> index e40c395db202..24d980220bf1 100644
> --- a/arch/sparc/kernel/smp_64.c
> +++ b/arch/sparc/kernel/smp_64.c
> @@ -297,9 +297,7 @@ static void ldom_startcpu_cpuid(unsigned int cpu, unsigned long thread_reg,
>   	unsigned long hv_err;
>   	int i;
>   
> -	hdesc = kzalloc(sizeof(*hdesc) +
> -			(sizeof(struct hvtramp_mapping) *
> -			 num_kernel_image_mappings - 1),
> +	hdesc = kzalloc(struct_size(hdesc, maps, num_kernel_image_mappings - 1),
>   			GFP_KERNEL);

Now the code is broken because it's allocating `num_kernel_image_mappings - 1`
elements instead of `num_kernel_image_mappings`.

--
Gustavo

  reply	other threads:[~2024-11-11 20:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-11 20:01 [PATCH] sparc: Replace one-element array with flexible array member Thorsten Blum
2024-11-11 20:20 ` Gustavo A. R. Silva [this message]
2024-11-11 20:45   ` Thorsten Blum
2024-11-11 21:03     ` Gustavo A. R. Silva

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=83a95dfe-533b-468c-8dd4-439157c0e1cf@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=andreas@gaisler.com \
    --cc=arnd@arndb.de \
    --cc=davem@davemloft.net \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=sam@ravnborg.org \
    --cc=sparclinux@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=thorsten.blum@linux.dev \
    /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;
as well as URLs for NNTP newsgroup(s).