of: Define of_match_ptr() with PTR_IF() to avoid unused variable warnings

Message ID 20221013195153.2767632-1-nathan@kernel.org
State New
Headers
Series of: Define of_match_ptr() with PTR_IF() to avoid unused variable warnings |

Commit Message

Nathan Chancellor Oct. 13, 2022, 7:51 p.m. UTC
  When CONFIG_OF is disabled and a driver is built in, it is possible for
an of_device_id structure to be unused, which results in a build warning
with W=1 due to -Wunused-const-variable.

For example, in sound/soc/codecs/src4xxx-i2c.c:

  static const struct of_device_id src4xxx_of_match[] = {
      { .compatible = "ti,src4392", },
      { }
  };
  MODULE_DEVICE_TABLE(of, src4xxx_of_match);

  static struct i2c_driver src4xxx_i2c_driver = {
      .driver = {
          .name = "src4xxx",
          .of_match_table = of_match_ptr(src4xxx_of_match),
      },
      .probe = src4xxx_i2c_probe,
      .id_table = src4xxx_i2c_ids,
  };
  module_i2c_driver(src4xxx_i2c_driver);

A configuration with CONFIG_OF=n and CONFIG_SND_SOC_SRC4XXX_I2C=y
produces

  sound/soc/codecs/src4xxx-i2c.c:28:34: warning: unused variable 'src4xxx_of_match' [-Wunused-const-variable]
  static const struct of_device_id src4xxx_of_match[] = {
                                   ^

because of_patch_ptr() expands to NULL when CONFIG_OF=n and
MODULE_DEVICE_TABLE() expands to nothing when MODULE is not set (i.e.,
when the driver is built into the kernel).

This is a similar situation to the power management suspend and resume
functions, which may or may not be used depending on whether or not
CONFIG_PM is set. The solution for a long time was to make the functions
as __maybe_unused but commit c06ef740d401 ("PM: core: Redefine pm_ptr()
macro") adopted a new solution involving IS_ENABLED() and PTR_IF(),
which allows the compiler to see the referenced object at least once in
the file to clear up the unused warning, while simultaneously allowing
the compiler to eliminate unused code in the final object file.

Do the same thing with of_match_ptr() so that unused device IDs do not
cause warnings. This would have prevented several added #ifdef's, such
as the one added by commit 527a7f52529f ("perf/smmuv3: Fix unused
variable warning when CONFIG_OF=n").

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 include/linux/of.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


base-commit: 4fe89d07dcc2804c8b562f6c7896a45643d34b2f
  

Comments

kernel test robot Oct. 14, 2022, 2:27 a.m. UTC | #1
Hi Nathan,

I love your patch! Yet something to improve:

[auto build test ERROR on 4fe89d07dcc2804c8b562f6c7896a45643d34b2f]

url:    https://github.com/intel-lab-lkp/linux/commits/Nathan-Chancellor/of-Define-of_match_ptr-with-PTR_IF-to-avoid-unused-variable-warnings/20221014-035324
base:   4fe89d07dcc2804c8b562f6c7896a45643d34b2f
config: hexagon-randconfig-r045-20221012
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/d312b5902005bf2f4497687edc1b1df76baa337b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Nathan-Chancellor/of-Define-of_match_ptr-with-PTR_IF-to-avoid-unused-variable-warnings/20221014-035324
        git checkout d312b5902005bf2f4497687edc1b1df76baa337b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/fpga/ drivers/hwmon/pmbus/ drivers/i2c/busses/ drivers/iio/adc/ drivers/phy/motorola/ drivers/power/supply/ drivers/regulator/ drivers/rtc/ drivers/tty/serial/ drivers/usb/cdns3/ drivers/usb/dwc3/ drivers/usb/host/ drivers/usb/misc/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/fpga/machxo2-spi.c:395:34: error: use of undeclared identifier 'of_match'
                   .of_match_table = of_match_ptr(of_match),
                                                  ^
   1 error generated.
--
>> drivers/fpga/altera-freeze-bridge.c:273:34: error: use of undeclared identifier 'altera_freeze_br_of_match'; did you mean 'altera_freeze_br_req_ack'?
                   .of_match_table = of_match_ptr(altera_freeze_br_of_match),
                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~
                                                  altera_freeze_br_req_ack
   include/linux/of.h:848:59: note: expanded from macro 'of_match_ptr'
   #define of_match_ptr(_ptr)      PTR_IF(IS_ENABLED(CONFIG_OF), (_ptr))
                                                                  ^
   include/linux/kernel.h:57:38: note: expanded from macro 'PTR_IF'
   #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
                                              ^
   drivers/fpga/altera-freeze-bridge.c:40:12: note: 'altera_freeze_br_req_ack' declared here
   static int altera_freeze_br_req_ack(struct altera_freeze_br_data *priv,
              ^
>> drivers/fpga/altera-freeze-bridge.c:273:21: error: incompatible pointer types initializing 'const struct of_device_id *' with an expression of type 'int (*)(struct altera_freeze_br_data *, u32, u32)' (aka 'int (*)(struct altera_freeze_br_data *, unsigned int, unsigned int)') [-Werror,-Wincompatible-pointer-types]
                   .of_match_table = of_match_ptr(altera_freeze_br_of_match),
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/of.h:848:28: note: expanded from macro 'of_match_ptr'
   #define of_match_ptr(_ptr)      PTR_IF(IS_ENABLED(CONFIG_OF), (_ptr))
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:27: note: expanded from macro 'PTR_IF'
   #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
                                   ^~~~~~~~~~~~~~~~~~~~~~~
   2 errors generated.
--
>> drivers/fpga/xilinx-pr-decoupler.c:179:34: error: use of undeclared identifier 'xlnx_pr_decoupler_of_match'
                   .of_match_table = of_match_ptr(xlnx_pr_decoupler_of_match),
                                                  ^
   1 error generated.
--
>> drivers/hwmon/pmbus/pli1209bc.c:135:37: error: use of undeclared identifier 'pli1209bc_of_match'
                      .of_match_table = of_match_ptr(pli1209bc_of_match),
                                                     ^
   1 error generated.
--
>> drivers/i2c/busses/i2c-pca-platform.c:247:34: error: use of undeclared identifier 'i2c_pca_of_match_table'
                   .of_match_table = of_match_ptr(i2c_pca_of_match_table),
                                                  ^
   1 error generated.
--
>> drivers/regulator/act8865-regulator.c:670:37: error: use of undeclared identifier 'act8865_dt_ids'; did you mean 'act8865_ldo_ops'?
                   id = of_match_device(of_match_ptr(act8865_dt_ids), dev);
                                                     ^~~~~~~~~~~~~~
                                                     act8865_ldo_ops
   include/linux/of.h:848:59: note: expanded from macro 'of_match_ptr'
   #define of_match_ptr(_ptr)      PTR_IF(IS_ENABLED(CONFIG_OF), (_ptr))
                                                                  ^
   include/linux/kernel.h:57:38: note: expanded from macro 'PTR_IF'
   #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
                                              ^
   drivers/regulator/act8865-regulator.c:416:35: note: 'act8865_ldo_ops' declared here
   static const struct regulator_ops act8865_ldo_ops = {
                                     ^
>> drivers/regulator/act8865-regulator.c:670:24: error: incompatible operand types ('struct regulator_ops' and 'void *')
                   id = of_match_device(of_match_ptr(act8865_dt_ids), dev);
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/of.h:848:28: note: expanded from macro 'of_match_ptr'
   #define of_match_ptr(_ptr)      PTR_IF(IS_ENABLED(CONFIG_OF), (_ptr))
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:35: note: expanded from macro 'PTR_IF'
   #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
                                           ^ ~~~~~   ~~~~
   2 errors generated.
--
>> drivers/regulator/isl9305.c:198:34: error: use of undeclared identifier 'isl9305_dt_ids'; did you mean 'isl9305_i2c_id'?
                   .of_match_table = of_match_ptr(isl9305_dt_ids),
                                                  ^~~~~~~~~~~~~~
                                                  isl9305_i2c_id
   include/linux/of.h:848:59: note: expanded from macro 'of_match_ptr'
   #define of_match_ptr(_ptr)      PTR_IF(IS_ENABLED(CONFIG_OF), (_ptr))
                                                                  ^
   include/linux/kernel.h:57:38: note: expanded from macro 'PTR_IF'
   #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
                                              ^
   drivers/regulator/isl9305.c:188:35: note: 'isl9305_i2c_id' declared here
   static const struct i2c_device_id isl9305_i2c_id[] = {
                                     ^
>> drivers/regulator/isl9305.c:198:21: error: incompatible pointer types initializing 'const struct of_device_id *' with an expression of type 'const struct i2c_device_id *' [-Werror,-Wincompatible-pointer-types]
                   .of_match_table = of_match_ptr(isl9305_dt_ids),
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/of.h:848:28: note: expanded from macro 'of_match_ptr'
   #define of_match_ptr(_ptr)      PTR_IF(IS_ENABLED(CONFIG_OF), (_ptr))
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:27: note: expanded from macro 'PTR_IF'
   #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
                                   ^~~~~~~~~~~~~~~~~~~~~~~
   2 errors generated.
--
>> drivers/rtc/rtc-ab-eoz9.c:580:34: error: use of undeclared identifier 'abeoz9_dt_match'
                   .of_match_table = of_match_ptr(abeoz9_dt_match),
                                                  ^
   1 error generated.
--
>> drivers/rtc/rtc-abx80x.c:915:34: error: use of undeclared identifier 'abx80x_of_match'
                   .of_match_table = of_match_ptr(abx80x_of_match),
                                                  ^
   1 error generated.
--
>> drivers/rtc/rtc-ds1302.c:209:40: error: use of undeclared identifier 'ds1302_dt_ids'; did you mean 'ds1302_spi_ids'?
           .driver.of_match_table = of_match_ptr(ds1302_dt_ids),
                                                 ^~~~~~~~~~~~~
                                                 ds1302_spi_ids
   include/linux/of.h:848:59: note: expanded from macro 'of_match_ptr'
   #define of_match_ptr(_ptr)      PTR_IF(IS_ENABLED(CONFIG_OF), (_ptr))
                                                                  ^
   include/linux/kernel.h:57:38: note: expanded from macro 'PTR_IF'
   #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
                                              ^
   drivers/rtc/rtc-ds1302.c:201:35: note: 'ds1302_spi_ids' declared here
   static const struct spi_device_id ds1302_spi_ids[] = {
                                     ^
>> drivers/rtc/rtc-ds1302.c:209:27: error: incompatible pointer types initializing 'const struct of_device_id *' with an expression of type 'const struct spi_device_id *' [-Werror,-Wincompatible-pointer-types]
           .driver.of_match_table = of_match_ptr(ds1302_dt_ids),
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/of.h:848:28: note: expanded from macro 'of_match_ptr'
   #define of_match_ptr(_ptr)      PTR_IF(IS_ENABLED(CONFIG_OF), (_ptr))
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:27: note: expanded from macro 'PTR_IF'
   #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
                                   ^~~~~~~~~~~~~~~~~~~~~~~
   2 errors generated.
--
>> drivers/rtc/rtc-mcp795.c:442:36: error: use of undeclared identifier 'mcp795_of_match'
                                   .of_match_table = of_match_ptr(mcp795_of_match),
                                                                  ^
   1 error generated.
..


vim +/of_match +395 drivers/fpga/machxo2-spi.c

88fb3a00233073 Paolo Pisati 2018-04-16  391  
88fb3a00233073 Paolo Pisati 2018-04-16  392  static struct spi_driver machxo2_spi_driver = {
88fb3a00233073 Paolo Pisati 2018-04-16  393  	.driver = {
88fb3a00233073 Paolo Pisati 2018-04-16  394  		.name = "machxo2-slave-spi",
88fb3a00233073 Paolo Pisati 2018-04-16 @395  		.of_match_table = of_match_ptr(of_match),
88fb3a00233073 Paolo Pisati 2018-04-16  396  	},
88fb3a00233073 Paolo Pisati 2018-04-16  397  	.probe = machxo2_spi_probe,
88fb3a00233073 Paolo Pisati 2018-04-16  398  	.id_table = lattice_ids,
88fb3a00233073 Paolo Pisati 2018-04-16  399  };
88fb3a00233073 Paolo Pisati 2018-04-16  400
  
kernel test robot Oct. 14, 2022, 2:27 a.m. UTC | #2
Hi Nathan,

I love your patch! Yet something to improve:

[auto build test ERROR on 4fe89d07dcc2804c8b562f6c7896a45643d34b2f]

url:    https://github.com/intel-lab-lkp/linux/commits/Nathan-Chancellor/of-Define-of_match_ptr-with-PTR_IF-to-avoid-unused-variable-warnings/20221014-035324
base:   4fe89d07dcc2804c8b562f6c7896a45643d34b2f
config: m68k-randconfig-r005-20221012
compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/d312b5902005bf2f4497687edc1b1df76baa337b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Nathan-Chancellor/of-Define-of_match_ptr-with-PTR_IF-to-avoid-unused-variable-warnings/20221014-035324
        git checkout d312b5902005bf2f4497687edc1b1df76baa337b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/char/tpm/ drivers/fpga/ drivers/gpio/ drivers/hwmon/ drivers/input/joystick/ drivers/media/i2c/ drivers/media/radio/si470x/ drivers/mfd/ drivers/misc/lis3lv02d/ drivers/regulator/ drivers/spi/ drivers/uio/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/rcupdate.h:29,
                    from include/linux/rculist.h:11,
                    from include/linux/pid.h:5,
                    from include/linux/sched.h:14,
                    from include/linux/delay.h:23,
                    from drivers/fpga/xilinx-spi.c:13:
>> drivers/fpga/xilinx-spi.c:267:48: error: 'xlnx_spi_of_match' undeclared here (not in a function)
     267 |                 .of_match_table = of_match_ptr(xlnx_spi_of_match),
         |                                                ^~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/fpga/xilinx-spi.c:267:35: note: in expansion of macro 'of_match_ptr'
     267 |                 .of_match_table = of_match_ptr(xlnx_spi_of_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/rcupdate.h:29,
                    from include/linux/rculist.h:11,
                    from include/linux/pid.h:5,
                    from include/linux/sched.h:14,
                    from include/linux/delay.h:23,
                    from drivers/fpga/microchip-spi.c:7:
>> drivers/fpga/microchip-spi.c:391:48: error: 'mpf_of_ids' undeclared here (not in a function); did you mean 'mpf_spi_ids'?
     391 |                 .of_match_table = of_match_ptr(mpf_of_ids),
         |                                                ^~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/fpga/microchip-spi.c:391:35: note: in expansion of macro 'of_match_ptr'
     391 |                 .of_match_table = of_match_ptr(mpf_of_ids),
         |                                   ^~~~~~~~~~~~
--
   In file included from drivers/gpio/gpio-mmio.c:46:
>> drivers/gpio/gpio-mmio.c:810:48: error: 'bgpio_of_match' undeclared here (not in a function)
     810 |                 .of_match_table = of_match_ptr(bgpio_of_match),
         |                                                ^~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/gpio/gpio-mmio.c:810:35: note: in expansion of macro 'of_match_ptr'
     810 |                 .of_match_table = of_match_ptr(bgpio_of_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/rcupdate.h:29,
                    from include/linux/rculist.h:11,
                    from include/linux/pid.h:5,
                    from include/linux/sched.h:14,
                    from include/linux/ratelimit.h:6,
                    from include/linux/dev_printk.h:16,
                    from include/linux/device.h:15,
                    from include/linux/gpio/driver.h:5,
                    from drivers/gpio/gpio-max3191x.c:37:
>> drivers/gpio/gpio-max3191x.c:487:48: error: 'max3191x_of_id' undeclared here (not in a function); did you mean 'max3191x_spi_id'?
     487 |                 .of_match_table = of_match_ptr(max3191x_of_id),
         |                                                ^~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/gpio/gpio-max3191x.c:487:35: note: in expansion of macro 'of_match_ptr'
     487 |                 .of_match_table = of_match_ptr(max3191x_of_id),
         |                                   ^~~~~~~~~~~~
--
   In file included from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/mutex.h:17,
                    from include/linux/kernfs.h:11,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/of.h:18,
                    from include/linux/irqdomain.h:35,
                    from include/linux/acpi.h:13,
                    from include/linux/i2c.h:13,
                    from drivers/char/tpm/tpm_tis_i2c.c:13:
>> drivers/char/tpm/tpm_tis_i2c.c:381:48: error: 'of_tis_i2c_match' undeclared here (not in a function)
     381 |                 .of_match_table = of_match_ptr(of_tis_i2c_match),
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/char/tpm/tpm_tis_i2c.c:381:35: note: in expansion of macro 'of_match_ptr'
     381 |                 .of_match_table = of_match_ptr(of_tis_i2c_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from include/linux/cpumask.h:10,
                    from include/linux/mm_types_task.h:14,
                    from include/linux/mm_types.h:5,
                    from include/linux/buildid.h:5,
                    from include/linux/module.h:14,
                    from drivers/hwmon/lm70.c:17:
>> drivers/hwmon/lm70.c:212:48: error: 'lm70_of_ids' undeclared here (not in a function); did you mean 'lm70_ids'?
     212 |                 .of_match_table = of_match_ptr(lm70_of_ids),
         |                                                ^~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/hwmon/lm70.c:212:35: note: in expansion of macro 'of_match_ptr'
     212 |                 .of_match_table = of_match_ptr(lm70_of_ids),
         |                                   ^~~~~~~~~~~~
--
   In file included from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/mutex.h:17,
                    from include/linux/kernfs.h:11,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/of.h:18,
                    from include/linux/irqdomain.h:35,
                    from include/linux/acpi.h:13,
                    from drivers/mfd/arizona-spi.c:10:
>> drivers/mfd/arizona-spi.c:286:48: error: 'arizona_spi_of_match' undeclared here (not in a function); did you mean 'arizona_spi_remove'?
     286 |                 .of_match_table = of_match_ptr(arizona_spi_of_match),
         |                                                ^~~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/mfd/arizona-spi.c:286:35: note: in expansion of macro 'of_match_ptr'
     286 |                 .of_match_table = of_match_ptr(arizona_spi_of_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/spinlock.h:62,
                    from include/linux/mmzone.h:8,
                    from include/linux/gfp.h:7,
                    from include/linux/slab.h:15,
                    from drivers/mfd/tps65910.c:13:
>> drivers/mfd/tps65910.c:536:51: error: 'tps65910_of_match' undeclared here (not in a function)
     536 |                    .of_match_table = of_match_ptr(tps65910_of_match),
         |                                                   ^~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/mfd/tps65910.c:536:38: note: in expansion of macro 'of_match_ptr'
     536 |                    .of_match_table = of_match_ptr(tps65910_of_match),
         |                                      ^~~~~~~~~~~~
--
   In file included from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/mutex.h:17,
                    from include/linux/kernfs.h:11,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/of.h:18,
                    from include/linux/irqdomain.h:35,
                    from include/linux/acpi.h:13,
                    from include/linux/i2c.h:13,
                    from drivers/mfd/max8907.c:10:
>> drivers/mfd/max8907.c:317:48: error: 'max8907_of_match' undeclared here (not in a function)
     317 |                 .of_match_table = of_match_ptr(max8907_of_match),
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/mfd/max8907.c:317:35: note: in expansion of macro 'of_match_ptr'
     317 |                 .of_match_table = of_match_ptr(max8907_of_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/spinlock.h:62,
                    from include/linux/mmzone.h:8,
                    from include/linux/gfp.h:7,
                    from include/linux/slab.h:15,
                    from drivers/mfd/max8998.c:11:
>> drivers/mfd/max8998.c:349:51: error: 'max8998_dt_match' undeclared here (not in a function); did you mean 'max8998_dump'?
     349 |                    .of_match_table = of_match_ptr(max8998_dt_match),
         |                                                   ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/mfd/max8998.c:349:38: note: in expansion of macro 'of_match_ptr'
     349 |                    .of_match_table = of_match_ptr(max8998_dt_match),
         |                                      ^~~~~~~~~~~~
--
   In file included from include/linux/interrupt.h:6,
                    from drivers/mfd/tps65090.c:10:
>> drivers/mfd/tps65090.c:239:48: error: 'tps65090_of_match' undeclared here (not in a function)
     239 |                 .of_match_table = of_match_ptr(tps65090_of_match),
         |                                                ^~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/mfd/tps65090.c:239:35: note: in expansion of macro 'of_match_ptr'
     239 |                 .of_match_table = of_match_ptr(tps65090_of_match),
         |                                   ^~~~~~~~~~~~
..


vim +/xlnx_spi_of_match +267 drivers/fpga/xilinx-spi.c

061c97d13f1a69c Anatolij Gustschin 2017-03-23  263  
061c97d13f1a69c Anatolij Gustschin 2017-03-23  264  static struct spi_driver xilinx_slave_spi_driver = {
061c97d13f1a69c Anatolij Gustschin 2017-03-23  265  	.driver = {
061c97d13f1a69c Anatolij Gustschin 2017-03-23  266  		.name = "xlnx-slave-spi",
061c97d13f1a69c Anatolij Gustschin 2017-03-23 @267  		.of_match_table = of_match_ptr(xlnx_spi_of_match),
061c97d13f1a69c Anatolij Gustschin 2017-03-23  268  	},
061c97d13f1a69c Anatolij Gustschin 2017-03-23  269  	.probe = xilinx_spi_probe,
061c97d13f1a69c Anatolij Gustschin 2017-03-23  270  };
061c97d13f1a69c Anatolij Gustschin 2017-03-23  271
  
kernel test robot Oct. 14, 2022, 2:37 a.m. UTC | #3
Hi Nathan,

I love your patch! Yet something to improve:

[auto build test ERROR on 4fe89d07dcc2804c8b562f6c7896a45643d34b2f]

url:    https://github.com/intel-lab-lkp/linux/commits/Nathan-Chancellor/of-Define-of_match_ptr-with-PTR_IF-to-avoid-unused-variable-warnings/20221014-035324
base:   4fe89d07dcc2804c8b562f6c7896a45643d34b2f
config: x86_64-rhel-8.3-func
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/d312b5902005bf2f4497687edc1b1df76baa337b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Nathan-Chancellor/of-Define-of_match_ptr-with-PTR_IF-to-avoid-unused-variable-warnings/20221014-035324
        git checkout d312b5902005bf2f4497687edc1b1df76baa337b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/char/tpm/ drivers/dma/dw/ drivers/hwmon/ drivers/i2c/busses/ drivers/input/mouse/ drivers/input/rmi4/ drivers/input/serio/ drivers/misc/lis3lv02d/ drivers/rtc/ drivers/uio/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from arch/x86/include/asm/percpu.h:27,
                    from arch/x86/include/asm/current.h:6,
                    from include/linux/sched.h:12,
                    from include/linux/delay.h:23,
                    from drivers/hwmon/pmbus/ltc2978.c:11:
>> drivers/hwmon/pmbus/ltc2978.c:923:51: error: 'ltc2978_of_match' undeclared here (not in a function); did you mean 'ltc2978_data'?
     923 |                    .of_match_table = of_match_ptr(ltc2978_of_match),
         |                                                   ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/hwmon/pmbus/ltc2978.c:923:38: note: in expansion of macro 'of_match_ptr'
     923 |                    .of_match_table = of_match_ptr(ltc2978_of_match),
         |                                      ^~~~~~~~~~~~
--
   In file included from arch/x86/include/asm/percpu.h:27,
                    from arch/x86/include/asm/current.h:6,
                    from include/linux/mutex.h:14,
                    from include/linux/kernfs.h:11,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/of.h:18,
                    from include/linux/irqdomain.h:35,
                    from include/linux/acpi.h:13,
                    from drivers/i2c/busses/i2c-designware-platdrv.c:11:
>> drivers/i2c/busses/i2c-designware-platdrv.c:504:48: error: 'dw_i2c_of_match' undeclared here (not in a function); did you mean 'dw_i2c_acpi_match'?
     504 |                 .of_match_table = of_match_ptr(dw_i2c_of_match),
         |                                                ^~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/i2c/busses/i2c-designware-platdrv.c:504:35: note: in expansion of macro 'of_match_ptr'
     504 |                 .of_match_table = of_match_ptr(dw_i2c_of_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from drivers/i2c/busses/i2c-pca-platform.c:11:
>> drivers/i2c/busses/i2c-pca-platform.c:247:48: error: 'i2c_pca_of_match_table' undeclared here (not in a function)
     247 |                 .of_match_table = of_match_ptr(i2c_pca_of_match_table),
         |                                                ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/i2c/busses/i2c-pca-platform.c:247:35: note: in expansion of macro 'of_match_ptr'
     247 |                 .of_match_table = of_match_ptr(i2c_pca_of_match_table),
         |                                   ^~~~~~~~~~~~
--
   In file included from arch/x86/include/asm/percpu.h:27,
                    from arch/x86/include/asm/current.h:6,
                    from include/linux/sched.h:12,
                    from include/linux/delay.h:23,
                    from drivers/input/mouse/cyapa.c:17:
>> drivers/input/mouse/cyapa.c:1490:48: error: 'cyapa_of_match' undeclared here (not in a function)
    1490 |                 .of_match_table = of_match_ptr(cyapa_of_match),
         |                                                ^~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/input/mouse/cyapa.c:1490:35: note: in expansion of macro 'of_match_ptr'
    1490 |                 .of_match_table = of_match_ptr(cyapa_of_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from arch/x86/include/asm/percpu.h:27,
                    from arch/x86/include/asm/current.h:6,
                    from include/linux/mutex.h:14,
                    from include/linux/kernfs.h:11,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/of.h:18,
                    from include/linux/irqdomain.h:35,
                    from include/linux/acpi.h:13,
                    from drivers/input/mouse/elan_i2c_core.c:18:
>> drivers/input/mouse/elan_i2c_core.c:1443:48: error: 'elan_of_match' undeclared here (not in a function)
    1443 |                 .of_match_table = of_match_ptr(elan_of_match),
         |                                                ^~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/input/mouse/elan_i2c_core.c:1443:35: note: in expansion of macro 'of_match_ptr'
    1443 |                 .of_match_table = of_match_ptr(elan_of_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from arch/x86/include/asm/percpu.h:27,
                    from arch/x86/include/asm/nospec-branch.h:14,
                    from arch/x86/include/asm/paravirt_types.h:40,
                    from arch/x86/include/asm/ptrace.h:97,
                    from arch/x86/include/asm/math_emu.h:5,
                    from arch/x86/include/asm/processor.h:13,
                    from arch/x86/include/asm/timex.h:5,
                    from include/linux/timex.h:67,
                    from include/linux/time32.h:13,
                    from include/linux/time.h:60,
                    from include/linux/stat.h:19,
                    from include/linux/module.h:13,
                    from drivers/input/mouse/synaptics_i2c.c:13:
>> drivers/input/mouse/synaptics_i2c.c:652:48: error: 'synaptics_i2c_of_match' undeclared here (not in a function); did you mean 'synaptics_i2c_id_table'?
     652 |                 .of_match_table = of_match_ptr(synaptics_i2c_of_match),
         |                                                ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/input/mouse/synaptics_i2c.c:652:35: note: in expansion of macro 'of_match_ptr'
     652 |                 .of_match_table = of_match_ptr(synaptics_i2c_of_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from arch/x86/include/asm/percpu.h:27,
                    from arch/x86/include/asm/current.h:6,
                    from include/linux/mutex.h:14,
                    from include/linux/kernfs.h:11,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/of.h:18,
                    from include/linux/irqdomain.h:35,
                    from include/linux/acpi.h:13,
                    from include/linux/i2c.h:13,
                    from drivers/input/rmi4/rmi_i2c.c:7:
>> drivers/input/rmi4/rmi_i2c.c:383:48: error: 'rmi_i2c_of_match' undeclared here (not in a function)
     383 |                 .of_match_table = of_match_ptr(rmi_i2c_of_match),
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/input/rmi4/rmi_i2c.c:383:35: note: in expansion of macro 'of_match_ptr'
     383 |                 .of_match_table = of_match_ptr(rmi_i2c_of_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from drivers/input/rmi4/rmi_spi.c:7:
>> drivers/input/rmi4/rmi_spi.c:522:48: error: 'rmi_spi_of_match' undeclared here (not in a function); did you mean 'rmi_spi_of_probe'?
     522 |                 .of_match_table = of_match_ptr(rmi_spi_of_match),
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/input/rmi4/rmi_spi.c:522:35: note: in expansion of macro 'of_match_ptr'
     522 |                 .of_match_table = of_match_ptr(rmi_spi_of_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from arch/x86/include/asm/percpu.h:27,
                    from arch/x86/include/asm/nospec-branch.h:14,
                    from arch/x86/include/asm/paravirt_types.h:40,
                    from arch/x86/include/asm/ptrace.h:97,
                    from arch/x86/include/asm/math_emu.h:5,
                    from arch/x86/include/asm/processor.h:13,
                    from arch/x86/include/asm/timex.h:5,
                    from include/linux/timex.h:67,
                    from include/linux/time32.h:13,
                    from include/linux/time.h:60,
                    from include/linux/stat.h:19,
                    from include/linux/module.h:13,
                    from drivers/input/serio/altera_ps2.c:11:
>> drivers/input/serio/altera_ps2.c:156:48: error: 'altera_ps2_match' undeclared here (not in a function); did you mean 'altera_ps2_probe'?
     156 |                 .of_match_table = of_match_ptr(altera_ps2_match),
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/input/serio/altera_ps2.c:156:35: note: in expansion of macro 'of_match_ptr'
     156 |                 .of_match_table = of_match_ptr(altera_ps2_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from arch/x86/include/asm/percpu.h:27,
                    from arch/x86/include/asm/nospec-branch.h:14,
                    from arch/x86/include/asm/paravirt_types.h:40,
                    from arch/x86/include/asm/ptrace.h:97,
                    from arch/x86/include/asm/math_emu.h:5,
                    from arch/x86/include/asm/processor.h:13,
                    from arch/x86/include/asm/timex.h:5,
                    from include/linux/timex.h:67,
                    from include/linux/time32.h:13,
                    from include/linux/time.h:60,
                    from include/linux/stat.h:19,
                    from include/linux/module.h:13,
                    from drivers/input/serio/arc_ps2.c:9:
>> drivers/input/serio/arc_ps2.c:264:48: error: 'arc_ps2_match' undeclared here (not in a function); did you mean 'arc_ps2_data'?
     264 |                 .of_match_table = of_match_ptr(arc_ps2_match),
         |                                                ^~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/input/serio/arc_ps2.c:264:35: note: in expansion of macro 'of_match_ptr'
     264 |                 .of_match_table = of_match_ptr(arc_ps2_match),
         |                                   ^~~~~~~~~~~~
--
   In file included from arch/x86/include/asm/percpu.h:27,
                    from arch/x86/include/asm/nospec-branch.h:14,
                    from arch/x86/include/asm/paravirt_types.h:40,
                    from arch/x86/include/asm/ptrace.h:97,
                    from arch/x86/include/asm/math_emu.h:5,
                    from arch/x86/include/asm/processor.h:13,
                    from arch/x86/include/asm/timex.h:5,
                    from include/linux/timex.h:67,
                    from include/linux/time32.h:13,
                    from include/linux/time.h:60,
                    from include/linux/stat.h:19,
                    from include/linux/module.h:13,
                    from drivers/misc/lis3lv02d/lis3lv02d_i2c.c:14:
>> drivers/misc/lis3lv02d/lis3lv02d_i2c.c:265:48: error: 'lis3lv02d_i2c_dt_ids' undeclared here (not in a function); did you mean 'lis3lv02d_i2c_driver'?
     265 |                 .of_match_table = of_match_ptr(lis3lv02d_i2c_dt_ids),
         |                                                ^~~~~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:44: note: in definition of macro 'PTR_IF'
      57 | #define PTR_IF(cond, ptr)       ((cond) ? (ptr) : NULL)
         |                                            ^~~
   drivers/misc/lis3lv02d/lis3lv02d_i2c.c:265:35: note: in expansion of macro 'of_match_ptr'
     265 |                 .of_match_table = of_match_ptr(lis3lv02d_i2c_dt_ids),
         |                                   ^~~~~~~~~~~~
..


vim +923 drivers/hwmon/pmbus/ltc2978.c

77aa3585805920d Alan Tull     2014-10-15  919  
c3ff9a674c2313d Guenter Roeck 2011-09-02  920  static struct i2c_driver ltc2978_driver = {
c3ff9a674c2313d Guenter Roeck 2011-09-02  921  	.driver = {
c3ff9a674c2313d Guenter Roeck 2011-09-02  922  		   .name = "ltc2978",
77aa3585805920d Alan Tull     2014-10-15 @923  		   .of_match_table = of_match_ptr(ltc2978_of_match),
c3ff9a674c2313d Guenter Roeck 2011-09-02  924  		   },
dd43193976b9a7b Stephen Kitt  2020-08-08  925  	.probe_new = ltc2978_probe,
c3ff9a674c2313d Guenter Roeck 2011-09-02  926  	.id_table = ltc2978_id,
c3ff9a674c2313d Guenter Roeck 2011-09-02  927  };
c3ff9a674c2313d Guenter Roeck 2011-09-02  928
  
Arnd Bergmann Oct. 14, 2022, 8:10 a.m. UTC | #4
On Thu, Oct 13, 2022, at 9:51 PM, Nathan Chancellor wrote:
> 
> -#define of_match_ptr(_ptr)	NULL
>  #define of_match_node(_matches, _node)	NULL
>  #endif /* CONFIG_OF */
> 
> +#define of_match_ptr(_ptr)	PTR_IF(IS_ENABLED(CONFIG_OF), (_ptr))
> +

I think this is counterproductive, as it means we cannot use
of_match_ptr() for its intended purpose any more, it will
now cause a build failure for any driver that references a
match table inside of an #ifdef.

Ideally we should be able to find the misuse of this macro with
coccinelle and have it automatically generate patches that just remove
it from drivers.

A first-level approximation would be this oneliner:

git grep -wl of_match_ptr | xargs git grep -wL CONFIG_OF | xargs sed -i "s:of_match_ptr(\([\ \#\>\"a-zA-Z0-9_-]*\)):\1:"

which takes care of 535 files that don't reference CONFIG_OF at all.
There are 496 more files that use of_match_ptr() as well but also
guard something inside of CONFIG_OF. Most of these are just
incorrectly copy-pasted from older drivers and should not have an
#ifdef in them to make the of_match_ptr() work, but they are not actually
usable without CONFIG_OF.

Historically, we added the #ifdef at the time when we supported hundreds
of boards without DT and only a couple of boards with DT, so having the
extra #ifdef was a way of ensuring that the DT conversion would not add
a few extra bytes of .data to each driver. Now we support thousands of
boards with DT and only a few dozen without DT, so this is all pointless.

       Arnd
  
Nathan Chancellor Oct. 14, 2022, 4:47 p.m. UTC | #5
On Fri, Oct 14, 2022 at 10:10:39AM +0200, Arnd Bergmann wrote:
> On Thu, Oct 13, 2022, at 9:51 PM, Nathan Chancellor wrote:
> > 
> > -#define of_match_ptr(_ptr)	NULL
> >  #define of_match_node(_matches, _node)	NULL
> >  #endif /* CONFIG_OF */
> > 
> > +#define of_match_ptr(_ptr)	PTR_IF(IS_ENABLED(CONFIG_OF), (_ptr))
> > +
> 
> I think this is counterproductive, as it means we cannot use
> of_match_ptr() for its intended purpose any more, it will
> now cause a build failure for any driver that references a
> match table inside of an #ifdef.

Ack, I obviously had not considered this before sending the change,
shows how much compile testing it got ;)

> Ideally we should be able to find the misuse of this macro with
> coccinelle and have it automatically generate patches that just remove
> it from drivers.
> 
> A first-level approximation would be this oneliner:
> 
> git grep -wl of_match_ptr | xargs git grep -wL CONFIG_OF | xargs sed -i "s:of_match_ptr(\([\ \#\>\"a-zA-Z0-9_-]*\)):\1:"
> 
> which takes care of 535 files that don't reference CONFIG_OF at all.
> There are 496 more files that use of_match_ptr() as well but also
> guard something inside of CONFIG_OF. Most of these are just
> incorrectly copy-pasted from older drivers and should not have an
> #ifdef in them to make the of_match_ptr() work, but they are not actually
> usable without CONFIG_OF.
> 
> Historically, we added the #ifdef at the time when we supported hundreds
> of boards without DT and only a couple of boards with DT, so having the
> extra #ifdef was a way of ensuring that the DT conversion would not add
> a few extra bytes of .data to each driver. Now we support thousands of
> boards with DT and only a few dozen without DT, so this is all pointless.

Ack to all of this but it sounds like this will be a bit of a larger
project than I am interested in picking up right now so consider this
patch retracted with an open invitation for someone else to continue
this clean up.

Cheers,
Nathan
  

Patch

diff --git a/include/linux/of.h b/include/linux/of.h
index 766d002bddb9..f2a8d411a0f2 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -14,6 +14,7 @@ 
 #include <linux/types.h>
 #include <linux/bitops.h>
 #include <linux/errno.h>
+#include <linux/kconfig.h>
 #include <linux/kobject.h>
 #include <linux/mod_devicetable.h>
 #include <linux/spinlock.h>
@@ -405,8 +406,6 @@  extern int of_update_property(struct device_node *np, struct property *newprop);
 extern int of_attach_node(struct device_node *);
 extern int of_detach_node(struct device_node *);
 
-#define of_match_ptr(_ptr)	(_ptr)
-
 /*
  * struct property *prop;
  * const __be32 *p;
@@ -843,10 +842,11 @@  static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np)
 	return PHYS_ADDR_MAX;
 }
 
-#define of_match_ptr(_ptr)	NULL
 #define of_match_node(_matches, _node)	NULL
 #endif /* CONFIG_OF */
 
+#define of_match_ptr(_ptr)	PTR_IF(IS_ENABLED(CONFIG_OF), (_ptr))
+
 /* Default string compare functions, Allow arch asm/prom.h to override */
 #if !defined(of_compat_cmp)
 #define of_compat_cmp(s1, s2, l)	strcasecmp((s1), (s2))