Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3037126pxb; Tue, 19 Jan 2021 12:02:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5OakxeCij2ZDdk9Do9cLsIbC7MuvzoGm5BDwh+ryBNA0ndt36l3hGLv77XrDlL7D6gO9B X-Received: by 2002:aa7:dd12:: with SMTP id i18mr3850864edv.36.1611086557299; Tue, 19 Jan 2021 12:02:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611086557; cv=none; d=google.com; s=arc-20160816; b=NzIgfMpOAYxGeHA8fwf6XJHKxFo4zCg3qXnIfdLLnRIgHE9KWUMaq2Fy/jDqX8Nma7 xReiS42KFISQqfPEKqwFGNdjo5TfdfHachZ+5M4v2Z/IzhDcyDp9QLmJhRXIJzcOXCWA dKfL2TgC5OEb/CSizFOJo7X/G1CvKd42lmfdcL+ef64fNf+UHS3bxrjv8fmywLD+7IjK 1YqAscGJvHTE6VSry8+CIastsAsy9Hdx2RXuMpPw8reTCsUMqe0rgtU/GN8al/A/DecM EvcNBu3zrF/h5wdTQ9xOMVAQhWuflhqY5ESEKzVCGIj9rVR6Pcy2Qrc/qPlKjEJpl01Z 403w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=ycCbBsQp5MgBLz/9+aM9SsC+P+lo0PhYDumfXCgVhG4=; b=gIwSsysyqN5aGjfBD+rAH+qsDhzpftdOQ1JASzOMSgqZMCICwdTxjv/PqS4Lb6eFK7 kGfJAZRNQ0TNZ3YKBuE5E7lgiONI8aVurqiuynGxSh1J3V5OXFox3z+a6JlJDACH8NLA I/6mAXaxzBsEq/8qIsE8/c71qRpfUyqbJrBFX8KiRB6JT6oCRNq19/TBYmV6adPjvy8j U1Xm0jIEp/W+ST7iM8Rc+GnoodjblESHC0ZhQqbMTDOh/VQNGyknpPdo2eIiinQEmuuC DUKQD0JVLOi7ceAQiVH2w3V8RKYpb+CQa8flQcSvinKcSxngLlDPQDj8XDrlFHKTGZ/2 yqBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qzNO8wNv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt2si7515190edb.89.2021.01.19.12.02.13; Tue, 19 Jan 2021 12:02:37 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qzNO8wNv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729688AbhASUB3 (ORCPT + 99 others); Tue, 19 Jan 2021 15:01:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:50976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729442AbhASTt3 (ORCPT ); Tue, 19 Jan 2021 14:49:29 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5D00E23138; Tue, 19 Jan 2021 19:48:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611085727; bh=x2G3h6gWeJttkZWzD3p/ebQvL5B00vXITXYElAWBRd4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qzNO8wNvaKloH3Wx57QRIH5z5O9G4ae3PQD05C5mUdINm758bne2s2m7JJ60TflI1 Yn+lE6M18hrs3tT4DrmpYJXji8mnqWFPQJI3IUB+pT+gOF5E/e0aE831rVwlgs1Anh 4x8LNxssHMvdFnt0eQun92kuDtY2yFXjLXo7L8yuY5rhHKcI1bCrB0V1Z3lYq+OTyP TmyG+W6ZO4TsINNhBF5ZIhplfB3S3uFcICTnhF+kmMKTlPR9nUX75GLD8wLHwKoFX/ p4N/Ryjhi2PdGxOccfQ03SCxNqbodG/PQXK2qswpZfc/XsCX+sjddhwRoxu7HxKxmQ djbE0QpoUx73g== Date: Tue, 19 Jan 2021 11:48:46 -0800 From: Jakub Kicinski To: Andrew Lunn , Alexander Lobakin Cc: "David S. Miller" , 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: <20210119114846.20b844b2@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: References: <20210116161246.67075-1-alobakin@pm.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 19 Jan 2021 16:21:35 +0100 Andrew Lunn wrote: > 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: > >=20 > > 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 =E2=80=98phy_device_release= =E2=80=99: > > ./include/linux/kernel.h:693:8: warning: declaration of =E2=80=98__mptr= =E2=80=99 shadows a previous local [-Wshadow] > > 693 | void *__mptr =3D (void *)(ptr); \ > > | ^~~~~~ > > ./include/linux/phy.h:647:26: note: in expansion of macro =E2=80=98cont= ainer_of=E2=80=99 > > 647 | #define to_phy_device(d) container_of(to_mdio_device(d), \ > > | ^~~~~~~~~~~~ > > ./include/linux/mdio.h:52:27: note: in expansion of macro =E2=80=98cont= ainer_of=E2=80=99 > > 52 | #define to_mdio_device(d) container_of(d, struct mdio_device, d= ev) > > | ^~~~~~~~~~~~ > > ./include/linux/phy.h:647:39: note: in expansion of macro =E2=80=98to_m= dio_device=E2=80=99 > > 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 =E2=80= =98to_phy_device=E2=80=99 > > 217 | kfree(to_phy_device(dev)); > > | ^~~~~~~~~~~~~ > > ./include/linux/kernel.h:693:8: note: shadowed declaration is here > > 693 | void *__mptr =3D (void *)(ptr); \ > > | ^~~~~~ > > ./include/linux/phy.h:647:26: note: in expansion of macro =E2=80=98cont= ainer_of=E2=80=99 > > 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 =E2=80= =98to_phy_device=E2=80=99 > > 217 | kfree(to_phy_device(dev)); > > | ^~~~~~~~~~~~~ > >=20 > > As they are declared in header files, these warnings are highly > > repetitive and very annoying (along with the one from linux/pci.h). > >=20 > > 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. > >=20 > > Signed-off-by: Alexander Lobakin =20 >=20 > Reviewed-by: Andrew Lunn Applied, thanks!