Re: [PATCH v2] gpio: mockup: Allow probing from device tree
From: Vincent Whitchurch
Date: Wed Oct 28 2020 - 22:45:14 EST
On Tue, Oct 27, 2020 at 07:12:13PM +0100, Bartosz Golaszewski wrote:
> On Tue, Oct 27, 2020 at 2:54 PM Vincent Whitchurch
> <vincent.whitchurch@xxxxxxxx> wrote:
> > diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
> > index 67ed4f238d43..c93892a6936a 100644
> > --- a/drivers/gpio/gpio-mockup.c
> > +++ b/drivers/gpio/gpio-mockup.c
> > @@ -13,6 +13,7 @@
> > #include <linux/gpio/driver.h>
> > #include <linux/interrupt.h>
> > #include <linux/irq.h>
> > +#include <linux/of.h>
>
> Please keep the includes ordered alphabetically.
Thanks, fixed in v3.
> > #include <linux/irq_sim.h>
> > #include <linux/irqdomain.h>
> > #include <linux/module.h>
> > @@ -460,9 +461,18 @@ static int gpio_mockup_probe(struct platform_device *pdev)
> > return 0;
> > }
> >
> > +#ifdef CONFIG_OF
> > +static const struct of_device_id gpio_mockup_of_match[] = {
> > + { .compatible = "gpio-mockup", },
> > + {},
> > +};
> > +MODULE_DEVICE_TABLE(of, gpio_mockup_of_match);
> > +#endif
>
> You don't need this ifdef - of_match_ptr() will evaluate to NULL if
> CONFIG_OF is disabled and the compiler will optimize this struct out.
The compiler can't optimise out the struct in the case of a module build
since there is a reference from the MODULE_DEVICE_TABLE:
$ grep CONFIG_OF .config
# CONFIG_OF is not set
$ nm drivers/gpio/gpio-mockup.ko | grep of_
00000000 r gpio_mockup_of_match
00000000 R __mod_of__gpio_mockup_of_match_device_table
But these few wasted bytes don't matter so I removed the CONFIG_OF
anyway as you suggested.