Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1934540pxp; Thu, 10 Mar 2022 15:26:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxn9W/VRP7PnzGlwYFcg+M96g0Rwe5M8d0Xxv1LlkrbWOYwB7aUWjOb466z86bZXWmCyI3U X-Received: by 2002:a17:907:6d23:b0:6d9:ac9d:222 with SMTP id sa35-20020a1709076d2300b006d9ac9d0222mr6679287ejc.595.1646954792592; Thu, 10 Mar 2022 15:26:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646954792; cv=none; d=google.com; s=arc-20160816; b=DN4Cjbh2U58LR+UxEc6iqDQ6FzO8gXuZscuiUcpC5KD/2e/dD84WAPlW0Ij7noJlO7 etjOC5Ofrzn+4oonJKtyMWTqiZyUsZ3qtOLCwr69RQAJIb3ZNBnemZsHSmprBau3u4TI ta46/iDArBsOIRAfJKM/8k3aKv0mHwhKWX8vVrW8KsoE11eYXiPVzcFKXzF3VeUzU4Bg O16prklKyH1YJ7XbjjurDQDqOXKN13TkihIbMJzrVYnQVD9iUH2aHsHMQlZIZWOWEHCd pOf8eZEPj/D6tXATMCrewjDgwOrzO9QvhRzq3hKNdW0y7+jSg6yd5NNrtN+GDppI02Vk 2xsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=DNOSyhkHXfgzoEe2/c8hFtpGMKpQzriIq1yRDqeFoGs=; b=N+mod9olKWR0HBW+JauruTw2yKULb18meKP/cZTgLVKUCdlrNzzq9vWLMTcAh7ygI8 Y7ew5JoysmHbY/Bzpqrj/S1fT9WqvWNKsimY4Ic7j0IcpOYKEB34oEj0I5mh1M9Kx2r6 dZYDMVUFdK1QrjNZ9At1xivbQxtKUqapfhlIfbhKitVs4h+eje+PC0ARgKzcPz3KVzhj 4zzI6SkQElPRh04/+eA8RHPbGTpW2CuM9gP4QFDPGk1eiZ3B9yJF0+IIuUT/hrRDg0cK dDz3Z8/6Gn0WgC0wjahglnoyNCB4/hvvfIo09m/qXDiuIqt4phS8GD2GQLcMVmuBBINM Kg3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Do5yGtd1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa28-20020a1709076d1c00b006da68fb6595si4507218ejc.542.2022.03.10.15.26.10; Thu, 10 Mar 2022 15:26:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Do5yGtd1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240544AbiCJJCB (ORCPT + 99 others); Thu, 10 Mar 2022 04:02:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbiCJJCA (ORCPT ); Thu, 10 Mar 2022 04:02:00 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E85CF8BA3 for ; Thu, 10 Mar 2022 01:01:00 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 0D1BB61BE7 for ; Thu, 10 Mar 2022 09:01:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 730DBC340E8; Thu, 10 Mar 2022 09:00:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646902859; bh=IOzytD6gUTJGKdB6MM8m0HZeo4aGPw0Sww5Drf5mH0U=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Do5yGtd1FKYeZJwiwR9npGgS+HFeXi0INUaxHUx+g0sZZ9wPqC+KScm7FnPrCIwB5 MiAMfq6po0qTPDRgsUpC0uY8QD1902DLzK4YnYoUgXQBzmlGLBkhQEa7gH4Q43t/R3 FsYeeqEXoRwsBQyubmk4iui8yqK3mjHU3EkG6X9aroyIN9KxbnR4rLUe1w72bCJzQa 5C42/qtdMGPJg97b/iH1kWoXIx7jGKcQRdMU3cs9GaYYFIbOOVpE3AH1Pgg8cKuJoa E28WRnT6/7ODTPY2bDBZL1mad/0M2mVAs+lSi4NbCEP3JnFzncfYhApO1h/Am2/MOs XBaJohCEzx7vw== 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 1nSEfJ-00DWvj-1z; Thu, 10 Mar 2022 09:00:57 +0000 Date: Thu, 10 Mar 2022 09:00:56 +0000 Message-ID: <87pmmuyyev.wl-maz@kernel.org> From: Marc Zyngier To: Guo Zhengkui Cc: Hector Martin , Sven Peter , Alyssa Rosenzweig , Thomas Gleixner , "moderated list:ARM/APPLE MACHINE SUPPORT" , "open list:IRQCHIP DRIVERS" , "zhengkui_guo@outlook.com" Subject: Re: [PATCH] irqchip/apple-aic: application of sizeof() to a pointer In-Reply-To: References: <20220310050238.4478-1-guozhengkui@vivo.com> <87sfrqyzyr.wl-maz@kernel.org> 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") Content-Type: text/plain; charset=US-ASCII 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-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 10 Mar 2022 08:48:07 +0000, Guo Zhengkui wrote: > > On 2022/3/10 16:27, Marc Zyngier wrote: > > 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. > > > > Oh, I surely made a big mistake... Big mistake? No. You patch didn't change the behaviour of the code. But in the future, you want to pay more attention to what the author is trying to achieve: how is the data used, for example. Blindly generalising an advice given out of context often leads to bad patches. > > > 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. > > > > So, will you send this new patch by yourself? I've directly applied it[1]. Thanks, M. [1] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/commit/?h=irq/irqchip-next&id=dc29812dbc873ae00bf19a4b8661984d7cce7a2e -- Without deviation from the norm, progress is not possible.