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 13CBBC38142 for ; Sun, 22 Jan 2023 00:03:17 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6251685509; Sun, 22 Jan 2023 01:03:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sholland.org header.i=@sholland.org header.b="Ww6/Doqg"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="R0JxhCW3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0EFA085477; Sun, 22 Jan 2023 01:03:02 +0100 (CET) Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CEFFE85509 for ; Sun, 22 Jan 2023 01:02:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=samuel@sholland.org Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id CA0673200583; Sat, 21 Jan 2023 19:02:54 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sat, 21 Jan 2023 19:02:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1674345774; x=1674432174; bh=w8 477QEeVx3sUdDEglQX5cfXH0EPgvWhQl+y+QzWxks=; b=Ww6/DoqgveYG503qGu ctu/17p7sqwozY5TtuP5X69F9abFjQwKDORYaOmt/xaQVYgFreMGFVctmSohW6po IFJ4MH4B/KBmFIX0pFjyQz0pAwUvK5+0KEgW9Gwn5NL20qwEwZW/pU+kNVHF3gWT i10GqHfngoIE6ziizXYwb78K6Z02WsGgkkzFpum6M5EqkBaqTWXwyeVHsltrgY0l g+lDkPHO/Eyd6jVyjWn2QdnZQWXu563yCjVElzA1MQHHwUY0afS3H9ZyvhQuLKEU wrJPhqI+Uz7U01hstD87Efor8r9pobMfT5jvElRUG8oyfzDraN9jOv/n6wy4gn5f Vyhg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1674345774; x=1674432174; bh=w8477QEeVx3sU dDEglQX5cfXH0EPgvWhQl+y+QzWxks=; b=R0JxhCW3zGN99aoOoq7rG0yLkmdri EooyMtwqNuhewPA8mcHe1xnYFU67kQ5xT7y2CeHDeEQKcrDWxDiY4HOdFkjPAleX /P/yDbhOBnGemM2OiNHBLMwD5MkXJeFdfQTX69DD670Dn0l5vOD5wI9/r8pGYp6H zKM1cibobXNBonXf6NSsfhP7gf7J8Ja0Qa/49niBTkuKXX2+jEVxfTeH2pfkqEpD hfpxbZtCAkoQ38l/NUpCaB5u+1LTyZHlmegH6LIHYKmmAiTQNBVfj0FCUcXaySGW me6xOJgwlGObOveULY4eBXZav6wtJZZNTSNGgpUUjaZ6eYaNQjwbmtEFA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudduhedgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepufgrmhhu vghlucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecugg ftrfgrthhtvghrnhepudekteeuudehtdelteevgfduvddvjefhfedulefgudevgeeghefg udefiedtveetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepshgrmhhuvghlsehshhholhhlrghnugdrohhrgh X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 21 Jan 2023 19:02:53 -0500 (EST) From: Samuel Holland To: Lukasz Majewski , Sean Anderson , Simon Glass Cc: Samuel Holland , Dario Binacchi , Michal Suchanek , u-boot@lists.denx.de, Marek Vasut Subject: [PATCH v2 2/2] reset: Allow reset_get_by_name() with NULL name Date: Sat, 21 Jan 2023 18:02:52 -0600 Message-Id: <20230122000252.53642-2-samuel@sholland.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20230122000252.53642-1-samuel@sholland.org> References: <20230122000252.53642-1-samuel@sholland.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.6 at phobos.denx.de X-Virus-Status: Clean This allows devm_reset_control_get(dev, NULL) to work and get the first reset control, which is common in code ported from Linux. Signed-off-by: Samuel Holland --- Changes in v2: - Move index error check inside if statement - Update function comment - Add unit test drivers/reset/reset-uclass.c | 12 +++++++----- include/reset.h | 3 ++- test/dm/reset.c | 3 +-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c index bcef46039c..b972faf013 100644 --- a/drivers/reset/reset-uclass.c +++ b/drivers/reset/reset-uclass.c @@ -147,16 +147,18 @@ int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk) int reset_get_by_name(struct udevice *dev, const char *name, struct reset_ctl *reset_ctl) { - int index; + int index = 0; debug("%s(dev=%p, name=%s, reset_ctl=%p)\n", __func__, dev, name, reset_ctl); reset_ctl->dev = NULL; - index = dev_read_stringlist_search(dev, "reset-names", name); - if (index < 0) { - debug("fdt_stringlist_search() failed: %d\n", index); - return index; + if (name) { + index = dev_read_stringlist_search(dev, "reset-names", name); + if (index < 0) { + debug("fdt_stringlist_search() failed: %d\n", index); + return index; + } } return reset_get_by_index(dev, index, reset_ctl); diff --git a/include/reset.h b/include/reset.h index 965f02e0ce..036a786d2a 100644 --- a/include/reset.h +++ b/include/reset.h @@ -238,7 +238,8 @@ int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk); * * @dev: The client device. * @name: The name of the reset signal to request, within the client's - * list of reset signals. + * list of reset signals, or NULL to request the first reset + * signal in the list. * @reset_ctl: A pointer to a reset control struct to initialize. * Return: 0 if OK, or a negative error code. */ diff --git a/test/dm/reset.c b/test/dm/reset.c index 9c00452336..e2d6f45623 100644 --- a/test/dm/reset.c +++ b/test/dm/reset.c @@ -35,8 +35,7 @@ static int dm_test_reset_base(struct unit_test_state *uts) /* Get the same reset port in 2 different ways and compare */ ut_assertok(reset_get_by_index(dev, 0, &reset_method1)); - ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 0, - &reset_method1_1)); + ut_assertok(reset_get_by_name(dev, NULL, &reset_method1_1)); ut_assertok(reset_get_by_index(dev, 1, &reset_method2)); ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 1, &reset_method2_1)); -- 2.37.4