From patchwork Thu Jun 1 16:22:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1789214 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=IJdSNNo/; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QXBLW3VH4z20Py for ; Fri, 2 Jun 2023 02:25:07 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 63A6986335; Thu, 1 Jun 2023 18:24:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="IJdSNNo/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C287E86339; Thu, 1 Jun 2023 18:24:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8A8798633C for ; Thu, 1 Jun 2023 18:24:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-33b1da9a8acso4143225ab.3 for ; Thu, 01 Jun 2023 09:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1685636668; x=1688228668; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sH1MStrfrc0dITNI61OOiPcdt1ZzQlPVTttqvWuPOoI=; b=IJdSNNo/uM3mTOax6ET06mepxGoIJizv7NnMuQ/I3hY3y2W0H+o2BwLuGieGdtnq+a 1S4wKKamux6xZRqpCPMMPdJ63IiMME90zgJ4LmetlRLki2FNFuVJEzGJLfp7x+VJyuTk KnY2NFHaquBOm0OLqa5g1jzRaTGkl3CzolWe4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685636668; x=1688228668; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sH1MStrfrc0dITNI61OOiPcdt1ZzQlPVTttqvWuPOoI=; b=Vg3nW5tKVsFPE2YK4/dW6r9F7y8edzzazEKHw+SYTg9Dc9AuweZjyD46IT1AS7cbGA NXVNPypnFc9xTUgbKMH4i+7jeHjSoIzIee6jV+nc1r0EoQP6okfUDECpT9nlmbxTbU6c 5/54ULMXW5OkpsJLjNYe42RnHdemiWB5uflSw9R617ncYC0N2D/VI0A7yvp7+RwlW462 8RGW6DHE2v+NzWhcuO0WCH84Rq3/8UwjDnkz35nS3TFotODcCC+fNcCzS6qfGBnCEZGw H9gHD5Quo0BrAeTEqj3BtuUQAIHyGGjCI2yTDAYiG9QYH0DAiCWqwFxD8WIA7Z3WKohJ VzhA== X-Gm-Message-State: AC+VfDyfGqh7ITLphzkzV93zQnNLdQck5wLiRABewfgQrb2n3W24eoHa BD3Uc3WVrrAI4ymDkFPGDep/dixkaHqH1cjBdLQ= X-Google-Smtp-Source: ACHHUZ5aNWo5LTXQP0JVoUWkkoFs8EitCyIQz6Rv7WopgyqzE9s2pIWpuXchmMzmLAd75O+DU2vWBg== X-Received: by 2002:a92:cf02:0:b0:338:d50f:f5e2 with SMTP id c2-20020a92cf02000000b00338d50ff5e2mr6356894ilo.18.1685636668070; Thu, 01 Jun 2023 09:24:28 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id l1-20020a922901000000b0033a6e7ee4e3sm3862098ilg.1.2023.06.01.09.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 09:24:27 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Tom Rini , Simon Glass Subject: [PATCH 03/40] expo: Convert to using a string ID for the scene title Date: Thu, 1 Jun 2023 10:22:27 -0600 Message-ID: <20230601102257.3.I2cf67d2d512c67904f8f1b9df25e8d8dcdfd01d2@changeid> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog In-Reply-To: <20230601162404.220488-1-sjg@chromium.org> References: <20230601162404.220488-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This is easier to deal with if it uses the existing string handling, since we will be able to use translations, etc. in the future. Update it to use an ID instead of a string. Signed-off-by: Simon Glass --- boot/scene.c | 8 ++------ include/expo.h | 10 +++++----- test/boot/expo.c | 19 ++++++++++--------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/boot/scene.c b/boot/scene.c index 030f6aa2a0a9..d2f77c008cf7 100644 --- a/boot/scene.c +++ b/boot/scene.c @@ -65,16 +65,12 @@ void scene_destroy(struct scene *scn) scene_obj_destroy(obj); free(scn->name); - free(scn->title); free(scn); } -int scene_title_set(struct scene *scn, const char *title) +int scene_title_set(struct scene *scn, uint id) { - free(scn->title); - scn->title = strdup(title); - if (!scn->title) - return log_msg_ret("tit", -ENOMEM); + scn->title_id = id; return 0; } diff --git a/include/expo.h b/include/expo.h index d242f48e30c7..8827f4b0b45f 100644 --- a/include/expo.h +++ b/include/expo.h @@ -92,7 +92,7 @@ struct expo_string { * @expo: Expo this scene is part of * @name: Name of the scene (allocated) * @id: ID number of the scene - * @title: Title of the scene (allocated) + * @title_id: String ID of title of the scene (allocated) * @sibling: Node to link this scene to its siblings * @obj_head: List of objects in the scene */ @@ -100,7 +100,7 @@ struct scene { struct expo *expo; char *name; uint id; - char *title; + uint title_id; struct list_head sibling; struct list_head obj_head; }; @@ -338,10 +338,10 @@ struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id); * scene_title_set() - set the scene title * * @scn: Scene to update - * @title: Title to set, NULL if none (this is allocated by this call) - * Returns: 0 if OK, -ENOMEM if out of memory + * @title_id: Title ID to set + * Returns: 0 if OK */ -int scene_title_set(struct scene *scn, const char *title); +int scene_title_set(struct scene *scn, uint title_id); /** * scene_obj_count() - Count the number of objects in a scene diff --git a/test/boot/expo.c b/test/boot/expo.c index 7104dff05e8d..3c0bc78bb7a4 100644 --- a/test/boot/expo.c +++ b/test/boot/expo.c @@ -28,6 +28,8 @@ enum { OBJ_MENU_TITLE, /* strings */ + STR_SCENE_TITLE, + STR_TEXT, STR_TEXT2, STR_MENU_TITLE, @@ -120,7 +122,7 @@ static int expo_scene(struct unit_test_state *uts) struct expo *exp; ulong start_mem; char name[100]; - int id; + int id, title_id; start_mem = ut_check_free(); @@ -141,21 +143,20 @@ static int expo_scene(struct unit_test_state *uts) ut_asserteq_str(SCENE_NAME1, scn->name); /* Set the title */ - strcpy(name, SCENE_TITLE); - ut_assertok(scene_title_set(scn, name)); - *name = '\0'; - ut_assertnonnull(scn->title); - ut_asserteq_str(SCENE_TITLE, scn->title); + title_id = expo_str(exp, "title", STR_SCENE_TITLE, SCENE_TITLE); + ut_assert(title_id >= 0); - /* Use an allocated ID */ + /* Use an allocated ID - this will be allocated after the title str */ scn = NULL; id = scene_new(exp, SCENE_NAME2, 0, &scn); ut_assertnonnull(scn); - ut_asserteq(SCENE2, id); - ut_asserteq(SCENE2 + 1, exp->next_id); + ut_assertok(scene_title_set(scn, title_id)); + ut_asserteq(STR_SCENE_TITLE + 1, id); + ut_asserteq(STR_SCENE_TITLE + 2, exp->next_id); ut_asserteq_ptr(exp, scn->expo); ut_asserteq_str(SCENE_NAME2, scn->name); + ut_asserteq(title_id, scn->title_id); expo_destroy(exp);