[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241031154507.GA1512215@yaz-khff2.amd.com>
Date: Thu, 31 Oct 2024 11:45:07 -0400
From: Yazen Ghannam <yazen.ghannam@....com>
To: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
Cc: "Zhuo, Qiuxu" <qiuxu.zhuo@...el.com>,
"linux-edac@...r.kernel.org" <linux-edac@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"Luck, Tony" <tony.luck@...el.com>,
"x86@...nel.org" <x86@...nel.org>,
"avadhut.naik@....com" <avadhut.naik@....com>,
"john.allen@....com" <john.allen@....com>,
"mario.limonciello@....com" <mario.limonciello@....com>,
"bhelgaas@...gle.com" <bhelgaas@...gle.com>,
"Shyam-sundar.S-k@....com" <Shyam-sundar.S-k@....com>,
"richard.gong@....com" <richard.gong@....com>,
"jdelvare@...e.com" <jdelvare@...e.com>,
"linux@...ck-us.net" <linux@...ck-us.net>,
"clemens@...isch.de" <clemens@...isch.de>,
"hdegoede@...hat.com" <hdegoede@...hat.com>,
"linux-pci@...r.kernel.org" <linux-pci@...r.kernel.org>,
"linux-hwmon@...r.kernel.org" <linux-hwmon@...r.kernel.org>,
"platform-driver-x86@...r.kernel.org" <platform-driver-x86@...r.kernel.org>,
"naveenkrishna.chatradhi@....com" <naveenkrishna.chatradhi@....com>,
"carlos.bilbao.osdev@...il.com" <carlos.bilbao.osdev@...il.com>
Subject: Re: [PATCH 06/16] x86/amd_nb: Simplify root device search
On Thu, Oct 31, 2024 at 05:42:34PM +0200, Ilpo Järvinen wrote:
> On Thu, 31 Oct 2024, Yazen Ghannam wrote:
>
> > On Thu, Oct 31, 2024 at 12:08:20PM +0200, Ilpo Järvinen wrote:
> > > On Thu, 31 Oct 2024, Zhuo, Qiuxu wrote:
> > >
> > > > > From: Yazen Ghannam <yazen.ghannam@....com>
> > > > > [...]
> > > > > +struct pci_dev *amd_node_get_root(u16 node) {
> > > > > + struct pci_dev *df_f0 __free(pci_dev_put) = NULL;
> > > >
> > > > NULL pointer initialization is not necessary.
> > >
> > > It is, because __free() is used...
> > >
> > > > > + struct pci_dev *root;
> > > > > + u16 cntl_off;
> > > > > + u8 bus;
> > > > > +
> > > > > + if (!boot_cpu_has(X86_FEATURE_ZEN))
> > > > > + return NULL;
> > >
> > > ...This would try to free() whatever garbage df_f0 holds...
> > >
> > > > > + /*
> > > > > + * D18F0xXXX [Config Address Control] (DF::CfgAddressCntl)
> > > > > + * Bits [7:0] (SecBusNum) holds the bus number of the root device for
> > > > > + * this Data Fabric instance. The segment, device, and function will be
> > > > > 0.
> > > > > + */
> > > > > + df_f0 = amd_node_get_func(node, 0);
> > >
> > > ...However, the recommended practice when using __free() is this (as
> > > documented in include/linux/cleanup.h):
> > >
> > > * Given that the "__free(...) = NULL" pattern for variables defined at
> > > * the top of the function poses this potential interdependency problem
> > > * the recommendation is to always define and assign variables in one
> > > * statement and not group variable definitions at the top of the
> > > * function when __free() is used.
> > >
> > > I know the outcome will look undesirable to some, me included, but
> > > there's little that can be done to that because there's no other way for
> > > the compiler to infer the order.
> > >
> > > That being said, strictly speaking it isn't causing issue in this function
> > > as is but it's still a bad pattern to initialize to = NULL because in
> > > other instances it will cause problems. So better to steer away from the
> > > pattern entirely rather than depend on reviewers noticing the a cleaup
> > > ordering problem gets introduced by some later change to the function.
> > >
> >
> > I originally read that in the context of using a guard(). But really we
> > should do like this in any case, correct?
> >
> > struct pci_dev *df_f0 __free(pci_dev_put) = amd_node_get_func(node, 0);
>
> Yes, that is the recommendation. It says "always" so not only the cases
> where guard() or other __free()s are used.
>
> Of course this only applies to use of __free(), other variables should
> still be declared in the usual place and not spread around.
>
Ah right. Will make the change.
Thanks,
Yazen
Powered by blists - more mailing lists