If a mode name is not set, the device parameters will format the NULL
mode name as <NULL>. Instead, let's just generate a name and use that.

If multiple modes have the same resolution and refresh rate, we will end
up with duplicate names, but that's ok as this is just a fallback.
Drivers can always assign proper names to their modes and most do.

Signed-off-by: Ahmad Fatoum <a.fat...@pengutronix.de>
---
 drivers/video/fb.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index fade873d1efa..64ca68e14513 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -291,6 +291,11 @@ static int fb_set_shadowfb(struct param_d *p, void *priv)
        return fb_alloc_shadowfb(info);
 }
 
+static const char *mode_name(struct fb_videomode *mode)
+{
+       return basprintf("%dx%d@%d", mode->xres, mode->yres, mode->refresh);
+}
+
 int register_framebuffer(struct fb_info *info)
 {
        int id;
@@ -351,10 +356,18 @@ int register_framebuffer(struct fb_info *info)
 
        names = xzalloc(sizeof(char *) * num_modes);
 
-       for (i = 0; i < info->modes.num_modes; i++)
+       for (i = 0; i < info->modes.num_modes; i++) {
+               if (!info->modes.modes[i].name)
+                       info->modes.modes[i].name = 
mode_name(&info->modes.modes[i]);
                names[i] = info->modes.modes[i].name;
-       for (i = 0; i < info->edid_modes.num_modes; i++)
+       }
+
+       for (i = 0; i < info->edid_modes.num_modes; i++) {
+               if (!info->edid_modes.modes[i].name)
+                       info->modes.modes[i].name = 
mode_name(&info->edid_modes.modes[i]);
                names[i + info->modes.num_modes] = 
info->edid_modes.modes[i].name;
+       }
+
        dev_add_param_enum(dev, "mode_name", fb_set_modename, NULL, 
&info->current_mode, names, num_modes, info);
        info->shadowfb = 1;
        dev_add_param_bool(dev, "shadowfb", fb_set_shadowfb, NULL, 
&info->shadowfb, info);
-- 
2.39.5


Reply via email to