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 2E994EB64DD for ; Tue, 25 Jul 2023 21:38:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5D1A386824; Tue, 25 Jul 2023 23:37:44 +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="d0t4NgN1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1E7DE86789; Tue, 25 Jul 2023 23:37:03 +0200 (CEST) Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) (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 52366867DF for ; Tue, 25 Jul 2023 23:36:56 +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-io1-xd30.google.com with SMTP id ca18e2360f4ac-783549ef058so312545039f.2 for ; Tue, 25 Jul 2023 14:36:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1690321014; x=1690925814; 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=hbYPg/0qCXm809ynGlCOwqRtu7skyiVWwFmrlOw+GBI=; b=d0t4NgN1EHxpTASuihzeIegWO5zEax8IocxOSEHl1OoPIw4VeLj3W4EDHUfW++IMbI jrD+yku8aWt3FJdfrtov55U9LNXNjbM62FDvMzglkyqod4hYuf1AuGW3Hqt+rOJ+c4om MATI3YebNY92bu3mvaEjI/R/37/uabz//BX2A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690321014; x=1690925814; 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=hbYPg/0qCXm809ynGlCOwqRtu7skyiVWwFmrlOw+GBI=; b=Ap+2OKZvw2DdYPj2gntShIETVMTXOkBRiNl2/j508D1NbuJgqWwEFCbtGzTPCq/01a Got2ORpKC/kgNgj9mfLVVe9CQU4oWjVhjdTgKviYGXklus/Hv+NAqlsKLur9lcvQtd/3 DQzexWSntXXhXyKNjR7rl15SiOw7g4zaTjsWSM/0qVcn3cKS3XBVFt36TYBQCvG5aGRV pm4YS3kNXZf4lEPohaXiUQ0lhrpKrVe/mIbaMfbjsjMYZE4c0bK42Cm4l8EZHUDfnlIO pziiFtgrIwEh7ZS8gYvHp/zxXGgKn+ixNGDLFSR3B7Cc2+1zLoYhNkz1QMw+eF7rgZvE FSMA== X-Gm-Message-State: ABy/qLbp+I3e8aCF26ZzANMSxoVdRfcvSBU6YVmKjEZOI6MGIqJR4zO8 UUVu2NfuXvfdTGQynnXdu+/RIiJwEVv7xXX5LWU= X-Google-Smtp-Source: APBJJlES8T4xfZoC7AXtMP5+v38kvxWUDIZjQ0Ee0TYzJjrNzdL4v4Lm9194ep/KIQzVIE6B6eivjw== X-Received: by 2002:a6b:f20e:0:b0:787:8cf:fe8a with SMTP id q14-20020a6bf20e000000b0078708cffe8amr137450ioh.2.1690321014324; Tue, 25 Jul 2023 14:36:54 -0700 (PDT) Received: from kea.bld.corp.google.com ([2620:15c:183:200:ce78:3dad:1309:8d43]) by smtp.gmail.com with ESMTPSA id ep18-20020a0566384e1200b0042b2d43ee3fsm3891987jab.82.2023.07.25.14.36.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 14:36:54 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Ilias Apalodimas , Tom Rini , Julius Werner , Dan Handley , Jose Marinho , Simon Glass , Bin Meng , Nikhil M Jain Subject: [PATCH 10/14] bloblist: Handle alignment with a void entry Date: Tue, 25 Jul 2023 15:36:22 -0600 Message-ID: <20230725213634.255345-11-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230725213634.255345-1-sjg@chromium.org> References: <20230725213634.255345-1-sjg@chromium.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 Rather than setting the alignment using the header size, add an entirely new entry to cover the gap left by the alignment. Signed-off-by: Simon Glass --- common/bloblist.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/common/bloblist.c b/common/bloblist.c index df5c63dae15..0ab82d3cdbc 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -131,7 +131,7 @@ static int bloblist_addrec(uint tag, int size, int align_log2, { struct bloblist_hdr *hdr = gd->bloblist; struct bloblist_rec *rec; - int data_start, new_alloced; + int data_start, aligned_start, new_alloced; if (!align_log2) align_log2 = BLOBLIST_ALIGN_LOG2; @@ -140,10 +140,25 @@ static int bloblist_addrec(uint tag, int size, int align_log2, data_start = map_to_sysmem(hdr) + hdr->alloced + sizeof(*rec); /* Align the address and then calculate the offset from ->alloced */ - data_start = ALIGN(data_start, 1U << align_log2) - map_to_sysmem(hdr); + aligned_start = ALIGN(data_start, 1U << align_log2) - data_start; + + /* If we need to create a dummy record, create it */ + if (aligned_start) { + int void_size = aligned_start - sizeof(*rec); + struct bloblist_rec *vrec; + int ret; + + ret = bloblist_addrec(BLOBLISTT_VOID, void_size, 0, &vrec); + if (ret) + return log_msg_ret("void", ret); + + /* start the record after that */ + data_start = map_to_sysmem(hdr) + hdr->alloced + sizeof(*vrec); + } /* Calculate the new allocated total */ - new_alloced = data_start + ALIGN(size, 1U << align_log2); + new_alloced = data_start - map_to_sysmem(hdr) + + ALIGN(size, 1U << align_log2); if (new_alloced > hdr->size) { log_err("Failed to allocate %x bytes size=%x, need size=%x\n", @@ -153,7 +168,7 @@ static int bloblist_addrec(uint tag, int size, int align_log2, rec = (void *)hdr + hdr->alloced; rec->tag = tag; - rec->hdr_size = data_start - hdr->alloced; + rec->hdr_size = sizeof(struct bloblist_rec); rec->size = size; /* Zero the record data */ -- 2.41.0.487.g6d72f3e995-goog