Commit 10ac8688 authored by Yisheng Xie's avatar Yisheng Xie Committed by Bartlomiej Zolnierkiewicz

fbcon: introduce for_each_registered_fb() helper

Following pattern is often used:

 for (i = 0; i < FB_MAX; i++) {
        if (registered_fb[i]) {
                ...
        }
 }

Therefore, as Andy's suggestion, for_each_registered_fb() helper can
be introduced to make the code easier to read and write by reducing
indentation level. It also saves few lines of code in each occurrence.

This patch convert all part here at the same time.
Suggested-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarYisheng Xie <ysxie@foxmail.com>
Acked-by: default avatarHans de Goede <hdegoede@redhat.com>
Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: David Lechner <david@lechnology.com>
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
parent 4a1208c5
...@@ -2234,8 +2234,8 @@ static int fbcon_switch(struct vc_data *vc) ...@@ -2234,8 +2234,8 @@ static int fbcon_switch(struct vc_data *vc)
* *
* info->currcon = vc->vc_num; * info->currcon = vc->vc_num;
*/ */
for (i = 0; i < FB_MAX; i++) { for_each_registered_fb(i) {
if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) { if (registered_fb[i]->fbcon_par) {
struct fbcon_ops *o = registered_fb[i]->fbcon_par; struct fbcon_ops *o = registered_fb[i]->fbcon_par;
o->currcon = vc->vc_num; o->currcon = vc->vc_num;
...@@ -3124,11 +3124,9 @@ static int fbcon_fb_unregistered(struct fb_info *info) ...@@ -3124,11 +3124,9 @@ static int fbcon_fb_unregistered(struct fb_info *info)
if (idx == info_idx) { if (idx == info_idx) {
info_idx = -1; info_idx = -1;
for (i = 0; i < FB_MAX; i++) { for_each_registered_fb(i) {
if (registered_fb[i] != NULL) { info_idx = i;
info_idx = i; break;
break;
}
} }
} }
...@@ -3609,10 +3607,8 @@ static int fbcon_output_notifier(struct notifier_block *nb, ...@@ -3609,10 +3607,8 @@ static int fbcon_output_notifier(struct notifier_block *nb,
deferred_takeover = false; deferred_takeover = false;
logo_shown = FBCON_LOGO_DONTSHOW; logo_shown = FBCON_LOGO_DONTSHOW;
for (i = 0; i < FB_MAX; i++) { for_each_registered_fb(i)
if (registered_fb[i]) fbcon_fb_registered(registered_fb[i]);
fbcon_fb_registered(registered_fb[i]);
}
return NOTIFY_OK; return NOTIFY_OK;
} }
...@@ -3638,11 +3634,9 @@ static void fbcon_start(void) ...@@ -3638,11 +3634,9 @@ static void fbcon_start(void)
console_lock(); console_lock();
for (i = 0; i < FB_MAX; i++) { for_each_registered_fb(i) {
if (registered_fb[i] != NULL) { info_idx = i;
info_idx = i; break;
break;
}
} }
do_fbcon_takeover(0); do_fbcon_takeover(0);
...@@ -3669,15 +3663,12 @@ static void fbcon_exit(void) ...@@ -3669,15 +3663,12 @@ static void fbcon_exit(void)
kfree((void *)softback_buf); kfree((void *)softback_buf);
softback_buf = 0UL; softback_buf = 0UL;
for (i = 0; i < FB_MAX; i++) { for_each_registered_fb(i) {
int pending = 0; int pending = 0;
mapped = 0; mapped = 0;
info = registered_fb[i]; info = registered_fb[i];
if (info == NULL)
continue;
if (info->queue.func) if (info->queue.func)
pending = cancel_work_sync(&info->queue); pending = cancel_work_sync(&info->queue);
DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" : DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
......
...@@ -1593,10 +1593,8 @@ static int do_remove_conflicting_framebuffers(struct apertures_struct *a, ...@@ -1593,10 +1593,8 @@ static int do_remove_conflicting_framebuffers(struct apertures_struct *a,
int i, ret; int i, ret;
/* check all firmware fbs and kick off if the base addr overlaps */ /* check all firmware fbs and kick off if the base addr overlaps */
for (i = 0 ; i < FB_MAX; i++) { for_each_registered_fb(i) {
struct apertures_struct *gen_aper; struct apertures_struct *gen_aper;
if (!registered_fb[i])
continue;
if (!(registered_fb[i]->flags & FBINFO_MISC_FIRMWARE)) if (!(registered_fb[i]->flags & FBINFO_MISC_FIRMWARE))
continue; continue;
......
...@@ -650,6 +650,10 @@ extern struct fb_info *registered_fb[FB_MAX]; ...@@ -650,6 +650,10 @@ extern struct fb_info *registered_fb[FB_MAX];
extern int num_registered_fb; extern int num_registered_fb;
extern struct class *fb_class; extern struct class *fb_class;
#define for_each_registered_fb(i) \
for (i = 0; i < FB_MAX; i++) \
if (!registered_fb[i]) {} else
extern int lock_fb_info(struct fb_info *info); extern int lock_fb_info(struct fb_info *info);
static inline void unlock_fb_info(struct fb_info *info) static inline void unlock_fb_info(struct fb_info *info)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment