Skip to contentSkip to conversation

i2c: designware: amdisp: Fix null pointer dereference in runtime resume

PATCH In review Pratap Nirujogi 4 participants 9 messages Mar 9 – Mar 20

Subsystems (4)
lore
Share & tools
lore

Pratap Nirujogi

author maintainer
#0 lore raw

PATCH 1/1 i2c: designware: amdisp: Fix null pointer dereference in runtime resume

Add NULL check for i_dev->map before calling i2c_dw_init() in the runtime resume path. The regmap may not be initialized yet when runtime PM tries to resume the device early in the probe sequence, leading to a NULL pointer dereference. Skip the i2c_dw_init() call if regmap is not yet created.

This race condition occurs when runtime PM resume is triggered before i2c_dw_probe() completes the regmap initialization and was observed in kernel v7.0 where the order of device enumeration has changed because of the changes in registering the device sources in the device hierarchy.

Fixes 02c057ddefef ("ACPI: video: Convert the driver to a platform one")
---
 drivers/i2c/busses/i2c-designware-amdisp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-amdisp.c +4 -1
index c48728ad9f6f2..cd7ee55fbe1ee 100644
@@ -153,7 +153,10 @@ static int amd_isp_dw_i2c_plat_runtime_resume(struct device *dev)
 		return -ENODEV;
 
 	i2c_dw_prepare_clk(i_dev, true);
-	i2c_dw_init(i_dev);
+
+	/* Skip i2c_dw_init if regmap not yet created by i2c_dw_probe */
+	if (i_dev->map)
+		i2c_dw_init(i_dev);
 
 	return 0;
 }
Signature · 1 line
2.43.0
#1 lore raw
Quoted 6 lines · Pratap Nirujogi

Add NULL check for i_dev->map before calling i2c_dw_init() in the runtime resume path. The regmap may not be initialized yet when runtime PM tries to resume the device early in the probe sequence, leading to a NULL pointer dereference. Skip the i2c_dw_init() call if regmap is not yet created.

Quoted 7 lines

This race condition occurs when runtime PM resume is triggered before i2c_dw_probe() completes the regmap initialization and was observed in kernel v7.0 where the order of device enumeration has changed because of the changes in registering the device sources in the device hierarchy.

Fixes 02c057ddefef ("ACPI: video: Convert the driver to a platform one")

Is this the right commit that introduced the race? Did it change the timing?

Or was the race always there and we just got lucky until that commit went in?

Quoted 21 lines
---
  drivers/i2c/busses/i2c-designware-amdisp.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-amdisp.c +4 -1
index c48728ad9f6f2..cd7ee55fbe1ee 100644
@@ -153,7 +153,10 @@ static int amd_isp_dw_i2c_plat_runtime_resume(struct device *dev)
  		return -ENODEV;
 
  	i2c_dw_prepare_clk(i_dev, true);
-	i2c_dw_init(i_dev);
+
+	/* Skip i2c_dw_init if regmap not yet created by i2c_dw_probe */
+	if (i_dev->map)
+		i2c_dw_init(i_dev);
 
  	return 0;
  }
#2 lore raw

Hi Mario,

Quoted 14 lines · Mario Limonciello
Quoted 11 lines · Pratap Nirujogi

Add NULL check for i_dev->map before calling i2c_dw_init() in the runtime resume path. The regmap may not be initialized yet when runtime PM tries to resume the device early in the probe sequence, leading to a NULL pointer dereference. Skip the i2c_dw_init() call if regmap is not yet created.

This race condition occurs when runtime PM resume is triggered before i2c_dw_probe() completes the regmap initialization and was observed in kernel v7.0 where the order of device enumeration has changed because of the changes in registering the device sources in the device hierarchy.

Quoted 7 lines
Quoted 2 lines
Fixes 02c057ddefef ("ACPI: video: Convert the driver to a platform one")

Is this the right commit that introduced the race?  Did it change the timing?

Or was the race always there and we just got lucky until that commit went in?

My apologies for mixing up this change along with other changes that were needed to fix the AMD ISP driver regressions in v7.0.

I investigated further and found that this issue was exposed by the below commit.

https://github.com/torvalds/linux/commit/38fa29b01a6a295aedb69d1bbdad70acd7d204c6

However, the resume‑probe race condition existed even earlier and had not surfaced because device initialization in resume is done only when init handle is valid.

Here is some background and context on this change:

The amdisp i2c device requires ISP to be in power on state for probe to succeed. To meet this requirement, we added this device, which is a amdgpu MFD child to the genpd, to control isp power using runtime PM. The pm_runtime_get_sync() call before probe triggers a PM resume, which powers on the ISP and also invokes the amdisp i2c runtime resume before the probe completes resulting in this race condition.

To fix this issue properly, I’m considering this change. Please review and share your feedback on whether this makes sense.

- Call dev_pm_genpd_resume() to Power ON ISP before probe
- Call dev_pm_genpd_suspend() to Power OFF ISP after probe
- Call pm_runtime_enable() after probe is successful to take care of system suspend/resume.

drivers/i2c/busses/i2c-designware-amdisp.c +5 -6
index 19de518be30a4..9ce58522951cd 100644
@@ -7,6 +7,7 @@
 
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 #include <linux/soc/amd/isp4_misc.h>
 
@@ -76,9 +77,7 @@ static int amd_isp_dw_i2c_plat_probe(struct platform_device *pdev)
 
        device_enable_async_suspend(&pdev->dev);
 
-       pm_runtime_enable(&pdev->dev);
-       pm_runtime_get_sync(&pdev->dev);
-
+       dev_pm_genpd_resume(&pdev->dev);
        ret = i2c_dw_probe(isp_i2c_dev);
        if (ret) {
@@ -86,14 +85,14 @@ static int amd_isp_dw_i2c_plat_probe(struct platform_device *pdev)
                goto error_release_rpm;
        }
-
-       pm_runtime_put_sync(&pdev->dev);
+       dev_pm_genpd_suspend(&pdev->dev);
+       pm_runtime_set_suspended(&pdev->dev);
+       pm_runtime_enable(&pdev->dev);
 
        return 0;
 
 error_release_rpm:
        amd_isp_dw_i2c_plat_pm_cleanup(isp_i2c_dev);
-       pm_runtime_put_sync(&pdev->dev);
        return ret;
 }
 

Thanks,
Pratap

Quoted 21 lines
Quoted 20 lines

---
  drivers/i2c/busses/i2c-designware-amdisp.c | 5 ++++-

  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-amdisp.c +4 -1
index c48728ad9f6f2..cd7ee55fbe1ee 100644
@@ -153,7 +153,10 @@ static int 
 amd_isp_dw_i2c_plat_runtime_resume(struct device *dev)
           return -ENODEV;
       i2c_dw_prepare_clk(i_dev, true);
-    i2c_dw_init(i_dev);
+
+    /* Skip i2c_dw_init if regmap not yet created by i2c_dw_probe */
+    if (i_dev->map)
+        i2c_dw_init(i_dev);
       return 0;
   }
#3 lore raw
Quoted 2 lines · Pratap
Quoted 1 line · Mario Limonciello

On 3/9/2026 5:00 PM, Pratap Nirujogi wrote:

...

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Fixes 02c057ddefef ("ACPI: video: Convert the driver to a platform one")

Is this the right commit that introduced the race?  Did it change the timing?

Or was the race always there and we just got lucky until that commit went in?

Quoted 7 lines

My apologies for mixing up this change along with other changes that were needed to fix the AMD ISP driver regressions in v7.0.

I investigated further and found that this issue was exposed by the below commit.

https://github.com/torvalds/linux/commit/38fa29b01a6a295aedb69d1bbdad70acd7d204c6

Still it might be not a culprit as at that point the device should be in power on state.

Quoted 3 lines

However, the resume‑probe race condition existed even earlier and had not surfaced because device initialization in resume is done only when init handle is valid.

That's what the initial cause, the AMD ISP driver initially relies on the broken (racy) behaviour. So, the original patch d6263c468a761 does not explain that bit. You need to go deeper and understand why the heck that condition is present there.

Quoted 1 line

Here is some background and context on this change:

Exactly, the below seems that you have nailed it down.

Quoted 7 lines

The amdisp i2c device requires ISP to be in power on state for probe to succeed. To meet this requirement, we added this device, which is a amdgpu MFD child to the genpd, to control isp power using runtime PM. The pm_runtime_get_sync() call before probe triggers a PM resume, which powers on the ISP and also invokes the amdisp i2c runtime resume before the probe completes resulting in this race condition.

Quoted 7 lines

To fix this issue properly, I’m considering this change. Please review and share your feedback on whether this makes sense.

- Call dev_pm_genpd_resume() to Power ON ISP before probe
- Call dev_pm_genpd_suspend() to Power OFF ISP after probe
- Call pm_runtime_enable() after probe is successful to take care of system suspend/resume.

I don't know the scope of dev_pm_genpd_*() usage, but the description of the proposed change sounds sane. And definitely it's much much better than previous attempt.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 51 lines · Andy Shevchenko

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 2 lines · Pratap
Quoted 1 line · Mario Limonciello

On 3/9/2026 5:00 PM, Pratap Nirujogi wrote:

...

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Fixes 02c057ddefef ("ACPI: video: Convert the driver to a platform one")

Is this the right commit that introduced the race? Did it change the timing?

Or was the race always there and we just got lucky until that commit went in?

Quoted 7 lines

My apologies for mixing up this change along with other changes that were needed to fix the AMD ISP driver regressions in v7.0.

I investigated further and found that this issue was exposed by the below commit.

https://github.com/torvalds/linux/commit/38fa29b01a6a295aedb69d1bbdad70acd7d204c6

Still it might be not a culprit as at that point the device should be in power on state.

Quoted 3 lines

However, the resume‑probe race condition existed even earlier and had not surfaced because device initialization in resume is done only when init handle is valid.

That's what the initial cause, the AMD ISP driver initially relies on the broken (racy) behaviour. So, the original patch d6263c468a761 does not explain that bit. You need to go deeper and understand why the heck that condition is present there.

Quoted 1 line

Here is some background and context on this change:

Exactly, the below seems that you have nailed it down.

Quoted 10 lines

The amdisp i2c device requires ISP to be in power on state for probe to succeed. To meet this requirement, we added this device, which is a amdgpu MFD child to the genpd, to control isp power using runtime PM. The pm_runtime_get_sync() call before probe triggers a PM resume, which powers on the ISP and also invokes the amdisp i2c runtime resume before the probe completes resulting in this race condition.

To fix this issue properly, I’m considering this change. Please review and share your feedback on whether this makes sense.

Quoted 9 lines
Quoted 4 lines

- Call dev_pm_genpd_resume() to Power ON ISP before probe
- Call dev_pm_genpd_suspend() to Power OFF ISP after probe
- Call pm_runtime_enable() after probe is successful to take care of system suspend/resume.

I don't know the scope of dev_pm_genpd_*() usage, but the description of the proposed change sounds sane. And definitely it's much much better than previous attempt.

Thanks, Andy, for the feedback and comments. I’ll send out v2 with the proposed changes.

Thanks,
Pratap

Quoted 5 lines

--
With Best Regards,
Andy Shevchenko

#5 lore raw
In reply to Nirujogi, Pratap
Quoted 74 lines · Pratap

Hi Mario,

Quoted 14 lines · Mario Limonciello
Quoted 11 lines · Pratap Nirujogi

Add NULL check for i_dev->map before calling i2c_dw_init() in the runtime resume path. The regmap may not be initialized yet when runtime PM tries to resume the device early in the probe sequence, leading to a NULL pointer dereference. Skip the i2c_dw_init() call if regmap is not yet created.

This race condition occurs when runtime PM resume is triggered before i2c_dw_probe() completes the regmap initialization and was observed in kernel v7.0 where the order of device enumeration has changed because of the changes in registering the device sources in the device hierarchy.

Quoted 7 lines
Quoted 2 lines
Fixes 02c057ddefef ("ACPI: video: Convert the driver to a platform one")

Is this the right commit that introduced the race?  Did it change the timing?

Or was the race always there and we just got lucky until that commit went in?

My apologies for mixing up this change along with other changes that were needed to fix the AMD ISP driver regressions in v7.0.

I investigated further and found that this issue was exposed by the below commit.

https://github.com/torvalds/linux/ commit/38fa29b01a6a295aedb69d1bbdad70acd7d204c6

However, the resume‑probe race condition existed even earlier and had not surfaced because device initialization in resume is done only when init handle is valid.

Here is some background and context on this change:

The amdisp i2c device requires ISP to be in power on state for probe to succeed. To meet this requirement, we added this device, which is a amdgpu MFD child to the genpd, to control isp power using runtime PM. The pm_runtime_get_sync() call before probe triggers a PM resume, which powers on the ISP and also invokes the amdisp i2c runtime resume before the probe completes resulting in this race condition.

To fix this issue properly, I’m considering this change. Please review and share your feedback on whether this makes sense.

- Call dev_pm_genpd_resume() to Power ON ISP before probe
- Call dev_pm_genpd_suspend() to Power OFF ISP after probe
- Call pm_runtime_enable() after probe is successful to take care of system suspend/resume.

drivers/i2c/busses/i2c-designware-amdisp.c +4 -5
index 19de518be30a4..9ce58522951cd 100644
@@ -7,6 +7,7 @@
 
  #include <linux/module.h>
  #include <linux/platform_device.h>
+#include <linux/pm_domain.h>
  #include <linux/pm_runtime.h>
  #include <linux/soc/amd/isp4_misc.h>
 
@@ -76,9 +77,7 @@ static int amd_isp_dw_i2c_plat_probe(struct 
 platform_device *pdev)
 
         device_enable_async_suspend(&pdev->dev);
 
-       pm_runtime_enable(&pdev->dev);
-       pm_runtime_get_sync(&pdev->dev);
-
+       dev_pm_genpd_resume(&pdev->dev);
         ret = i2c_dw_probe(isp_i2c_dev);
         if (ret) {
@@ -86,14 +85,14 @@ static int amd_isp_dw_i2c_plat_probe(struct 
 platform_device *pdev)
                 goto error_release_rpm;
         }
-
-       pm_runtime_put_sync(&pdev->dev);
+       dev_pm_genpd_suspend(&pdev->dev);
+       pm_runtime_set_suspended(&pdev->dev);

drivers/i2c/busses/i2c-designware-amdisp.c static int amd_isp_dw_i2c_plat_probe(struct · line 98

Quoted 10 lines
drivers/i2c/busses/i2c-designware-amdisp.c +1 -1
+       pm_runtime_enable(&pdev->dev);
 
         return 0;
 
  error_release_rpm:
         amd_isp_dw_i2c_plat_pm_cleanup(isp_i2c_dev);
-       pm_runtime_put_sync(&pdev->dev);
         return ret;
  }
 

Good investigation. Since this was around all the time and just got worse I would say you should add a fixes tag for the first commit that introduced this driver rather than 38fa29b01a6a295aedb69d1bbdad70acd7d204c6 and just note in the commit message that 38fa29b01a6a295aedb69d1bbdad70acd7d204c6 made it worse.

#6 lore raw
Quoted 81 lines · Mario Limonciello
Quoted 78 lines · Pratap

Hi Mario,

Quoted 14 lines · Mario Limonciello
Quoted 11 lines · Pratap Nirujogi

Add NULL check for i_dev->map before calling i2c_dw_init() in the runtime resume path. The regmap may not be initialized yet when runtime PM tries to resume the device early in the probe sequence, leading to a NULL pointer dereference. Skip the i2c_dw_init() call if regmap is not yet created.

This race condition occurs when runtime PM resume is triggered before i2c_dw_probe() completes the regmap initialization and was observed in kernel v7.0 where the order of device enumeration has changed because of the changes in registering the device sources in the device hierarchy.

Quoted 7 lines
Quoted 2 lines
Fixes 02c057ddefef ("ACPI: video: Convert the driver to a platform one")

Is this the right commit that introduced the race?  Did it change the timing?

Or was the race always there and we just got lucky until that commit went in?

My apologies for mixing up this change along with other changes that were needed to fix the AMD ISP driver regressions in v7.0.

I investigated further and found that this issue was exposed by the below commit.

https://github.com/torvalds/linux/ commit/38fa29b01a6a295aedb69d1bbdad70acd7d204c6

However, the resume‑probe race condition existed even earlier and had not surfaced because device initialization in resume is done only when init handle is valid.

Here is some background and context on this change:

The amdisp i2c device requires ISP to be in power on state for probe to succeed. To meet this requirement, we added this device, which is a amdgpu MFD child to the genpd, to control isp power using runtime PM. The pm_runtime_get_sync() call before probe triggers a PM resume, which powers on the ISP and also invokes the amdisp i2c runtime resume before the probe completes resulting in this race condition.

To fix this issue properly, I’m considering this change. Please review and share your feedback on whether this makes sense.

- Call dev_pm_genpd_resume() to Power ON ISP before probe
- Call dev_pm_genpd_suspend() to Power OFF ISP after probe
- Call pm_runtime_enable() after probe is successful to take care of system suspend/resume.

drivers/i2c/busses/i2c-designware-amdisp.c +5 -5
index 19de518be30a4..9ce58522951cd 100644
@@ -7,6 +7,7 @@
 
   #include <linux/module.h>
   #include <linux/platform_device.h>
+#include <linux/pm_domain.h>
   #include <linux/pm_runtime.h>
   #include <linux/soc/amd/isp4_misc.h>
 
@@ -76,9 +77,7 @@ static int amd_isp_dw_i2c_plat_probe(struct 
 platform_device *pdev)
 
          device_enable_async_suspend(&pdev->dev);
 
-       pm_runtime_enable(&pdev->dev);
-       pm_runtime_get_sync(&pdev->dev);
-
+       dev_pm_genpd_resume(&pdev->dev);
          ret = i2c_dw_probe(isp_i2c_dev);
          if (ret) {
@@ -86,14 +85,14 @@ static int amd_isp_dw_i2c_plat_probe(struct 
 platform_device *pdev)
                  goto error_release_rpm;
          }
-
-       pm_runtime_put_sync(&pdev->dev);
+       dev_pm_genpd_suspend(&pdev->dev);
+       pm_runtime_set_suspended(&pdev->dev);
+       pm_runtime_enable(&pdev->dev);
 
          return 0;
 
Quoted 7 lines
Quoted 6 lines

  error_release_rpm:
         amd_isp_dw_i2c_plat_pm_cleanup(isp_i2c_dev); -       pm_runtime_put_sync(&pdev->dev); return ret;
  }

Good investigation.  Since this was around all the time and just got worse I would say you should add a fixes tag for the first commit that introduced this driver rather than 38fa29b01a6a295aedb69d1bbdad70acd7d204c6 and just note in the commit message that 38fa29b01a6a295aedb69d1bbdad70acd7d204c6 made it worse.

Thanks, Mario. Your feedback on the Fixes tag and commit message is very helpful, I will take care of these while submitting v2.

Thanks,
Pratap

#7 lore raw
In reply to Pratap Nirujogi
Quoted 6 lines · Pratap Nirujogi

Add NULL check for i_dev->map before calling i2c_dw_init() in the runtime resume path. The regmap may not be initialized yet when runtime PM tries to resume the device early in the probe sequence, leading to a NULL pointer dereference. Skip the i2c_dw_init() call if regmap is not yet created.

Quoted 6 lines

This race condition occurs when runtime PM resume is triggered before i2c_dw_probe() completes the regmap initialization and was observed in kernel v7.0 where the order of device enumeration has changed because of the changes in registering the device sources in the device hierarchy.

Please, read Submitting Patches on the tags, especially how to correctly use Co-developed-by.

Quoted 2 lines
Fixes 02c057ddefef ("ACPI: video: Convert the driver to a platform one")

...

drivers/i2c/busses/i2c-designware-amdisp.c static int amd_isp_dw_i2c_plat_runtime_resume(struct device *dev) · line 157

Quoted 4 lines
drivers/i2c/busses/i2c-designware-amdisp.c +2 -1
 	i2c_dw_prepare_clk(i_dev, true);
-	i2c_dw_init(i_dev);
+
+	/* Skip i2c_dw_init if regmap not yet created by i2c_dw_probe */

Use same style for references to the functions: func().

drivers/i2c/busses/i2c-designware-amdisp.c static int amd_isp_dw_i2c_plat_runtime_resume(struct device *dev) · line 159

Quoted 2 lines
drivers/i2c/busses/i2c-designware-amdisp.c +2 -0
+	if (i_dev->map)
+		i2c_dw_init(i_dev);

TBH, Looks like papering over the problem. Why the resume is called on uninitialised regmap to begin with?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Hi Andy,

Quoted 15 lines · Andy Shevchenko

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 10 lines · Pratap Nirujogi

Add NULL check for i_dev->map before calling i2c_dw_init() in the runtime resume path. The regmap may not be initialized yet when runtime PM tries to resume the device early in the probe sequence, leading to a NULL pointer dereference. Skip the i2c_dw_init() call if regmap is not yet created.

This race condition occurs when runtime PM resume is triggered before i2c_dw_probe() completes the regmap initialization and was observed in kernel v7.0 where the order of device enumeration has changed because of the changes in registering the device sources in the device hierarchy.

Quoted 5 lines
Quoted 1 line

Please, read Submitting Patches on the tags, especially how to correctly use Co-developed-by.

sure, will fix the incorrect usage of tags in the next version.

Quoted 12 lines
Quoted 2 lines
Fixes 02c057ddefef ("ACPI: video: Convert the driver to a platform one")

...

drivers/i2c/busses/i2c-designware-amdisp.c static int amd_isp_dw_i2c_plat_runtime_resume(struct device *dev) · line 157

Quoted 4 lines
       i2c_dw_prepare_clk(i_dev, true);
drivers/i2c/busses/i2c-designware-amdisp.c +2 -1
-     i2c_dw_init(i_dev);
+
+     /* Skip i2c_dw_init if regmap not yet created by i2c_dw_probe */

Use same style for references to the functions: func().

sure, will fix it in the next version.

Quoted 6 lines

drivers/i2c/busses/i2c-designware-amdisp.c static int amd_isp_dw_i2c_plat_runtime_resume(struct device *dev) · line 159

Quoted 2 lines
drivers/i2c/busses/i2c-designware-amdisp.c +2 -0
+     if (i_dev->map)
+             i2c_dw_init(i_dev);

TBH, Looks like papering over the problem. Why the resume is called on uninitialised regmap to begin with?

yes, I agree, this change avoids the issue rather than fixing the root cause of the race condition. I investigated further and shared the details in response to Mario’s comments. Could you please review the latest response[1] and share your feedback?

[1] https://lore.kernel.org/all/[email protected]/

Thanks,
Pratap

Quoted 5 lines

--
With Best Regards,
Andy Shevchenko