From patchwork Mon Nov 14 21:49:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 1703761 X-Patchwork-Delegate: sjg@chromium.org 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 (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=vV/UbIOb; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=ukIAHd0d; 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 4NB2zj6q6nz23mH for ; Tue, 15 Nov 2022 08:50:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8787B84CDF; Mon, 14 Nov 2022 22:50:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1668462617; bh=kUl4pnqspz101FFXIcukNrz6rHmd4JYH9WeewGGDCQ4=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=vV/UbIObZby8DpA8S/6mJKhpkbLAKkV2OzP71cASjGJOIxGBHLWSskPz6qyT3Jq5/ Wx+6e4tgFX9m51XRcwsULti0pQSAY6gXplhjR5+OWLWhLUsUPLZsAQQcOOwFZJ3m4K v8KOb5ImGHK8BTZqD50qTtjWibJniA+XiIhxVpyYXp52dnXn+b+iRVesz1nW8/t/1/ YY81t7k14EYCfX04Jlm4dHu7NcYasti4cdQoIk7qPK7uRjk+YsJlK4xUE6tvP7ps3M QTlVPNElpsJpjOMIuhw613w6P1yR+taEOF+HLg06ZfPuuCp+ZS7GOKZzVUswyutq4M 7fHCE+TipxMEA== Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 039D980FED; Mon, 14 Nov 2022 22:50:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1668462616; bh=kUl4pnqspz101FFXIcukNrz6rHmd4JYH9WeewGGDCQ4=; h=From:To:Cc:Subject:Date:From; b=ukIAHd0dIfKbSGMGESZ4pmMaTnNphc6zgxuJn41Kr6c7/iP3dZUEGXdDHzi9sCjRd 8mY+OlLJrOdv6yRYDgadgxFxZep5zXXJbEoet3btnpHZ4BfsTpnWwNtejfLBen4TBk oDDiJ+vARYEWWTcFouU31kqJ7VXowyb/BxajC8ldjnngoQ85qIs9JhZ4hEk6+wk3t0 eOvqmMomrqhqZFttsAEHry89cNA7GnVtDMKWrPGF8ggnnSa2e45DjvyICWlheSJYOG 2z2gwRzijiATeu9tuxtsuTkLAI9uxthnCJO+i3wWeJIs5D9Ay7eu2nTixL3B9NpYpo c5deqeaej8dvA== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Heinrich Schuchardt , Simon Glass , Tom Rini Subject: [PATCH v2 1/2] cmd: fdt: Fix iteration over elements above index 1 in fdt get Date: Mon, 14 Nov 2022 22:49:59 +0100 Message-Id: <20221114215000.94947-1-marex@denx.de> X-Mailer: git-send-email 2.35.1 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.6 at phobos.denx.de X-Virus-Status: Clean Always increment both the iterator and pointer into the string property value by length of the current element + 1 (to cater for the string delimiter), otherwise the element extracted from the string property value would be extracted from an offset that is multiple of the length of the first element, instead of sum of element lengths until select index. This fixes 'fdt get value' operation for index above 1 (counting from index 0). Acked-by: Heinrich Schuchardt Fixes: 13982ced2cc ("cmd: fdt: Add support for reading stringlist property values") Signed-off-by: Marek Vasut Acked-by: Heinrich Schuchardt Signed-off-by: Marek Vasut --- Cc: Heinrich Schuchardt Cc: Simon Glass Cc: Tom Rini --- V2: - Update commit message, use index above 1 and clarify the counting is zero-based - Add AB from Heinrich --- cmd/fdt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/fdt.c b/cmd/fdt.c index 4b2dcfec863..8e51a431261 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -60,11 +60,14 @@ static int fdt_value_env_set(const void *nodep, int len, * Iterate over all members in stringlist and find the one at * offset $index. If no such index exists, indicate failure. */ - for (i = 0; i < len; i += strlen(nodec) + 1) { - if (index-- > 0) + for (i = 0; i < len; ) { + if (index-- > 0) { + i += strlen(nodec) + 1; + nodec += strlen(nodec) + 1; continue; + } - env_set(var, nodec + i); + env_set(var, nodec); return 0; }