All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Guo Zhengkui <guozhengkui@vivo.com>
Cc: Hector Martin <marcan@marcan.st>, Sven Peter <sven@svenpeter.dev>,
	Alyssa Rosenzweig <alyssa@rosenzweig.io>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-arm-kernel@lists.infradead.org (moderated list:ARM/APPLE
	MACHINE SUPPORT),
	linux-kernel@vger.kernel.org (open list:IRQCHIP DRIVERS),
	zhengkui_guo@outlook.com
Subject: Re: [PATCH] irqchip/apple-aic: application of sizeof() to a pointer
Date: Thu, 10 Mar 2022 08:27:24 +0000	[thread overview]
Message-ID: <87sfrqyzyr.wl-maz@kernel.org> (raw)
In-Reply-To: <20220310050238.4478-1-guozhengkui@vivo.com>

On Thu, 10 Mar 2022 05:02:38 +0000,
Guo Zhengkui <guozhengkui@vivo.com> wrote:
> 
> `ic->fiq_aff[fiq]` is a pointer to the unnamed struct.
> `sizeof(ic->fiq_aff[fiq])` intends to get the size of this pointer. But
> readers may get confused. `sizeof(unsigned long)` makes more sense because
> `unsigned long` has the same size of pointer.

More sense? It really depends on who reads the code.

> 
> reference:
> https://lore.kernel.org/all/Ya%2FeUbdN1+ABFVWf@rowland.harvard.edu/
> https://lore.kernel.org/all/YbBGGI9wQenI4kP7@kroah.com/
> https://lore.kernel.org/all/20211209062441.9856-1-guozhengkui@vivo.com/
> 
> Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
> ---
>  drivers/irqchip/irq-apple-aic.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c
> index b40199c6625e..23098b469b1a 100644
> --- a/drivers/irqchip/irq-apple-aic.c
> +++ b/drivers/irqchip/irq-apple-aic.c
> @@ -810,7 +810,7 @@ static void build_fiq_affinity(struct aic_irq_chip *ic, struct device_node *aff)
>  	if (WARN_ON(n < 0))
>  		return;
>  
> -	ic->fiq_aff[fiq] = kzalloc(sizeof(ic->fiq_aff[fiq]), GFP_KERNEL);
> +	ic->fiq_aff[fiq] = kzalloc(sizeof(unsigned long), GFP_KERNEL);

And by doing that, you are making even more difficult to spot the
glaring bug that is in front of your eyes: we're not trying to
allocate a pointer, but to allocate the full data structure.

Nothing went wrong as a 64bit allocation is plenty when you need at
most 10 bits, but jeez, what a howler. I'm stashing the fixlet below
on top.

Thanks,

	M.

diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c
index b40199c6625e..3f1d2f3ccb7f 100644
--- a/drivers/irqchip/irq-apple-aic.c
+++ b/drivers/irqchip/irq-apple-aic.c
@@ -810,7 +810,7 @@ static void build_fiq_affinity(struct aic_irq_chip *ic, struct device_node *aff)
 	if (WARN_ON(n < 0))
 		return;
 
-	ic->fiq_aff[fiq] = kzalloc(sizeof(ic->fiq_aff[fiq]), GFP_KERNEL);
+	ic->fiq_aff[fiq] = kzalloc(sizeof(*ic->fiq_aff[fiq]), GFP_KERNEL);
 	if (!ic->fiq_aff[fiq])
 		return;
 

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-03-10  8:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-10  5:02 [PATCH] irqchip/apple-aic: application of sizeof() to a pointer Guo Zhengkui
2022-03-10  8:27 ` Marc Zyngier [this message]
2022-03-10  8:48   ` Guo Zhengkui
2022-03-10  9:00     ` Marc Zyngier

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=87sfrqyzyr.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=alyssa@rosenzweig.io \
    --cc=guozhengkui@vivo.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcan@marcan.st \
    --cc=sven@svenpeter.dev \
    --cc=tglx@linutronix.de \
    --cc=zhengkui_guo@outlook.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.