drm/i915/switcheroo: check for NULL before dereferencing
Subsystems (2)
PATCH 1/1 drm/i915/switcheroo: check for NULL before dereferencing
Both i915_switcheroo_set_state() and i915_switcheroo_can_switch() check for i915 == NULL. Commit d2e184f8e16a ("drm/i915/switcheroo: pass display to HAS_DISPLAY()") started dereferencing it before the NULL check. Fix it.
--- drivers/gpu/drm/i915/i915_switcheroo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_switcheroo.c +2 -2
@@ -15,7 +15,7 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) {struct drm_i915_private *i915 =pdev_to_i915 (pdev); -struct intel_display *display = i915->display; +struct intel_display *display = i915 ? i915->display :NULL ;pm_message_t pmm = { .event =PM_EVENT_SUSPEND };if (!i915) {
@@ -45,7 +45,7 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev,static bool i915_switcheroo_can_switch (struct pci_dev *pdev) {struct drm_i915_private *i915 =pdev_to_i915 (pdev); -struct intel_display *display = i915->display; +struct intel_display *display = i915 ? i915->display :NULL ;/* * FIXME: open_count is protected by drm_global_mutex but that would lead to
Signature · 1 line
2.47.2
Patchwork
CI✓ i915.CI.BAT: success for drm/i915/switcheroo: check for NULL before dereferencing
== Series Details ==
== Series Details ==
Series: drm/i915/switcheroo: check for NULL before dereferencing
URL : https://patchwork.freedesktop.org/series/153039/
State : success
== Summary ==
CI Bug Log - changes from CI_DRM_17021 -> Patchwork_153039v1
====================================================
Summary
-------
**SUCCESS**
No regressions found.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_153039v1/index.html
Participating hosts (43 -> 42)
------------------------------
Missing (1): fi-snb-2520m
Changes
-------
No changes found
Build changes
-------------
* Linux: CI_DRM_17021 -> Patchwork_153039v1
CI-20190529: 20190529
CI_DRM_17021: 2109e38df4c111216f291cde8fd0f7eede4ebd62 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_8495: b412b144685feadfd5675f3108de3d6820a4d1db @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_153039v1: 2109e38df4c111216f291cde8fd0f7eede4ebd62 @ git://anongit.freedesktop.org/gfx-ci/linux
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_153039v1/index.html
Patchwork
CI✓ i915.CI.Full: success for drm/i915/switcheroo: check for NULL before dereferencing
In reply to Jani Nikula== Series Details ==
== Series Details ==
Series: drm/i915/switcheroo: check for NULL before dereferencing
URL : https://patchwork.freedesktop.org/series/153039/
State : success
== Summary ==
CI Bug Log - changes from CI_DRM_17021_full -> Patchwork_153039v1_full
====================================================
Summary
-------
**SUCCESS**
No regressions found.
Participating hosts (13 -> 13)
------------------------------
No changes in participating hosts
Changes
-------
No changes found
Build changes
-------------
* Linux: CI_DRM_17021 -> Patchwork_153039v1
CI-20190529: 20190529
CI_DRM_17021: 2109e38df4c111216f291cde8fd0f7eede4ebd62 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_8495: b412b144685feadfd5675f3108de3d6820a4d1db @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_153039v1: 2109e38df4c111216f291cde8fd0f7eede4ebd62 @ git://anongit.freedesktop.org/gfx-ci/linux
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_153039v1/index.html
Quoting Jani Nikula (2025-08-18 04:16:05-03:00)
Quoted 4 lines
Both
i915_switcheroo_set_state()andi915_switcheroo_can_switch()check for i915 == NULL. Commitd2e184f8e16a("drm/i915/switcheroo: pass display toHAS_DISPLAY()") started dereferencing it before the NULL check. Fix it.
Hm... Did it? I think i915->display will only give you an invalid address when i915 is NULL, but I don't think any dereferencing will happen, because of the checks on i915.
Anyways, playing it safe here is probably a good idea. I would just reword the commit message a bit. With that,
Quoted 36 lines
Fixes d2e184f8e16a ("drm/i915/switcheroo: pass display to HAS_DISPLAY()")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Cc Gustavo Sousa <[email protected]>Signed-off-by Jani Nikula <[email protected]>---
drivers/gpu/drm/i915/i915_switcheroo.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_switcheroo.c +2
-2@@ -15,7 +15,7 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) {struct drm_i915_private *i915 =pdev_to_i915 (pdev); -struct intel_display *display = i915->display; +struct intel_display *display = i915 ? i915->display :NULL ;pm_message_t pmm = { .event =PM_EVENT_SUSPEND };if (!i915) {@@ -45,7 +45,7 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev,static bool i915_switcheroo_can_switch (struct pci_dev *pdev) {struct drm_i915_private *i915 =pdev_to_i915 (pdev); -struct intel_display *display = i915->display; +struct intel_display *display = i915 ? i915->display :NULL ;/* * FIXME: open_count is protected by drm_global_mutex but that would lead to Signature · 1 line
2.47.2
Quoted 9 lines · Gustavo Sousa
Quoting Jani Nikula (2025-08-18 04:16:05-03:00)
Quoted 4 lines
Both
i915_switcheroo_set_state()andi915_switcheroo_can_switch()check for i915 == NULL. Commitd2e184f8e16a("drm/i915/switcheroo: pass display toHAS_DISPLAY()") started dereferencing it before the NULL check. Fix it.Hm... Did it? I think
i915->displaywill only give you an invalid address when i915 is NULL, but I don't think any dereferencing will happen, because of the checks on i915.
What would be the case for &i915->display, but not i915->display?
Quoted 5 lines
Anyways, playing it safe here is probably a good idea. I would just reword the commit message a bit. With that,
Reviewed-by Gustavo Sousa <[email protected]>
Thanks.
Quoted 37 lines
Quoted 37 lines
Fixes d2e184f8e16a ("drm/i915/switcheroo: pass display to HAS_DISPLAY()")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Cc Gustavo Sousa <[email protected]>Signed-off-by Jani Nikula <[email protected]>---
drivers/gpu/drm/i915/i915_switcheroo.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_switcheroo.c +2
-2@@ -15,7 +15,7 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) {struct drm_i915_private *i915 =pdev_to_i915 (pdev); -struct intel_display *display = i915->display; +struct intel_display *display = i915 ? i915->display :NULL ;pm_message_t pmm = { .event =PM_EVENT_SUSPEND };if (!i915) {@@ -45,7 +45,7 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev,static bool i915_switcheroo_can_switch (struct pci_dev *pdev) {struct drm_i915_private *i915 =pdev_to_i915 (pdev); -struct intel_display *display = i915->display; +struct intel_display *display = i915 ? i915->display :NULL ;/* * FIXME: open_count is protected by drm_global_mutex but that would lead to Signature · 1 line
2.47.2
Signature · 1 line
Jani Nikula, Intel
Quoting Jani Nikula (2025-08-18 10:30:30-03:00)
Quoted 7 lines · Gustavo Sousa
Quoted 6 lines
Quoting Jani Nikula (2025-08-18 04:16:05-03:00)
Quoted 4 lines
Both
i915_switcheroo_set_state()andi915_switcheroo_can_switch()check for i915 == NULL. Commitd2e184f8e16a("drm/i915/switcheroo: pass display toHAS_DISPLAY()") started dereferencing it before the NULL check. Fix it.
Quoted 5 lines
Quoted 3 lines
Hm... Did it? I think
i915->displaywill only give you an invalid address when i915 is NULL, but I don't think any dereferencing will happen, because of the checks on i915.What would be the case for
&i915->display, but noti915->display?
Ah, right.
Yeah, I got confused thinking this was the same as the old times when we stored display directly in the structure. In that case, we would use &i915->display and no dereferencing would happen.
Now we store a pointer to the display in i915 and we need dereferencing in order to get the address.
Sorry for the noise!
--
Gustavo Sousa
Quoted 49 lines
Quoted 6 lines
Anyways, playing it safe here is probably a good idea. I would just reword the commit message a bit. With that,
Reviewed-by Gustavo Sousa <[email protected]>Thanks.
Quoted 37 lines
Quoted 37 lines
Fixes d2e184f8e16a ("drm/i915/switcheroo: pass display to HAS_DISPLAY()")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Cc Gustavo Sousa <[email protected]>Signed-off-by Jani Nikula <[email protected]>---
drivers/gpu/drm/i915/i915_switcheroo.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_switcheroo.c +2
-2@@ -15,7 +15,7 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) {struct drm_i915_private *i915 =pdev_to_i915 (pdev); -struct intel_display *display = i915->display; +struct intel_display *display = i915 ? i915->display :NULL ;pm_message_t pmm = { .event =PM_EVENT_SUSPEND };if (!i915) {@@ -45,7 +45,7 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev,static bool i915_switcheroo_can_switch (struct pci_dev *pdev) {struct drm_i915_private *i915 =pdev_to_i915 (pdev); -struct intel_display *display = i915->display; +struct intel_display *display = i915 ? i915->display :NULL ;/* * FIXME: open_count is protected by drm_global_mutex but that would lead to Signature · 1 line
2.47.2Signature · 1 line
Jani Nikula, Intel
Quoted 16 lines · Gustavo Sousa
Quoting Jani Nikula (2025-08-18 10:30:30-03:00)
Quoted 7 lines · Gustavo Sousa
Quoted 6 lines
Quoting Jani Nikula (2025-08-18 04:16:05-03:00)
Quoted 4 lines
Both
i915_switcheroo_set_state()andi915_switcheroo_can_switch()check for i915 == NULL. Commitd2e184f8e16a("drm/i915/switcheroo: pass display toHAS_DISPLAY()") started dereferencing it before the NULL check. Fix it.Quoted 5 lines
Quoted 3 lines
Hm... Did it? I think
i915->displaywill only give you an invalid address when i915 is NULL, but I don't think any dereferencing will happen, because of the checks on i915.What would be the case for
&i915->display, but noti915->display?Ah, right.
Quoted 8 lines
Yeah, I got confused thinking this was the same as the old times when we stored display directly in the structure. In that case, we would use
&i915->displayand no dereferencing would happen.Now we store a pointer to the display in i915 and we need dereferencing in order to get the address.
Sorry for the noise!
Good to clarify!
Thanks for the review, pushed to din.
BR,
Jani.
Quoted 53 lines
--
Gustavo SousaQuoted 49 lines
Quoted 6 lines
Anyways, playing it safe here is probably a good idea. I would just reword the commit message a bit. With that,
Reviewed-by Gustavo Sousa <[email protected]>Thanks.
Quoted 37 lines
Quoted 37 lines
Fixes d2e184f8e16a ("drm/i915/switcheroo: pass display to HAS_DISPLAY()")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Cc Gustavo Sousa <[email protected]>Signed-off-by Jani Nikula <[email protected]>---
drivers/gpu/drm/i915/i915_switcheroo.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_switcheroo.c +2
-2@@ -15,7 +15,7 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) {struct drm_i915_private *i915 =pdev_to_i915 (pdev); -struct intel_display *display = i915->display; +struct intel_display *display = i915 ? i915->display :NULL ;pm_message_t pmm = { .event =PM_EVENT_SUSPEND };if (!i915) {@@ -45,7 +45,7 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev,static bool i915_switcheroo_can_switch (struct pci_dev *pdev) {struct drm_i915_private *i915 =pdev_to_i915 (pdev); -struct intel_display *display = i915->display; +struct intel_display *display = i915 ? i915->display :NULL ;/* * FIXME: open_count is protected by drm_global_mutex but that would lead to Signature · 1 line
2.47.2Signature · 1 line
Jani Nikula, Intel
Signature · 1 line
Jani Nikula, Intel