[PATCH 09/13] cpufreq: acpi-cpufreq: Remove unused ID structs

Lee Jones lee.jones at linaro.org
Wed Jul 15 08:07:42 EDT 2020


On Wed, 15 Jul 2020, Lee Jones wrote:

> On Wed, 15 Jul 2020, Rafael J. Wysocki wrote:
> 
> > On Wed, Jul 15, 2020 at 1:34 PM Lee Jones <lee.jones at linaro.org> wrote:
> > >
> > > On Wed, 15 Jul 2020, Rafael J. Wysocki wrote:
> > >
> > > > On Wed, Jul 15, 2020 at 5:27 AM Viresh Kumar <viresh.kumar at linaro.org> wrote:
> > > > >
> > > > > On 15-07-20, 08:54, Viresh Kumar wrote:
> > > > > > On 14-07-20, 22:03, Lee Jones wrote:
> > > > > > > On Tue, 14 Jul 2020, Rafael J. Wysocki wrote:
> > > > > > >
> > > > > > > > On Tue, Jul 14, 2020 at 4:51 PM Lee Jones <lee.jones at linaro.org> wrote:
> > > > > > > > >
> > > > > > > > > Can't see them being used anywhere and the compiler doesn't complain
> > > > > > > > > that they're missing, so ...
> > > > > > > >
> > > > > > > > Aren't they needed for automatic module loading in certain configurations?
> > > > > > >
> > > > > > > Any idea how that works, or where the code is for that?
> > > > > >
> > > > > > The MODULE_DEVICE_TABLE() thingy creates a map of vendor-id,
> > > > > > product-id that the kernel keeps after boot (and so there is no static
> > > > > > reference of it for the compiler), later when a device is hotplugged
> > > > > > into the kernel it refers to the map to find the related driver for it
> > > > > > and loads it if it isn't already loaded.
> > > > > >
> > > > > > This has some of it, search for MODULE_DEVICE_TABLE() in it.
> > > > > > Documentation/driver-api/usb/hotplug.rst
> > > > >
> > > > > And you just need to add __maybe_unused to them to suppress the
> > > > > warning.
> > > >
> > > > Wouldn't that cause the compiler to optimize them away if it doesn't
> > > > see any users?
> > >
> > > It looks like they're only unused when !MODULE,
> > 
> > OK
> > 
> > > in which case optimising them away would be the correct thing to do, no?
> 
> It would be good if someone with a little more knowledge could provide
> a second opinion though.  I would think (hope) that the compiler would
> be smart enough to see when its actually in use.  After all, it is the
> compiler that places the information into the device table.
> 
> If that is not the case, then the MODULE_DEVICE_TABLE() magic is
> broken and will need fixing.  Removing boiler-plate is good, but not
> at the expense of obfuscation.

Okay, I'm satisfied.  This test build is without __maybe_unused:

# All configs built as modules (MODULE) - the compiler knows to use the tables

 $ ccache make -f Makefile -j24 KBUILD_OUTPUT=../builds/build-x86 allmodconfig
 $ ccache make -f Makefile -j24 KBUILD_OUTPUT=../builds/build-x86  W=1  drivers/cpufreq/
 [...]
   CC [M]  drivers/cpufreq/pcc-cpufreq.o

# All configs built-in (!MODULE) - the compiler sees that they are unused

 $ ccache make -f Makefile -j24 KBUILD_OUTPUT=../builds/build-x86 allyesconfig
 $ ccache make -f Makefile -j24 KBUILD_OUTPUT=../builds/build-x86  W=1  drivers/cpufreq/
   CC      drivers/cpufreq/pcc-cpufreq.o
  drivers/cpufreq/pcc-cpufreq.c:619:36: warning: ‘processor_device_ids’ defined but not used [-Wunused-const-variable=]
  619 | static const struct acpi_device_id processor_device_ids[] = {
      |                                    ^~~~~~~~~~~~~~~~~~~~

-- 
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog



More information about the linux-arm-kernel mailing list