[Concept,34/36] video: Pass a cursor pointer to console_alloc_cursor()

Message ID 20260120231814.2033069-35-sjg@u-boot.org
State New
Headers
Series video: Add multiple-context support to vidconsole (part F) |

Commit Message

Simon Glass Jan. 20, 2026, 11:18 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Change console_alloc_cursor() to take a struct vidconsole_cursor pointer
directly instead of the full context, since that is not needed.

This allows the function to be used a cursor embedded in a larger
struct.

Add a matching console_free_cursor() function to free the cursor's
save_data buffer.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 drivers/video/console_core.c        |  9 ++++++---
 drivers/video/vidconsole-uclass.c   |  4 ++--
 drivers/video/vidconsole_internal.h | 13 +++++++++++--
 3 files changed, 19 insertions(+), 7 deletions(-)
  

Patch

diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index 0580e2661de..6bd7dc263e6 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -280,9 +280,8 @@  int cursor_hide(struct vidconsole_cursor *curs, struct video_priv *vid_priv,
 	return 0;
 }
 
-int console_alloc_cursor(struct udevice *dev, struct vidconsole_ctx *ctx)
+int console_alloc_cursor(struct udevice *dev, struct vidconsole_cursor *curs)
 {
-	struct vidconsole_cursor *curs;
 	struct video_priv *vid_priv;
 	struct udevice *vid;
 	int save_count;
@@ -291,7 +290,6 @@  int console_alloc_cursor(struct udevice *dev, struct vidconsole_ctx *ctx)
 		return 0;
 	vid = dev_get_parent(dev);
 	vid_priv = dev_get_uclass_priv(vid);
-	curs = &ctx->curs;
 
 	/* Allocate cursor save buffer for maximum possible cursor height */
 	save_count = vid_priv->ysize * VIDCONSOLE_CURSOR_WIDTH;
@@ -302,6 +300,11 @@  int console_alloc_cursor(struct udevice *dev, struct vidconsole_ctx *ctx)
 	return 0;
 }
 
+void console_free_cursor(struct vidconsole_cursor *curs)
+{
+	free(curs->save_data);
+}
+
 int console_probe(struct udevice *dev)
 {
 	int ret;
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 83cd1651205..b22408dc2a4 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -749,7 +749,7 @@  static void vidconsole_free_ctx(struct udevice *dev, struct vidconsole_ctx *ctx)
 {
 	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
 
-	free(ctx->curs.save_data);
+	console_free_cursor(&ctx->curs);
 	if (ops->ctx_dispose)
 		ops->ctx_dispose(dev, ctx);
 }
@@ -951,7 +951,7 @@  static int vidconsole_post_probe(struct udevice *dev)
 	int ret;
 
 	if (CONFIG_IS_ENABLED(CURSOR) && xpl_phase() == PHASE_BOARD_R) {
-		ret = console_alloc_cursor(dev, ctx);
+		ret = console_alloc_cursor(dev, &ctx->curs);
 		if (ret)
 			return ret;
 	}
diff --git a/drivers/video/vidconsole_internal.h b/drivers/video/vidconsole_internal.h
index 23d29fea081..b5ffdfad4da 100644
--- a/drivers/video/vidconsole_internal.h
+++ b/drivers/video/vidconsole_internal.h
@@ -152,10 +152,19 @@  int cursor_hide(struct vidconsole_cursor *curs, struct video_priv *vid_priv,
  * Allocates memory for saving pixels under the cursor
  *
  * @dev: vidconsole device
- * @ctx: vidconsole context
+ * @curs: cursor to set up
  * Return: 0 if success, -ENOMEM if allocation fails
  */
-int console_alloc_cursor(struct udevice *dev, struct vidconsole_ctx *ctx);
+int console_alloc_cursor(struct udevice *dev, struct vidconsole_cursor *curs);
+
+/**
+ * console_free_cursor() - Free cursor memory
+ *
+ * Free the memory used by a cursor
+ *
+ * @curs: cursor to set up
+ */
+void console_free_cursor(struct vidconsole_cursor *curs);
 
 /**
  * console probe function.