Skip to content

Commit 4bfb77f

Browse files
Thomas Zimmermannlag-linaro
authored andcommitted
backlight: Move blank-state handling into helper
Move the handling of blank-state updates into a separate helper, so that is can be called without the fbdev event. No functional changes. As a minor improvement over the original code, the update replaces manual locking with a guard. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: "Daniel Thompson (RISCstar)" <danielt@kernel.org> Acked-by: Simona Vetter <simona.vetter@ffwll.ch> Link: https://lore.kernel.org/r/20250321095517.313713-6-tzimmermann@suse.de Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 726491f commit 4bfb77f

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

drivers/video/backlight/backlight.c

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ static const char *const backlight_scale_types[] = {
8080

8181
#if defined(CONFIG_FB_CORE) || (defined(CONFIG_FB_CORE_MODULE) && \
8282
defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE))
83+
static void backlight_notify_blank(struct backlight_device *bd,
84+
struct device *display_dev,
85+
bool fb_on, bool prev_fb_on)
86+
{
87+
guard(mutex)(&bd->ops_lock);
88+
89+
if (!bd->ops)
90+
return;
91+
if (bd->ops->controls_device && !bd->ops->controls_device(bd, display_dev))
92+
return;
93+
94+
if (fb_on && (!prev_fb_on || !bd->use_count)) {
95+
if (!bd->use_count++) {
96+
bd->props.state &= ~BL_CORE_FBBLANK;
97+
backlight_update_status(bd);
98+
}
99+
} else if (!fb_on && prev_fb_on && bd->use_count) {
100+
if (!(--bd->use_count)) {
101+
bd->props.state |= BL_CORE_FBBLANK;
102+
backlight_update_status(bd);
103+
}
104+
}
105+
}
106+
83107
/*
84108
* fb_notifier_callback
85109
*
@@ -107,31 +131,15 @@ static int fb_notifier_callback(struct notifier_block *self,
107131
return 0;
108132

109133
bd = container_of(self, struct backlight_device, fb_notif);
110-
mutex_lock(&bd->ops_lock);
111134

112-
if (!bd->ops)
113-
goto out;
114-
if (bd->ops->controls_device && !bd->ops->controls_device(bd, info->device))
115-
goto out;
116135
if (fb_bd && fb_bd != bd)
117-
goto out;
136+
return 0;
118137

119138
fb_on = fb_blank[0] == FB_BLANK_UNBLANK;
120139
prev_fb_on = fb_blank[1] == FB_BLANK_UNBLANK;
121140

122-
if (fb_on && (!prev_fb_on || !bd->use_count)) {
123-
if (!bd->use_count++) {
124-
bd->props.state &= ~BL_CORE_FBBLANK;
125-
backlight_update_status(bd);
126-
}
127-
} else if (!fb_on && prev_fb_on && bd->use_count) {
128-
if (!(--bd->use_count)) {
129-
bd->props.state |= BL_CORE_FBBLANK;
130-
backlight_update_status(bd);
131-
}
132-
}
133-
out:
134-
mutex_unlock(&bd->ops_lock);
141+
backlight_notify_blank(bd, info->device, fb_on, prev_fb_on);
142+
135143
return 0;
136144
}
137145

0 commit comments

Comments
 (0)