dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fbdev: ssd1307fb: release PWM if panel initialization fails
@ 2026-11-26 13:35 Yige Jiang
  2026-11-26 13:40 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Yige Jiang @ 2026-11-26 13:35 UTC (permalink / raw)
  To: Helge Deller; +Cc: Yige Jiang, linux-fbdev, dri-devel, linux-kernel, stable

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")
Cc: stable@vger.kernel.org
Link: https://sashiko.dev/#/patchset/20260926-fix-fbdefio-error-handling-v1-0-a94810b6e263%40kernel.org
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
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(-)

diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
index ef4bb920c6ff..dbe5dc67e044 100644
--- a/drivers/video/fbdev/ssd1307fb.c
+++ b/drivers/video/fbdev/ssd1307fb.c
@@ -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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fbdev: ssd1307fb: release PWM if panel initialization fails
  2026-11-26 13:35 [PATCH] fbdev: ssd1307fb: release PWM if panel initialization fails Yige Jiang
@ 2026-11-26 13:40 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-26 13:40 UTC (permalink / raw)
  To: Yige Jiang; +Cc: dri-devel

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 <yigejiang86@gmail.com>

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.

Link: https://sashiko.dev/#/patchset/20260926-fix-fbdefio-error-handling-v1-0-a94810b6e263%40kernel.org

> diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
> index ef4bb920c6ff6..dbe5dc67e0442 100644
> --- a/drivers/video/fbdev/ssd1307fb.c
> +++ b/drivers/video/fbdev/ssd1307fb.c

[ ... ]

> @@ -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

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/rc-b1-20261110-vc-112-b07bbe936b75@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-27  8:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 13:35 [PATCH] fbdev: ssd1307fb: release PWM if panel initialization fails Yige Jiang
2026-11-26 13:40 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox