Skip to content

Commit 1520081

Browse files
Jinjie Ruanhdeller
authored andcommitted
fbdev/core: Use list_for_each_entry() helper
Convert list_for_each() to list_for_each_entry() so that the pos list_head pointer and list_entry() call are no longer needed, which can reduce a few lines of code. No functional changed. Signed-off-by: Jinjie Ruan <[email protected]> Signed-off-by: Helge Deller <[email protected]>
1 parent 87dfd85 commit 1520081

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

drivers/video/fbdev/core/fbsysfs.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,12 @@ static ssize_t store_mode(struct device *device, struct device_attribute *attr,
6161
struct fb_var_screeninfo var;
6262
struct fb_modelist *modelist;
6363
struct fb_videomode *mode;
64-
struct list_head *pos;
6564
size_t i;
6665
int err;
6766

6867
memset(&var, 0, sizeof(var));
6968

70-
list_for_each(pos, &fb_info->modelist) {
71-
modelist = list_entry(pos, struct fb_modelist, list);
69+
list_for_each_entry(modelist, &fb_info->modelist, list) {
7270
mode = &modelist->mode;
7371
i = mode_string(mstr, 0, mode);
7472
if (strncmp(mstr, buf, max(count, i)) == 0) {
@@ -129,13 +127,11 @@ static ssize_t show_modes(struct device *device, struct device_attribute *attr,
129127
{
130128
struct fb_info *fb_info = dev_get_drvdata(device);
131129
unsigned int i;
132-
struct list_head *pos;
133130
struct fb_modelist *modelist;
134131
const struct fb_videomode *mode;
135132

136133
i = 0;
137-
list_for_each(pos, &fb_info->modelist) {
138-
modelist = list_entry(pos, struct fb_modelist, list);
134+
list_for_each_entry(modelist, &fb_info->modelist, list) {
139135
mode = &modelist->mode;
140136
i += mode_string(buf, i, mode);
141137
}

drivers/video/fbdev/core/modedb.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -963,15 +963,12 @@ int fb_mode_is_equal(const struct fb_videomode *mode1,
963963
const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var,
964964
struct list_head *head)
965965
{
966-
struct list_head *pos;
967966
struct fb_modelist *modelist;
968967
struct fb_videomode *mode, *best = NULL;
969968
u32 diff = -1;
970969

971-
list_for_each(pos, head) {
970+
list_for_each_entry(modelist, head, list) {
972971
u32 d;
973-
974-
modelist = list_entry(pos, struct fb_modelist, list);
975972
mode = &modelist->mode;
976973

977974
if (mode->xres >= var->xres && mode->yres >= var->yres) {
@@ -1001,15 +998,12 @@ const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var
1001998
const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode,
1002999
struct list_head *head)
10031000
{
1004-
struct list_head *pos;
10051001
struct fb_modelist *modelist;
10061002
struct fb_videomode *cmode, *best = NULL;
10071003
u32 diff = -1, diff_refresh = -1;
10081004

1009-
list_for_each(pos, head) {
1005+
list_for_each_entry(modelist, head, list) {
10101006
u32 d;
1011-
1012-
modelist = list_entry(pos, struct fb_modelist, list);
10131007
cmode = &modelist->mode;
10141008

10151009
d = abs(cmode->xres - mode->xres) +
@@ -1041,13 +1035,11 @@ const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode,
10411035
const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var,
10421036
struct list_head *head)
10431037
{
1044-
struct list_head *pos;
10451038
struct fb_modelist *modelist;
10461039
struct fb_videomode *m, mode;
10471040

10481041
fb_var_to_videomode(&mode, var);
1049-
list_for_each(pos, head) {
1050-
modelist = list_entry(pos, struct fb_modelist, list);
1042+
list_for_each_entry(modelist, head, list) {
10511043
m = &modelist->mode;
10521044
if (fb_mode_is_equal(m, &mode))
10531045
return m;
@@ -1065,13 +1057,11 @@ const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var,
10651057
*/
10661058
int fb_add_videomode(const struct fb_videomode *mode, struct list_head *head)
10671059
{
1068-
struct list_head *pos;
10691060
struct fb_modelist *modelist;
10701061
struct fb_videomode *m;
10711062
int found = 0;
10721063

1073-
list_for_each(pos, head) {
1074-
modelist = list_entry(pos, struct fb_modelist, list);
1064+
list_for_each_entry(modelist, head, list) {
10751065
m = &modelist->mode;
10761066
if (fb_mode_is_equal(m, mode)) {
10771067
found = 1;
@@ -1152,7 +1142,6 @@ void fb_videomode_to_modelist(const struct fb_videomode *modedb, int num,
11521142
const struct fb_videomode *fb_find_best_display(const struct fb_monspecs *specs,
11531143
struct list_head *head)
11541144
{
1155-
struct list_head *pos;
11561145
struct fb_modelist *modelist;
11571146
const struct fb_videomode *m, *m1 = NULL, *md = NULL, *best = NULL;
11581147
int first = 0;
@@ -1161,8 +1150,7 @@ const struct fb_videomode *fb_find_best_display(const struct fb_monspecs *specs,
11611150
goto finished;
11621151

11631152
/* get the first detailed mode and the very first mode */
1164-
list_for_each(pos, head) {
1165-
modelist = list_entry(pos, struct fb_modelist, list);
1153+
list_for_each_entry(modelist, head, list) {
11661154
m = &modelist->mode;
11671155

11681156
if (!first) {

0 commit comments

Comments
 (0)