Re: [PATCH] platform/chrome: fix reference leak on failed device registration

From: Guangshuo Li

Date: Fri Apr 17 2026 - 05:17:03 EST


Hi,

On Fri, 17 Apr 2026 at 16:47, kernel test robot <lkp@xxxxxxxxx> wrote:
>
> Hi Guangshuo,
>
> kernel test robot noticed the following build errors:
>
> [auto build test ERROR on chrome-platform/for-next]
> [also build test ERROR on chrome-platform/for-firmware-next linus/master v7.0 next-20260416]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url: https://github.com/intel-lab-lkp/linux/commits/Guangshuo-Li/platform-chrome-fix-reference-leak-on-failed-device-registration/20260416-135638
> base: https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next
> patch link: https://lore.kernel.org/r/20260415175038.3633384-1-lgs201920130244%40gmail.com
> patch subject: [PATCH] platform/chrome: fix reference leak on failed device registration
> config: x86_64-randconfig-013-20260417 (https://download.01.org/0day-ci/archive/20260417/202604171609.wl8JLCit-lkp@xxxxxxxxx/config)
> compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260417/202604171609.wl8JLCit-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), kindly add following tags
> | Reported-by: kernel test robot <lkp@xxxxxxxxx>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202604171609.wl8JLCit-lkp@xxxxxxxxx/
>
> All errors (new ones prefixed by >>):
>
> >> drivers/platform/chrome/chromeos_pstore.c:131:3: error: use of undeclared identifier 'ret'
> 131 | ret = platform_device_register(&chromeos_ramoops);
> | ^
> drivers/platform/chrome/chromeos_pstore.c:132:7: error: use of undeclared identifier 'ret'
> 132 | if (ret)
> | ^
> drivers/platform/chrome/chromeos_pstore.c:135:10: error: use of undeclared identifier 'ret'
> 135 | return ret;
> | ^
> 3 errors generated.
>
>
> vim +/ret +131 drivers/platform/chrome/chromeos_pstore.c
>
> 119
> 120 static int __init chromeos_pstore_init(void)
> 121 {
> 122 bool acpi_dev_found;
> 123
> 124 if (ecc_size > 0)
> 125 chromeos_ramoops_data.ecc_info.ecc_size = ecc_size;
> 126
> 127 /* First check ACPI for non-hardcoded values from firmware. */
> 128 acpi_dev_found = chromeos_check_acpi();
> 129
> 130 if (acpi_dev_found || dmi_check_system(chromeos_pstore_dmi_table)) {
> > 131 ret = platform_device_register(&chromeos_ramoops);
> 132 if (ret)
> 133 platform_device_put(&chromeos_ramoops);
> 134
> 135 return ret;
> 136 }
> 137
> 138 return -ENODEV;
> 139 }
> 140
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki

Yes, the build error is because in the first version I accidentally
forgot to declare the local variable ret in chromeos_pstore_init().

Sorry for the oversight, and thanks for the report.

Also, the underlying issue here appears to be related to the
platform_device_register() core/API behavior. We are currently
discussing in another similar case whether the better fix, if any,
should be made in the core/API code rather than in individual callers:

https://patchew.org/linux/20260415174159.3625777-1-lgs201920130244@xxxxxxxxx/

Once that discussion reaches a conclusion, we will revisit this and
make the appropriate fix if needed.

Thanks,
Guangshuo