From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB6E6C433EF for ; Thu, 10 Mar 2022 08:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CkJrLsMgmF+lPXowApUWBLf2QJ8pmXjody7/TDOoeag=; b=i0VpSHjemFRr55 63C34B3yiijAUUKBmDyQNwGIXZft/0APhCcleouIz2uUInC1VFMpjKC52VC3sz8klcgwA6Z5unvnQ nRvosWS9WqcgI/4DK0lCd82oD19lYDADodsZVaQkjXq3RLNYliIS+HBMClaXB/w4euuQefxGCFNRC 4PPDv4+3067T1ZckMDkkjuwq30q+6zADDMDSmLTTRwqLfwenhWld0+fBruLzG+VXcFAo6txGURWAO dYEnWYzYcxV7JH9OX21ZQptEWvO351lVG3kUNR7j8LS/nFIsaEzwmOQUdlmX6rqZ4Twq7M5sN4P02 g452W004Eg7s8qzEerig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSE8z-00Btkp-Pg; Thu, 10 Mar 2022 08:27:33 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSE8w-00Btjz-5Y for linux-arm-kernel@lists.infradead.org; Thu, 10 Mar 2022 08:27:32 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 676EDB81EA0; Thu, 10 Mar 2022 08:27:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 119F9C340E8; Thu, 10 Mar 2022 08:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646900847; bh=/9C4BIqgXx2c6sRMgvh7r/nxQcHFArxVvepmMcPWiqk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=klveAPUWwdziQvpok91nyvuHrJKz3bUdUEpKL1ioi5JsCz3/usIomklsX9E7vreru WSbfCAN3vQWXc6eQFjwPsutt/tFWL/TcPC/Sv9kCsE+RHdH48LOEMI3zdlFRROxjFo 7dQUjqOa0PtM/uvWnB2kW0aQ4OYQB1BKxDzLLZpgKgBjtWXQqZoKwmHkxvd3grYiZw ycDnu/Gj/q239TY9Ybp0slYLLjzqn8XAZcXBl67aoKIPs+KH9RFqF1K7+BX2gcePjA BvoXTsjoFg9XhI/LgdggO0VBJDfTliDh0SuS/T/4JSM8qRcSdMg0eQj2l0Ab0e4bGE l4R0JSUjOhvsg== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nSE8q-00DWXz-M8; Thu, 10 Mar 2022 08:27:24 +0000 Date: Thu, 10 Mar 2022 08:27:24 +0000 Message-ID: <87sfrqyzyr.wl-maz@kernel.org> From: Marc Zyngier To: Guo Zhengkui Cc: Hector Martin , Sven Peter , Alyssa Rosenzweig , Thomas Gleixner , 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 In-Reply-To: <20220310050238.4478-1-guozhengkui@vivo.com> References: <20220310050238.4478-1-guozhengkui@vivo.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: guozhengkui@vivo.com, marcan@marcan.st, sven@svenpeter.dev, alyssa@rosenzweig.io, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, zhengkui_guo@outlook.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220310_002730_534648_112FE147 X-CRM114-Status: GOOD ( 24.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 10 Mar 2022 05:02:38 +0000, Guo Zhengkui 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 > --- > 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