Re: [PATCH v3 1/3] misc/pvpanic: split-up generic and platform dependent code

From: Arnd Bergmann
Date: Fri Feb 12 2021 - 15:28:42 EST


On Fri, Feb 12, 2021 at 8:32 PM Mihai Carabas <mihai.carabas@xxxxxxxxxx> wrote:
>
> Split-up generic and platform dependent code in order to be able to re-use
> generic event handling code in pvpanic PCI device driver in the next patches.
>
> The code from pvpanic.c was split in two new files:
> - pvpanic.c: generic code that handles pvpanic events
> - pvpanic-mmio.c: platform/bus dependent code
>
> Signed-off-by: Mihai Carabas <mihai.carabas@xxxxxxxxxx>

> ---
> drivers/misc/Kconfig | 9 +--
> drivers/misc/Makefile | 2 +-
> drivers/misc/pvpanic.c | 111 ------------------------------------
> drivers/misc/pvpanic/Kconfig | 19 ++++++
> drivers/misc/pvpanic/Makefile | 8 +++
> drivers/misc/pvpanic/pvpanic-mmio.c | 83 +++++++++++++++++++++++++++
> drivers/misc/pvpanic/pvpanic.c | 62 ++++++++++++++++++++
> drivers/misc/pvpanic/pvpanic.h | 17 ++++++


As mentioned, please use 'git format-patch -M' to make it easier to review

> +
> +config PVPANIC
> + bool "pvpanic device support"
> + help
> + This option allows to select a specific pvpanic device driver.
> + pvpanic is a paravirtualized device provided by QEMU; it lets
> + a virtual machine (guest) communicate panic events to the host.
> +
> +config PVPANIC_MMIO
> + tristate "pvpanic MMIO device support"
> + depends on HAS_IOMEM && (ACPI || OF) && PVPANIC
> + help
> + This driver provides support for the MMIO pvpanic device.
...
> +#
> +obj-$(CONFIG_PVPANIC) += pvpanic.o
> +obj-$(CONFIG_PVPANIC_MMIO) += pvpanic-mmio.o

This solves the problem that Greg pointed out, but now the core pvpanic
driver is always built-in even when it is only used from loadable modules.

The easiest way to express what you actually want is with a Makefile
trick:

obj-$(CONFIG_PVPANIC) += pvpanic.o pvpanic-pci.o
obj-$(CONFIG_PVPANIC_MMIO) += pvpanic.o pvpanic-mmio.o

When you do this, pvpanic.o is built-in when at least one of its
users is built-in, and otherwise it a loadable module when there
is at least one user, but it will not be built twice or with the wrong
flags.

Arnd