From: Simon Glass <sjg@chromium.org>
If there is no console (e.g. in a test) this function segfaults. Add
the console as a parameter so it is clear that it is needed. Check for
it in the caller.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
boot/scene.c | 6 +++++-
boot/scene_internal.h | 5 ++++-
boot/scene_textline.c | 7 ++++---
3 files changed, 13 insertions(+), 5 deletions(-)
@@ -1114,7 +1114,11 @@ int scene_calc_dims(struct scene *scn)
struct scene_obj_textline *tline;
tline = (struct scene_obj_textline *)obj;
- ret = scene_textline_calc_dims(tline);
+ if (!scn->expo->cons)
+ continue;
+
+ ret = scene_textline_calc_dims(tline,
+ scn->expo->cons);
if (ret)
return log_msg_ret("men", ret);
@@ -21,6 +21,7 @@ struct scene_obj_menu;
struct scene_obj_textline;
struct scene_obj_txtedit;
struct scene_txt_generic;
+struct udevice;
struct vidconsole_bbox;
enum scene_obj_t;
@@ -380,9 +381,11 @@ int scene_dims_union(struct scene *scn, uint id, struct scene_obj_dims *dims);
* Updates the width and height of the textline based on its contents
*
* @tline: Textline to update
+ * @cons: UCLASS_VIDEO_CONSOLE device (cannot be NULL)
* Returns 0 if OK, -ENOTSUPP if there is no graphical console
*/
-int scene_textline_calc_dims(struct scene_obj_textline *tline);
+int scene_textline_calc_dims(struct scene_obj_textline *tline,
+ struct udevice *cons);
/**
* scene_menu_calc_bbox() - Calculate bounding boxes for the menu
@@ -60,7 +60,8 @@ void scene_textline_calc_bbox(struct scene_obj_textline *tline,
edit_bbox);
}
-int scene_textline_calc_dims(struct scene_obj_textline *tline)
+int scene_textline_calc_dims(struct scene_obj_textline *tline,
+ struct udevice *cons)
{
struct scene *scn = tline->obj.scene;
struct vidconsole_bbox bbox;
@@ -71,8 +72,8 @@ int scene_textline_calc_dims(struct scene_obj_textline *tline)
if (!txt)
return log_msg_ret("dim", -ENOENT);
- ret = vidconsole_nominal(scn->expo->cons, txt->gen.font_name,
- txt->gen.font_size, tline->max_chars, &bbox);
+ ret = vidconsole_nominal(cons, txt->gen.font_name, txt->gen.font_size,
+ tline->max_chars, &bbox);
if (ret)
return log_msg_ret("nom", ret);