Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CF623C46CD2 for ; Fri, 22 Dec 2023 21:32:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4EE65877CD; Fri, 22 Dec 2023 22:31:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="iW8XjkGq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BBF73877CA; Fri, 22 Dec 2023 22:31:57 +0100 (CET) Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) (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 D673E877CD for ; Fri, 22 Dec 2023 22:31:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=raymond.mao@linaro.org Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-78120bb5592so105512585a.3 for ; Fri, 22 Dec 2023 13:31:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703280712; x=1703885512; darn=lists.denx.de; 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=90S5eGrJX62iUtWwdZTLVpCYSWiJCMPx+KDc/k+BtAo=; b=iW8XjkGqa81daoxipDpZNW2wVuwxxvgGKXjZtGCOnuJjV3YOUwjgGp0Ivn2Ju1CSda TQby7lXby3DB5OBweZ5lDLgLr/MVwGnjFktU1gET6Dvy9v6X/wS8vbBne40i8VQj7pO7 jxvixzqJsHSb0Vl1kuyb15O8vvl5qLeoPEpPMwtMn/bmeeLyBu6tcmx9x/Q/s66SLN0z kUy6D7vTMB/Yq0Xu5G2Rfso40mSz1wET+ZnmgeJpEp5JIl7r7YnXm+oELPaej4UAbE0N E5h6ZOn1FLIQJINvVwDFs3/Aj3hpToKZdoCe13pWNF8JIULyYM9kL+pl8GoWdEgl1K+4 TE6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703280712; x=1703885512; 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=90S5eGrJX62iUtWwdZTLVpCYSWiJCMPx+KDc/k+BtAo=; b=AH8m/b0nlOCWnIz+hG/JIE5fyrv3e+/nzDubM+TDavrs8OnQ1DUJljQhXoRJbYQYYw oRu6boVmnOM4pKhzpImCwS00gsfFh7jPflCtDdF7vygrZUpumahPXrVUNP4/YiOsvlzt jMJwpEuiJ5ldSqGg1pUVSpBiV3gtZoYGr2aLSKA+TBxOpAdzg88ctpccMxzAypnNcdwg /RZ4pGXGiZJ5MpfuIXNtd8pUU5sSzpQ9BOjVqthrEd06nNKkUQnHDDxHefnzbd/9ItR3 EBDXOce5bRlMfnEB9FZMB3BPKDOoe2h/wV/EAawMQSH+l2XcQSTtP4VAXIWm4bIbod3t X+kw== X-Gm-Message-State: AOJu0YwcJiWWUPh6cRtr54Rz+C/OMWA3rX4ycvz1gXY03Wg0jyP1lvZw Ydf/CoOenaoI7a0dRsGUU6fYDLDf0WaEw8M5gPJVQ8198yE= X-Google-Smtp-Source: AGHT+IEQ6I7hP8Y9XNQRBsnG1S2R3od0Zah3dDpOl4dErSxoNAQEBiMnerWRVUMpgcX4+tb5IQS1mw== X-Received: by 2002:a05:6214:500e:b0:67a:a721:ec03 with SMTP id jo14-20020a056214500e00b0067aa721ec03mr2070003qvb.71.1703280712200; Fri, 22 Dec 2023 13:31:52 -0800 (PST) Received: from ubuntu.localdomain (cpe688f2e182063-cm688f2e182060.sdns.net.rogers.com. [174.115.4.214]) by smtp.gmail.com with ESMTPSA id dm6-20020ad44e26000000b0067f6ec98ae9sm1623096qvb.32.2023.12.22.13.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 13:31:51 -0800 (PST) From: Raymond Mao To: u-boot@lists.denx.de, ilias.apalodimas@linaro.org, sjg@chromium.org, jwerner@chromium.org Cc: Raymond Mao , Tuomas Tynkkynen , Kevin Chen , Nikhil M Jain , Bin Meng , Devarsh Thakkar , Kunihiko Hayashi , Heinrich Schuchardt , Marek Vasut , Shiji Yang , Baruch Siach , Michal Simek , Sean Anderson , Stefan Roese Subject: [PATCH v3 3/9] bloblist: refactor of bloblist_reloc() Date: Fri, 22 Dec 2023 13:31:03 -0800 Message-Id: <20231222213110.660402-4-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231222213110.660402-1-raymond.mao@linaro.org> References: <20231222213110.660402-1-raymond.mao@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 The current bloblist pointer and size can be retrieved from global data, so we don't need to pass them from the function arguments. This change also help to remove all external access of gd->bloblist outside of bloblist module. Signed-off-by: Raymond Mao --- Changes in v2 - New patch file created for v2. Changes in v3 - Check the space size before copying the bloblist. - Add return code of bloblist_reloc(). common/bloblist.c | 10 ++++++++-- common/board_f.c | 8 ++------ include/bloblist.h | 8 ++++---- test/bloblist.c | 6 ++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/common/bloblist.c b/common/bloblist.c index db3fbb20cf..5ad1db137a 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -472,13 +472,19 @@ void bloblist_show_list(void) } } -void bloblist_reloc(void *to, uint to_size, void *from, uint from_size) +int bloblist_reloc(void *to, uint to_size) { struct bloblist_hdr *hdr; - memcpy(to, from, from_size); + if (to_size < gd->bloblist->total_size) + return -ENOSPC; + + memcpy(to, gd->bloblist, gd->bloblist->total_size); hdr = to; hdr->total_size = to_size; + gd->bloblist = to; + + return 0; } int bloblist_init(void) diff --git a/common/board_f.c b/common/board_f.c index d4d7d01f8f..00b0430889 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -676,13 +676,9 @@ static int reloc_bloblist(void) return 0; } if (gd->new_bloblist) { - int size = CONFIG_BLOBLIST_SIZE; - debug("Copying bloblist from %p to %p, size %x\n", - gd->bloblist, gd->new_bloblist, size); - bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC, - gd->bloblist, size); - gd->bloblist = gd->new_bloblist; + gd->bloblist, gd->new_bloblist, gd->bloblist->total_size); + bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC); } #endif diff --git a/include/bloblist.h b/include/bloblist.h index bd32e38a06..c1dab11f78 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -418,11 +418,11 @@ const char *bloblist_tag_name(enum bloblist_tag_t tag); * bloblist_reloc() - Relocate the bloblist and optionally resize it * * @to: Pointer to new bloblist location (must not overlap old location) - * @to_size: New size for bloblist (must be larger than from_size) - * @from: Pointer to bloblist to relocate - * @from_size: Size of bloblist to relocate + * @to_size: New size for bloblist + * Return: 0 if OK, -ENOSPC if the new size is small than the bloblist total + * size. */ -void bloblist_reloc(void *to, uint to_size, void *from, uint from_size); +int bloblist_reloc(void *to, uint to_size); /** * bloblist_init() - Init the bloblist system with a single bloblist diff --git a/test/bloblist.c b/test/bloblist.c index 7dab9addf8..1c60bbac36 100644 --- a/test/bloblist.c +++ b/test/bloblist.c @@ -376,13 +376,12 @@ static int bloblist_test_reloc(struct unit_test_state *uts) { const uint large_size = TEST_BLOBLIST_SIZE; const uint small_size = 0x20; - void *old_ptr, *new_ptr; + void *new_ptr; void *blob1, *blob2; ulong new_addr; ulong new_size; ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); - old_ptr = map_sysmem(TEST_ADDR, TEST_BLOBLIST_SIZE); /* Add one blob and then one that won't fit */ blob1 = bloblist_add(TEST_TAG, small_size, 0); @@ -394,8 +393,7 @@ static int bloblist_test_reloc(struct unit_test_state *uts) new_addr = TEST_ADDR + TEST_BLOBLIST_SIZE; new_size = TEST_BLOBLIST_SIZE + 0x100; new_ptr = map_sysmem(new_addr, TEST_BLOBLIST_SIZE); - bloblist_reloc(new_ptr, new_size, old_ptr, TEST_BLOBLIST_SIZE); - gd->bloblist = new_ptr; + ut_assertok(bloblist_reloc(new_ptr, new_size)); /* Check the old blob is there and that we can now add the bigger one */ ut_assertnonnull(bloblist_find(TEST_TAG, small_size)); -- 2.25.1