diff mbox series

[01/28] backlight: lcd: Rearrange code in fb_notifier_callback()

Message ID 20240820093452.68270-2-tzimmermann@suse.de
State New
Headers show
Series backlight: lcd: Remove fbdev dependencies | expand

Commit Message

Thomas Zimmermann Aug. 20, 2024, 9:22 a.m. UTC
First aqcuire the ops_lock and do al tests while holing it. Rearranges
the code in lcd's fb_notifier_callback() to resemble the callback in
the backlight module. This will simplify later changes to these tests.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/backlight/lcd.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

Comments

Daniel Thompson Sept. 3, 2024, 2:54 p.m. UTC | #1
On Tue, Aug 20, 2024 at 11:22:39AM +0200, Thomas Zimmermann wrote:
> First aqcuire the ops_lock and do al tests while holing it. Rearranges

s/aqcuire/acquire/
s/al/all/

> the code in lcd's fb_notifier_callback() to resemble the callback in
> the backlight module. This will simplify later changes to these tests.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
>  drivers/video/backlight/lcd.c | 24 ++++++++++++++----------
>  1 file changed, 14 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
> index ceec90ca758b..0cd0fa1b24f9 100644
> --- a/drivers/video/backlight/lcd.c
> +++ b/drivers/video/backlight/lcd.c
> @@ -29,21 +29,25 @@ static int fb_notifier_callback(struct notifier_block *self,
>  {
>  	struct lcd_device *ld;
>  	struct fb_event *evdata = data;
> +	struct fb_info *info = evdata->info;
>
>  	ld = container_of(self, struct lcd_device, fb_notif);
> +	mutex_lock(&ld->ops_lock);
> +

guard(mutex)(&ld->ops_lock); and eliminating all the goto code would be
better here but not a huge deal.



Daniel.
diff mbox series

Patch

diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
index ceec90ca758b..0cd0fa1b24f9 100644
--- a/drivers/video/backlight/lcd.c
+++ b/drivers/video/backlight/lcd.c
@@ -29,21 +29,25 @@  static int fb_notifier_callback(struct notifier_block *self,
 {
 	struct lcd_device *ld;
 	struct fb_event *evdata = data;
+	struct fb_info *info = evdata->info;
 
 	ld = container_of(self, struct lcd_device, fb_notif);
+	mutex_lock(&ld->ops_lock);
+
 	if (!ld->ops)
-		return 0;
+		goto out;
+	if (ld->ops->check_fb && !ld->ops->check_fb(ld, evdata->info))
+		goto out;
 
-	mutex_lock(&ld->ops_lock);
-	if (!ld->ops->check_fb || ld->ops->check_fb(ld, evdata->info)) {
-		if (event == FB_EVENT_BLANK) {
-			if (ld->ops->set_power)
-				ld->ops->set_power(ld, *(int *)evdata->data);
-		} else {
-			if (ld->ops->set_mode)
-				ld->ops->set_mode(ld, evdata->data);
-		}
+	if (event == FB_EVENT_BLANK) {
+		if (ld->ops->set_power)
+			ld->ops->set_power(ld, *(int *)evdata->data);
+	} else {
+		if (ld->ops->set_mode)
+			ld->ops->set_mode(ld, evdata->data);
 	}
+
+out:
 	mutex_unlock(&ld->ops_lock);
 	return 0;
 }