Skip to contentSkip to conversation

drm/panel-simple: take i2c adapter module reference

PATCH In review Johan Hovold 4 participants 9 messages Jul 16 – Nov 18

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/panel-simple: take i2c adapter module reference

The i2c subsystem currently blocks during adapter deregistration whenever there are consumers holding a reference.

Switch to using of_get_i2c_adapter_by_node() which also takes a reference to the adapter module so that an attempt to unload the module while in use fails gracefully instead of blocking uninterruptibly.

---
 drivers/gpu/drm/panel/panel-simple.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/panel/panel-simple.c +3 -3
index c09bf3db5e78..f58e83aa4ebe 100644
@@ -701,7 +701,7 @@ static struct panel_simple *panel_simple_probe(struct device *dev)
 
 	ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
 	if (ddc) {
-		panel->ddc = of_find_i2c_adapter_by_node(ddc);
+		panel->ddc = of_get_i2c_adapter_by_node(ddc);
 		of_node_put(ddc);
 
 		if (!panel->ddc)
@@ -746,7 +746,7 @@ static struct panel_simple *panel_simple_probe(struct device *dev)
 	pm_runtime_disable(dev);
 free_ddc:
 	if (panel->ddc)
-		put_device(&panel->ddc->dev);
+		i2c_put_adapter(panel->ddc);
 
 	return ERR_PTR(err);
 }
@@ -791,7 +791,7 @@ static void panel_simple_remove(struct device *dev)
 	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_disable(dev);
 	if (panel->ddc)
-		put_device(&panel->ddc->dev);
+		i2c_put_adapter(panel->ddc);
 }
 
 static const struct drm_display_mode ampire_am_1280800n3tzqw_t00h_mode = {
Signature · 1 line
2.54.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Calling `i2c_put_adapter()` breaks the build when `CONFIG_I2C` is not enabled. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Calling i2c_put_adapter() breaks the build when CONFIG_I2C is not enabled. --

--- Patch [1]: [PATCH] drm/panel-simple: take i2c adapter module reference --- commit 78f8d3d7539288c8e1940d04e2aff6503a3592b4
Author: Johan Hovold <[email protected]>

drm/panel-simple: take i2c adapter module reference

This patch changes the panel-simple driver to use of_get_i2c_adapter_by_node() instead of of_find_i2c_adapter_by_node(). This ensures the i2c adapter module reference is taken, preventing uninterruptible blocking during deregistration. The teardown paths are updated to use i2c_put_adapter() instead of put_device().

Quoted 4 lines
drivers/gpu/drm/panel/panel-simple.c +0 -0
index 5c169fdf265c1..79bd6bbec7bde 100644

[ ... ]

drivers/gpu/drm/panel/panel-simple.c static struct panel_simple *panel_simple_probe(struct device *dev) · line 749

Quoted 6 lines
drivers/gpu/drm/panel/panel-simple.c +1 -1
@@ -746,7 +746,7 @@ static struct panel_simple *panel_simple_probe(struct device *dev)
 	pm_runtime_disable(dev);
 free_ddc:
 	if (panel->ddc)
-		put_device(&panel->ddc->dev);
+		i2c_put_adapter(panel->ddc);

[Severity: Low]
Does this cause a build failure when CONFIG_I2C is disabled?

Looking at include/linux/i2c.h, it appears the declaration for i2c_put_adapter() is guarded by IS_ENABLED(CONFIG_I2C), but there is no corresponding empty stub provided in the fallback block for when I2C is disabled.

Since this driver can be built without CONFIG_I2C, calling i2c_put_adapter() unconditionally here in panel_simple_probe() might result in an undefined reference during linking or an implicit declaration error.

Quoted 3 lines
drivers/gpu/drm/panel/panel-simple.c +0 -0
 	return ERR_PTR(err);
 }

[ ... ]

drivers/gpu/drm/panel/panel-simple.c static void panel_simple_remove(struct device *dev) · line 794

Quoted 6 lines
drivers/gpu/drm/panel/panel-simple.c +1 -1
@@ -791,7 +791,7 @@ static void panel_simple_remove(struct device *dev)
 	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_disable(dev);
 	if (panel->ddc)
-		put_device(&panel->ddc->dev);
+		i2c_put_adapter(panel->ddc);

[Severity: Low]
The same potential build issue with CONFIG_I2C=n applies here in panel_simple_remove().

Quoted 3 lines
drivers/gpu/drm/panel/panel-simple.c +0 -0
 }
 
 static const struct drm_display_mode ampire_am_1280800n3tzqw_t00h_mode = {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Johan Hovold
Quoted 8 lines · Johan Hovold

The i2c subsystem currently blocks during adapter deregistration whenever there are consumers holding a reference.

Switch to using of_get_i2c_adapter_by_node() which also takes a reference to the adapter module so that an attempt to unload the module while in use fails gracefully instead of blocking uninterruptibly.

Can this one be picked up for 7.3-rc1?

Johan

#3 lore raw
Quoted 11 lines · Johan Hovold
Quoted 8 lines · Johan Hovold

The i2c subsystem currently blocks during adapter deregistration whenever there are consumers holding a reference.

Switch to using of_get_i2c_adapter_by_node() which also takes a reference to the adapter module so that an attempt to unload the module while in use fails gracefully instead of blocking uninterruptibly.

Can this one be picked up for 7.3-rc1?

Again, can someone please pick this one up?

Johan

#4 lore raw
In reply to Johan Hovold
Quoted 11 lines · Johan Hovold
Quoted 8 lines · Johan Hovold

The i2c subsystem currently blocks during adapter deregistration whenever there are consumers holding a reference.

Switch to using of_get_i2c_adapter_by_node() which also takes a reference to the adapter module so that an attempt to unload the module while in use fails gracefully instead of blocking uninterruptibly.

Can this one be picked up for 7.3-rc1?

This one is still not in linux-next. Can I get one more ack or whatever is needed for this to move forward?

Also adding Doug who merged a corresponding patch for panel-edp back in July. [1]

Johan

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

#5 lore raw

Hi,

Quoted 17 lines · Johan Hovold
Quoted 11 lines · Johan Hovold
Quoted 8 lines · Johan Hovold

The i2c subsystem currently blocks during adapter deregistration whenever there are consumers holding a reference.

Switch to using of_get_i2c_adapter_by_node() which also takes a reference to the adapter module so that an attempt to unload the module while in use fails gracefully instead of blocking uninterruptibly.

Can this one be picked up for 7.3-rc1?

This one is still not in linux-next. Can I get one more ack or whatever is needed for this to move forward?

Quoted 7 lines

Also adding Doug who merged a corresponding patch for panel-edp back in July. [1]

Johan

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

I took a quick gander. One thing I notice is that earlier in the thread there is a Sashiko review [1]. It seems to point out a valid problem here. I'd imagine that if I land this patch, I'll get a nastygram from Arnd and his RANDCONFIG testing. Am I confused? Is Sashiko wrong in its analysis?

[1] http://lore.kernel.org/r/[email protected]

#6 lore raw
Quoted 5 lines · Doug Anderson

I took a quick gander. One thing I notice is that earlier in the thread there is a Sashiko review [1]. It seems to point out a valid problem here. I'd imagine that if I land this patch, I'll get a nastygram from Arnd and his RANDCONFIG testing. Am I confused? Is Sashiko wrong in its analysis?

Thanks, Doug.

Yeah, I took a look at that at the time and I believe the LLM is mistaken as DRM selects I2C since forever so the driver cannot be built without CONFIG_I2C enabled (and you'd have the same situation with the panel-edp change merged in July).

I started cleaning up the I2C mess but got pre-empted. I don't think that should block this change.

Johan

Quoted 1 line

[1] http://lore.kernel.org/r/[email protected]

Reviewed-by
#7 lore raw

Hi Johan,

Quoted 16 lines · Johan Hovold
Quoted 5 lines · Doug Anderson

I took a quick gander. One thing I notice is that earlier in the thread there is a Sashiko review [1]. It seems to point out a valid problem here. I'd imagine that if I land this patch, I'll get a nastygram from Arnd and his RANDCONFIG testing. Am I confused? Is Sashiko wrong in its analysis?

Thanks, Doug.

Yeah, I took a look at that at the time and I believe the LLM is mistaken as DRM selects I2C since forever so the driver cannot be built without CONFIG_I2C enabled (and you'd have the same situation with the panel-edp change merged in July).

Quoted 6 lines

I started cleaning up the I2C mess but got pre-empted. I don't think that should block this change.

Johan

Quoted 1 line

[1] http://lore.kernel.org/r/[email protected]

Ah, got it! OK, then

...and pushed to drm-misc-next (not -fixes for the same reason I didn't send the panel-edp patch to -fixes).

[1/1] drm/panel-simple: take i2c adapter module reference

      commit: eb2d05056f5c65fae6e88f6d935f3f7089badf00
maintainer Reviewed-by on v1 1/1
#8 lore raw
In reply to Johan Hovold
Quoted 35 lines · Johan Hovold

The i2c subsystem currently blocks during adapter deregistration whenever there are consumers holding a reference.

Switch to using of_get_i2c_adapter_by_node() which also takes a reference to the adapter module so that an attempt to unload the module while in use fails gracefully instead of blocking uninterruptibly.

---
  drivers/gpu/drm/panel/panel-simple.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/panel/panel-simple.c +2 -2
index c09bf3db5e78..f58e83aa4ebe 100644
@@ -701,7 +701,7 @@ static struct panel_simple *panel_simple_probe(struct device *dev)
 
  	ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
  	if (ddc) {
-		panel->ddc = of_find_i2c_adapter_by_node(ddc);
+		panel->ddc = of_get_i2c_adapter_by_node(ddc);
  		of_node_put(ddc);
 
  		if (!panel->ddc)
@@ -746,7 +746,7 @@ static struct panel_simple *panel_simple_probe(struct device *dev)
  	pm_runtime_disable(dev);
  free_ddc:
  	if (panel->ddc)
-		put_device(&panel->ddc->dev);
+		i2c_put_adapter(panel->ddc);
 
  	return ERR_PTR(err);
  }

drivers/gpu/drm/panel/panel-simple.c static void panel_simple_remove(struct device *dev) · line 797

Quoted 8 lines
drivers/gpu/drm/panel/panel-simple.c +1 -1
@@ -791,7 +791,7 @@ static void panel_simple_remove(struct device *dev)
  	pm_runtime_dont_use_autosuspend(dev);
  	pm_runtime_disable(dev);
  	if (panel->ddc)
-		put_device(&panel->ddc->dev);
+		i2c_put_adapter(panel->ddc);
  }
 
  static const struct drm_display_mode ampire_am_1280800n3tzqw_t00h_mode = {

Thanks,
Neil