* [drm-i915:for-linux-next 11/18] drivers/gpu/drm/i915/i915_switcheroo.c:21 i915_switcheroo_set_state() warn: variable dereferenced before check 'i915' (see line 18)
@ 2025-08-15 20:09 ` Dan Carpenter
0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-08-15 17:01 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp, Dan Carpenter
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
TO: Jani Nikula <jani.nikula@intel.com>
CC: Gustavo Sousa <gustavo.sousa@intel.com>
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/202508160035.hmzuKiww-lkp@intel.com/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 <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202508160035.hmzuKiww-lkp@intel.com/
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 <jani.nikula@intel.com>
:::::: CC: Jani Nikula <jani.nikula@intel.com>
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread* [drm-i915:for-linux-next 11/18] drivers/gpu/drm/i915/i915_switcheroo.c:21 i915_switcheroo_set_state() warn: variable dereferenced before check 'i915' (see line 18)
@ 2025-08-15 20:09 ` Dan Carpenter
0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2025-08-15 20:09 UTC (permalink / raw)
To: oe-kbuild, Jani Nikula; +Cc: lkp, oe-kbuild-all, Gustavo Sousa
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/202508160035.hmzuKiww-lkp@intel.com/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 <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202508160035.hmzuKiww-lkp@intel.com/
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 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;
^^^^^^^^^^^^^
Patch adds a dereference
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) {
^^^^^
Checked too late.
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;
^^^^^^^^^^^^^
Dereference
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;
^^^^
The old code assumed that i915 could be NULL.
63bf8301aac492 Jani Nikula 2019-10-04 56 }
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [drm-i915:for-linux-next 11/18] drivers/gpu/drm/i915/i915_switcheroo.c:21 i915_switcheroo_set_state() warn: variable dereferenced before check 'i915' (see line 18)
2025-08-15 20:09 ` Dan Carpenter
(?)
@ 2025-08-18 7:18 ` Jani Nikula
2025-08-18 8:07 ` Dan Carpenter
-1 siblings, 1 reply; 5+ messages in thread
From: Jani Nikula @ 2025-08-18 7:18 UTC (permalink / raw)
To: Dan Carpenter, oe-kbuild; +Cc: lkp, oe-kbuild-all, Gustavo Sousa
On Fri, 15 Aug 2025, Dan Carpenter <dan.carpenter@linaro.org> wrote:
> 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/202508160035.hmzuKiww-lkp@intel.com/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 <lkp@intel.com>
> | Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> | Closes: https://lore.kernel.org/r/202508160035.hmzuKiww-lkp@intel.com/
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
> 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)
Thanks for the report, fix at [1].
BR,
Jani.
[1] https://lore.kernel.org/r/20250818071605.2541523-1-jani.nikula@intel.com
--
Jani Nikula, Intel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [drm-i915:for-linux-next 11/18] drivers/gpu/drm/i915/i915_switcheroo.c:21 i915_switcheroo_set_state() warn: variable dereferenced before check 'i915' (see line 18)
2025-08-18 7:18 ` Jani Nikula
@ 2025-08-18 8:07 ` Dan Carpenter
2025-08-18 11:57 ` Jani Nikula
0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2025-08-18 8:07 UTC (permalink / raw)
To: Jani Nikula; +Cc: oe-kbuild, lkp, oe-kbuild-all, Gustavo Sousa
On Mon, Aug 18, 2025 at 10:18:14AM +0300, Jani Nikula wrote:
> On Fri, 15 Aug 2025, Dan Carpenter <dan.carpenter@linaro.org> wrote:
> > 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/202508160035.hmzuKiww-lkp@intel.com/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 <lkp@intel.com>
> > | Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> > | Closes: https://lore.kernel.org/r/202508160035.hmzuKiww-lkp@intel.com/
>
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [drm-i915:for-linux-next 11/18] drivers/gpu/drm/i915/i915_switcheroo.c:21 i915_switcheroo_set_state() warn: variable dereferenced before check 'i915' (see line 18)
2025-08-18 8:07 ` Dan Carpenter
@ 2025-08-18 11:57 ` Jani Nikula
0 siblings, 0 replies; 5+ messages in thread
From: Jani Nikula @ 2025-08-18 11:57 UTC (permalink / raw)
To: Dan Carpenter; +Cc: oe-kbuild, lkp, oe-kbuild-all, Gustavo Sousa
On Mon, 18 Aug 2025, Dan Carpenter <dan.carpenter@linaro.org> wrote:
> On Mon, Aug 18, 2025 at 10:18:14AM +0300, Jani Nikula wrote:
>> On Fri, 15 Aug 2025, Dan Carpenter <dan.carpenter@linaro.org> wrote:
>> > 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/202508160035.hmzuKiww-lkp@intel.com/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 <lkp@intel.com>
>> > | Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
>> > | Closes: https://lore.kernel.org/r/202508160035.hmzuKiww-lkp@intel.com/
>>
>> 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.
--
Jani Nikula, Intel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-18 11:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-15 17:01 [drm-i915:for-linux-next 11/18] drivers/gpu/drm/i915/i915_switcheroo.c:21 i915_switcheroo_set_state() warn: variable dereferenced before check 'i915' (see line 18) kernel test robot
2025-08-15 20:09 ` Dan Carpenter
2025-08-18 7:18 ` Jani Nikula
2025-08-18 8:07 ` Dan Carpenter
2025-08-18 11:57 ` Jani Nikula
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.