drivers/gpu/drm/i915/i915_switcheroo.c:21 i915_switcheroo_set_state() warn: variable dereferenced before check 'i915' (see line 18)
kernel test robot
build botBCC: [email protected]
CC: [email protected]
TO: Jani Nikula <[email protected]>
CC: Gustavo Sousa <[email protected]>
tree: https://gitlab.freedesktop.org/drm/i915/kernel for-linux-next head: 63e0b17ae79a4365e874d7e2ff3816db2e6d55b5 commit: d2e184f8e16ab85876ddcc0779358fbfe5162414 [11/18] drm/i915/switcheroo: pass display to HAS_DISPLAY()
:::::: branch date: 6 hours ago
:::::: commit date: 31 hours ago
config: i386-randconfig-141-20250815 (https://download.01.org/0day-ci/archive/20250816/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
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 <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
smatch warnings:drivers/gpu/drm/i915/i915_switcheroo.c:21 i915_switcheroo_set_state() warn: variable dereferenced before check 'i915' (see line 18) drivers/gpu/drm/i915/i915_switcheroo.c:55 i915_switcheroo_can_switch() warn: variable dereferenced before check 'i915' (see line 48)
vim +/i915 +21 drivers/gpu/drm/i915/i915_switcheroo.c
63bf8301aac492 Jani Nikula 2019-10-04 13
63bf8301aac492 Jani Nikula 2019-10-04 14 static void i915_switcheroo_set_state(struct pci_dev *pdev,
63bf8301aac492 Jani Nikula 2019-10-04 15 enum vga_switcheroo_state state)
63bf8301aac492 Jani Nikula 2019-10-04 16 {
63bf8301aac492 Jani Nikula 2019-10-04 17 struct drm_i915_private *i915 = pdev_to_i915(pdev);
d2e184f8e16ab8 Jani Nikula 2025-08-06 @18 struct intel_display *display = i915->display;
63bf8301aac492 Jani Nikula 2019-10-04 19 pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
63bf8301aac492 Jani Nikula 2019-10-04 20
63bf8301aac492 Jani Nikula 2019-10-04 @21 if (!i915) {
63bf8301aac492 Jani Nikula 2019-10-04 22 dev_err(&pdev->dev, "DRM not initialized, aborting switch.\n");
63bf8301aac492 Jani Nikula 2019-10-04 23 return;
63bf8301aac492 Jani Nikula 2019-10-04 24 }
d2e184f8e16ab8 Jani Nikula 2025-08-06 25 if (!HAS_DISPLAY(display)) {
a273e95721e968 Thomas Zimmermann 2023-01-16 26 dev_err(&pdev->dev, "Device state not initialized, aborting switch.\n");
a273e95721e968 Thomas Zimmermann 2023-01-16 27 return;
a273e95721e968 Thomas Zimmermann 2023-01-16 28 }
63bf8301aac492 Jani Nikula 2019-10-04 29
63bf8301aac492 Jani Nikula 2019-10-04 30 if (state == VGA_SWITCHEROO_ON) {
f54efb6ad03322 Jani Nikula 2020-04-02 31 drm_info(&i915->drm, "switched on\n");
63bf8301aac492 Jani Nikula 2019-10-04 32 i915->drm.switch_power_state = DRM_SWITCH_POWER_CHANGING;
63bf8301aac492 Jani Nikula 2019-10-04 33 /* i915 resume handler doesn't set to D0 */
63bf8301aac492 Jani Nikula 2019-10-04 34 pci_set_power_state(pdev, PCI_D0);
b8d65b8a5aea33 Jani Nikula 2021-11-11 35 i915_driver_resume_switcheroo(i915);
63bf8301aac492 Jani Nikula 2019-10-04 36 i915->drm.switch_power_state = DRM_SWITCH_POWER_ON;
63bf8301aac492 Jani Nikula 2019-10-04 37 } else {
f54efb6ad03322 Jani Nikula 2020-04-02 38 drm_info(&i915->drm, "switched off\n");
63bf8301aac492 Jani Nikula 2019-10-04 39 i915->drm.switch_power_state = DRM_SWITCH_POWER_CHANGING;
b8d65b8a5aea33 Jani Nikula 2021-11-11 40 i915_driver_suspend_switcheroo(i915, pmm);
63bf8301aac492 Jani Nikula 2019-10-04 41 i915->drm.switch_power_state = DRM_SWITCH_POWER_OFF;
63bf8301aac492 Jani Nikula 2019-10-04 42 }
63bf8301aac492 Jani Nikula 2019-10-04 43 }
63bf8301aac492 Jani Nikula 2019-10-04 44
63bf8301aac492 Jani Nikula 2019-10-04 45 static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
63bf8301aac492 Jani Nikula 2019-10-04 46 {
63bf8301aac492 Jani Nikula 2019-10-04 47 struct drm_i915_private *i915 = pdev_to_i915(pdev);
d2e184f8e16ab8 Jani Nikula 2025-08-06 @48 struct intel_display *display = i915->display;
63bf8301aac492 Jani Nikula 2019-10-04 49
63bf8301aac492 Jani Nikula 2019-10-04 50 /*
63bf8301aac492 Jani Nikula 2019-10-04 51 * FIXME: open_count is protected by drm_global_mutex but that would lead to
63bf8301aac492 Jani Nikula 2019-10-04 52 * locking inversion with the driver load path. And the access here is
63bf8301aac492 Jani Nikula 2019-10-04 53 * completely racy anyway. So don't bother with locking for now.
63bf8301aac492 Jani Nikula 2019-10-04 54 */
d2e184f8e16ab8 Jani Nikula 2025-08-06 @55 return i915 && HAS_DISPLAY(display) && atomic_read(&i915->drm.open_count) == 0;
63bf8301aac492 Jani Nikula 2019-10-04 56 }
63bf8301aac492 Jani Nikula 2019-10-04 57 :::::: The code at line 21 was first introduced by commit
:::::: 63bf8301aac492d4c5fdf7b0ec42b142c05080e3 drm/i915: split out i915_switcheroo.[ch] from i915_drv.c
:::::: TO: Jani Nikula <[email protected]>
:::::: CC: Jani Nikula <[email protected]>
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 11 lines · Dan Carpenter
tree: https://gitlab.freedesktop.org/drm/i915/kernel for-linux-next head: 63e0b17ae79a4365e874d7e2ff3816db2e6d55b5 commit: d2e184f8e16ab85876ddcc0779358fbfe5162414 [11/18] drm/i915/switcheroo: pass display to HAS_DISPLAY() config: i386-randconfig-141-20250815 (https://download.01.org/0day-ci/archive/20250816/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)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 <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
Side note, this triplet of tags leads to checkpatch warning:
WARNING:BAD_REPORTED_BY_LINK: Reported-by: should be immediately followed by Closes: with a URL to the report
Quoted 3 lines
smatch warnings:
drivers/gpu/drm/i915/i915_switcheroo.c:21i915_switcheroo_set_state()warn: variable dereferenced before check 'i915' (see line 18)drivers/gpu/drm/i915/i915_switcheroo.c:55i915_switcheroo_can_switch()warn: variable dereferenced before check 'i915' (see line 48)
Thanks for the report, fix at [1].
BR,
Jani.
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Jani Nikula, Intel
Quoted 13 lines · Jani Nikula
Quoted 11 lines · Dan Carpenter
tree: https://gitlab.freedesktop.org/drm/i915/kernel for-linux-next head: 63e0b17ae79a4365e874d7e2ff3816db2e6d55b5 commit: d2e184f8e16ab85876ddcc0779358fbfe5162414 [11/18] drm/i915/switcheroo: pass display to HAS_DISPLAY() config: i386-randconfig-141-20250815 (https://download.01.org/0day-ci/archive/20250816/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)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 <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
Quoted 5 lines
Side note, this triplet of tags leads to checkpatch warning:
WARNING:BAD_REPORTED_BY_LINK: Reported-by: should be immediately followed by Closes: with a URL to the report
It's hard to know what to do about that... There is only one link but both zero day and I rely on Reported-by tags to justify our saleries..
regards,
dan carpenter
Quoted 14 lines · Dan Carpenter
Quoted 13 lines · Jani Nikula
Quoted 11 lines · Dan Carpenter
tree: https://gitlab.freedesktop.org/drm/i915/kernel for-linux-next head: 63e0b17ae79a4365e874d7e2ff3816db2e6d55b5 commit: d2e184f8e16ab85876ddcc0779358fbfe5162414 [11/18] drm/i915/switcheroo: pass display to HAS_DISPLAY() config: i386-randconfig-141-20250815 (https://download.01.org/0day-ci/archive/20250816/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)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 <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
Quoted 8 lines
Quoted 5 lines
Side note, this triplet of tags leads to checkpatch warning:
WARNING:BAD_REPORTED_BY_LINK: Reported-by: should be immediately followed by Closes: with a URL to the report
It's hard to know what to do about that... There is only one link but both zero day and I rely on Reported-by tags to justify our saleries..
Make checkpatch allow multiple reported by for one mail? *shrug*
BR,
Jani.
Signature · 1 line
Jani Nikula, Intel