Skip to contentSkip to conversation

fbdev: ssd1307fb: release PWM if panel initialization fails

PATCH New Yige Jiang 2 participants 2 messages Nov 26

Subsystems (2)
lore
Share & tools
lore

Yige Jiang

author
#0 lore raw

PATCH 1/1 fbdev: ssd1307fb: release PWM if panel initialization fails

On the SSD1307 variant, ssd1307fb_init() gets and enables the PWM before it sends the panel init commands over I2C. If one of those writes fails, ssd1307fb_probe() jumps to regulator_enable_error, below the pwm_disable()/pwm_put() at panel_init_error. The PWM is left enabled and requested, and its references on the PWM chip device and module are never dropped. As the PWM stays marked as requested, a later probe of the display can no longer get it (pwm_device_request() returns -EBUSY).

The sashiko AI review bot pointed this out on 2026-09-26, while reviewing an unrelated ssd1307fb error-handling patch.

Jump to panel_init_error instead and drop the now unused regulator_enable_error label. pwm_disable() and pwm_put() accept NULL, which covers variants without a PWM, so clear par->pwm when pwm_get() fails instead of leaving an ERR_PTR() for the error path.

Fixes bbc79089ae2b ("video: ssd1307fb: Add support for SSD1306 OLED controller")

---
Based on linux-next next-20261109 (630059a5a632).
Compile-tested: arm64, GCC 14.2.0, W=1, CONFIG_FB_SSD1307=m, CONFIG_PWM=y, CONFIG_COMPILE_TEST=y; baseline and patched ssd1307fb.o, no new warnings. No hardware or runtime test was performed.
The path needs an I2C write error during panel init on a solomon,ssd1307fb-i2c device.

 drivers/video/fbdev/ssd1307fb.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/video/fbdev/ssd1307fb.c +4 -3
index ef4bb920c6ff..dbe5dc67e044 100644
@@ -403,7 +403,9 @@ static int ssd1307fb_init(struct ssd1307fb_par *par)
 		par->pwm = pwm_get(&par->client->dev, NULL);
 		if (IS_ERR(par->pwm)) {
 			dev_err(&par->client->dev, "Could not get PWM from device tree!\n");
-			return PTR_ERR(par->pwm);
+			ret = PTR_ERR(par->pwm);
+			par->pwm = NULL;
+			return ret;
 		}
 
 		pwm_init_state(par->pwm, &pwmstate);
@@ -794,7 +796,7 @@ static int ssd1307fb_probe(struct i2c_client *client)
 
 	ret = ssd1307fb_init(par);
 	if (ret)
-		goto regulator_enable_error;
+		goto panel_init_error;
 
 	bl = backlight_device_register("ssd1307fb-bl", dev, par, &ssd1307fb_bl_ops,
 				       NULL);
@@ -823,7 +825,6 @@ static int ssd1307fb_probe(struct i2c_client *client)
 panel_init_error:
 	pwm_disable(par->pwm);
 	pwm_put(par->pwm);
-regulator_enable_error:
 	if (par->vbat_reg)
 		regulator_disable(par->vbat_reg);
 reset_oled_error:

base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47

#1 lore raw
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] fbdev: ssd1307fb: invalid virtual…

Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] fbdev: ssd1307fb: invalid virtual address passed to __free_pages() [1]
--

commit 0007b36f0bb513d1789d67a9c3b80f87e05fe107
Author: Yige Jiang <[email protected]>

fbdev: ssd1307fb: release PWM if panel initialization fails

This commit updates ssd1307fb_probe() to jump to panel_init_error when ssd1307fb_init() fails so that any requested PWM is disabled and released, and clears par->pwm on pwm_get() failure.

Quoted 4 lines
drivers/video/fbdev/ssd1307fb.c +0 -0
index ef4bb920c6ff6..dbe5dc67e0442 100644

[ ... ]

drivers/video/fbdev/ssd1307fb.c static int ssd1307fb_probe(struct i2c_client *client) · line 830

Quoted 8 lines
drivers/video/fbdev/ssd1307fb.c +0 -1
@@ -823,7 +825,6 @@ static int ssd1307fb_probe(struct i2c_client *client)
 panel_init_error:
 	pwm_disable(par->pwm);
 	pwm_put(par->pwm);
-regulator_enable_error:
 	if (par->vbat_reg)
 		regulator_disable(par->vbat_reg);
 reset_oled_error:

[Severity: Critical]
This problem wasn't introduced by this patch, but in this error path (and in ssd1307fb_remove()), does fb_defio_error corrupt memory by passing a virtual address to __free_pages() [1]?

vmem is allocated with __get_free_pages(), which returns a virtual address stored as void *:

drivers/video/fbdev/ssd1307fb.c:ssd1307fb_probe() {
	...
	vmem = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
					get_order(vmem_size));
	...
fb_defio_error:
	__free_pages(vmem, get_order(vmem_size));
}

__free_pages() expects a struct page *, whereas free_pages() takes a virtual address. Because vmem and __va(info->fix.smem_start) are void *, they convert implicitly to struct page *, causing __free_pages() to treat the framebuffer buffer itself as a struct page descriptor on probe failure or module unload.

[1] https://sashiko.dev/#/bug/linux-2cc48a80-14a7-42fb-ac37-6c2eebc04a6d

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1