Re: [PATCH v7 5/7] nvmem: core: Rework layouts to become platform devices
From: Miquel Raynal
Date: Fri Aug 04 2023 - 11:46:38 EST
Hi again Dan,
miquel.raynal@xxxxxxxxxxx wrote on Fri, 4 Aug 2023 17:39:03 +0200:
> Hi Dan,
>
> dan.carpenter@xxxxxxxxxx wrote on Thu, 3 Aug 2023 13:13:04 +0300:
>
> > Hi Miquel,
> >
> > kernel test robot noticed the following build warnings:
> >
> > https://git-scm.com/docs/git-format-patch#_base_tree_information]
> >
> > url: https://github.com/intel-lab-lkp/linux/commits/Miquel-Raynal/nvmem-core-Create-all-cells-before-adding-the-nvmem-device/20230802-022331
> > base: char-misc/char-misc-testing
> > patch link: https://lore.kernel.org/r/20230801182132.1058707-6-miquel.raynal%40bootlin.com
> > patch subject: [PATCH v7 5/7] nvmem: core: Rework layouts to become platform devices
> > config: x86_64-randconfig-m001-20230730 (https://download.01.org/0day-ci/archive/20230803/202308030002.DnSFOrMB-lkp@xxxxxxxxx/config)
> > compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
> > reproduce: (https://download.01.org/0day-ci/archive/20230803/202308030002.DnSFOrMB-lkp@xxxxxxxxx/reproduce)
> >
> > If you fix the issue in a separate patch/commit
> > (i.e. not just a new version of the same patch/commit),
>
> (Nice addition, a lot of newcomers would always add these tags
> otherwise.)
>
> > kindly add following tags
> > | Reported-by: kernel test robot <lkp@xxxxxxxxx>
> > | Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
> > | Closes: https://lore.kernel.org/r/202308030002.DnSFOrMB-lkp@xxxxxxxxx/
> >
> > New smatch warnings:
> > drivers/nvmem/core.c:1003 nvmem_register() warn: 'layout_np' is an error pointer or valid
> > drivers/nvmem/core.c:2130 nvmem_try_loading_layout_driver() warn: 'layout_np' is an error pointer or valid
> >
> > Old smatch warnings:
> > drivers/nvmem/core.c:761 nvmem_add_cells_from_fixed_layout() warn: 'layout_np' is an error pointer or valid
> > drivers/nvmem/core.c:802 nvmem_layout_get() warn: 'layout_np' is an error pointer or valid
> >
> > vim +/layout_np +1003 drivers/nvmem/core.c
> >
> > 266570f496b90d Michael Walle 2023-04-04 1000
> > 00d059fd6702f0 Miquel Raynal 2023-08-01 1001 /* Populate layouts as devices */
> > 00d059fd6702f0 Miquel Raynal 2023-08-01 1002 layout_np = of_nvmem_layout_get_container(nvmem);
> > 00d059fd6702f0 Miquel Raynal 2023-08-01 @1003 if (layout_np) {
> >
> > So, ugh, of_nvmem_layout_get_container() return NULL on error or error
> > pointer if either CONFIG_NVMEM or CONFIG_OF is turned off. I feel like
> > that's a mistake. Normally when a function returns both error pointers
> > and NULL then the NULL means the feature is disabled and the error
> > pointers mean there was an error. Here it is the opposite.
> >
> > I have written a blog about this:
> > https://staticthinking.wordpress.com/2022/08/01/mixing-error-pointers-and-null/
>
> Nice (besides the huge spider which stared at me unexpectedly :-) )
>
> > At first I thought that this was to do with CONFIG_COMPILE_TEST but
> > actually that is disabled. The issue here is that CONFIG_OF is turned
> > off. So this is a genuine bug, we're compiling a module which will
> > always crash.
> >
> > So I guess the fix is easy that this should return NULL if either
> > CONFIG_NVMEM or CONFIG_OF is turned off. That was a long explanation
> > which is no longer required now that it's not a COMPILE_TEST issue. :P
>
> I wanted to disable CONFIG_OF to make the test, I totally forget, I'll
> handle this case and return NULL when this happens.
Actually of_nvmem_layout_get_container() already returns NULL if
CONFIG_OF is not defined. This helper returns either a valid pointer of
NULL. Where can it return an error pointer?
> However I don't understand why you mention CONFIG_NVMEM, because if it
> is not defined, this file will not compile at all?
>
> > 00d059fd6702f0 Miquel Raynal 2023-08-01 1004 rval = of_platform_populate(nvmem->dev.of_node, NULL, NULL, NULL);
> > 00d059fd6702f0 Miquel Raynal 2023-08-01 1005 if (rval)
> > 00d059fd6702f0 Miquel Raynal 2023-08-01 1006 goto err_remove_cells;
> > 00d059fd6702f0 Miquel Raynal 2023-08-01 1007 of_node_put(layout_np);
> > 00d059fd6702f0 Miquel Raynal 2023-08-01 1008 }
> > 00d059fd6702f0 Miquel Raynal 2023-08-01 1009
> > 25c9b5d3aa24a0 Miquel Raynal 2023-08-01 1010 mutex_lock(&nvmem_devices_mutex);
> > 25c9b5d3aa24a0 Miquel Raynal 2023-08-01 1011 list_add_tail(&nvmem->node, &nvmem_devices_list);
> > 25c9b5d3aa24a0 Miquel Raynal 2023-08-01 1012 mutex_unlock(&nvmem_devices_mutex);
> > 25c9b5d3aa24a0 Miquel Raynal 2023-08-01 1013
> > f4853e1c321edb Bartosz Golaszewski 2019-02-15 1014 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem);
> > bee1138bea15a6 Bartosz Golaszewski 2018-09-21 1015
> > eace75cfdcf7d9 Srinivas Kandagatla 2015-07-27 1016 return nvmem;
> > 3360acdf839170 Johan Hovold 2017-06-09 1017
> > b985f4cba6dbb3 Bartosz Golaszewski 2018-09-21 1018 err_remove_cells:
> > b985f4cba6dbb3 Bartosz Golaszewski 2018-09-21 1019 nvmem_device_remove_all_cells(nvmem);
> > fa72d847d68d78 Bartosz Golaszewski 2018-09-21 1020 if (config->compat)
> > ae0c2d725512f3 Srinivas Kandagatla 2019-04-16 1021 nvmem_sysfs_remove_compat(nvmem, config);
> > 3360acdf839170 Johan Hovold 2017-06-09 1022 err_put_device:
> > 3360acdf839170 Johan Hovold 2017-06-09 1023 put_device(&nvmem->dev);
> > 3360acdf839170 Johan Hovold 2017-06-09 1024
> > b6c217ab9be689 Andrew Lunn 2016-02-26 1025 return ERR_PTR(rval);
> > eace75cfdcf7d9 Srinivas Kandagatla 2015-07-27 1026 }
> >
>
>
> Thanks,
> Miquèl
Thanks,
Miquèl