Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2842792pxb; Tue, 19 Jan 2021 07:26:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwZj+83o0cdCw8kfCPvcXqq+66l0+836KYDY262qxSquyMfmAwl5FXvUQ7+hEBjhuAUoZj X-Received: by 2002:a05:6402:3487:: with SMTP id v7mr3927964edc.68.1611069970769; Tue, 19 Jan 2021 07:26:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611069970; cv=none; d=google.com; s=arc-20160816; b=RZxiQWC4v5tlfMPOh/O5zB3eZxUJdv9P1kWnm44R2pWCfGa9hsxwrcjU1KeNJKM9fW L/Ns/idAuYksERyf6O9PB89vPoFpNAadvUbVAWhDf35iTlZRn6TzabS3ar/+HJlsedXo TWsCXntOVWRVDD6CSbSTt9vL21FJb0WaXLeGRkXqOPXZf5ZTD54AJ2TpaVmiEAElTwGs dTs1nzDXWPFDsyiuyGi91taxPGV/BsTxU3mjArf2aIv9Al+SqLyf/k9XoqfDmM2UWlt4 b6Prle7TMkQspokudoIyEHDMzFFzNpAi+s3COo8Md8JeGpZtb7SETtExGMnnDOwzHpfT 7zEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=qD7VHWhJTuSCDBtjo/463roPkbJHzTXLh066FsEomBs=; b=v+gv7qOVo0weZSA/hdVahxxZrKvELt81k/RQX08KmjKU7x1dkKB5Wdam59+6GCy8ZL 5Ufl0nV8WpDSvrjrWr4un25e2SFx1TRHhgSx1nocFXalPqH7DgT8r6shtL1ga+MbezoT yMixKiEQvwCF5c7JRNe8CrBbOtuPTGo91GoKobkC62QL3x0l1q5GHIKFdPto2UizRjT7 w3AmR692yvINLI1TSQjBXesY4a3pVcvHph+eWuu21EPL6CwItOQVkDL4Yh7tcfNceBS+ txSSO25gXvoUxWSCSYHYpd1iuHyZTWG3wzFIxFXEOPGxDir0h91R11imRK8Ag5NlVnIq XOYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm7si3766301ejc.558.2021.01.19.07.25.46; Tue, 19 Jan 2021 07:26:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391443AbhASPX3 (ORCPT + 99 others); Tue, 19 Jan 2021 10:23:29 -0500 Received: from vps0.lunn.ch ([185.16.172.187]:47896 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391314AbhASPW0 (ORCPT ); Tue, 19 Jan 2021 10:22:26 -0500 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1l1sp5-001T0o-6c; Tue, 19 Jan 2021 16:21:35 +0100 Date: Tue, 19 Jan 2021 16:21:35 +0100 From: Andrew Lunn To: Alexander Lobakin Cc: "David S. Miller" , Jakub Kicinski , Heiner Kallweit , Russell King , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] mdio, phy: fix -Wshadow warnings triggered by nested container_of() Message-ID: References: <20210116161246.67075-1-alobakin@pm.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210116161246.67075-1-alobakin@pm.me> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 16, 2021 at 04:13:22PM +0000, Alexander Lobakin wrote: > container_of() macro hides a local variable '__mptr' inside. This > becomes a problem when several container_of() are nested in each > other within single line or plain macros. > As C preprocessor doesn't support generating random variable names, > the sole solution is to avoid defining macros that consist only of > container_of() calls, or they will self-shadow '__mptr' each time: > > In file included from ./include/linux/bitmap.h:10, > from drivers/net/phy/phy_device.c:12: > drivers/net/phy/phy_device.c: In function ‘phy_device_release’: > ./include/linux/kernel.h:693:8: warning: declaration of ‘__mptr’ shadows a previous local [-Wshadow] > 693 | void *__mptr = (void *)(ptr); \ > | ^~~~~~ > ./include/linux/phy.h:647:26: note: in expansion of macro ‘container_of’ > 647 | #define to_phy_device(d) container_of(to_mdio_device(d), \ > | ^~~~~~~~~~~~ > ./include/linux/mdio.h:52:27: note: in expansion of macro ‘container_of’ > 52 | #define to_mdio_device(d) container_of(d, struct mdio_device, dev) > | ^~~~~~~~~~~~ > ./include/linux/phy.h:647:39: note: in expansion of macro ‘to_mdio_device’ > 647 | #define to_phy_device(d) container_of(to_mdio_device(d), \ > | ^~~~~~~~~~~~~~ > drivers/net/phy/phy_device.c:217:8: note: in expansion of macro ‘to_phy_device’ > 217 | kfree(to_phy_device(dev)); > | ^~~~~~~~~~~~~ > ./include/linux/kernel.h:693:8: note: shadowed declaration is here > 693 | void *__mptr = (void *)(ptr); \ > | ^~~~~~ > ./include/linux/phy.h:647:26: note: in expansion of macro ‘container_of’ > 647 | #define to_phy_device(d) container_of(to_mdio_device(d), \ > | ^~~~~~~~~~~~ > drivers/net/phy/phy_device.c:217:8: note: in expansion of macro ‘to_phy_device’ > 217 | kfree(to_phy_device(dev)); > | ^~~~~~~~~~~~~ > > As they are declared in header files, these warnings are highly > repetitive and very annoying (along with the one from linux/pci.h). > > Convert the related macros from linux/{mdio,phy}.h to static inlines > to avoid self-shadowing and potentially improve bug-catching. > No functional changes implied. > > Signed-off-by: Alexander Lobakin Reviewed-by: Andrew Lunn Andrew