From mboxrd@z Thu Jan 1 00:00:00 1970 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 152C1C433FE for ; Wed, 12 Oct 2022 19:58:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D741F84F0C; Wed, 12 Oct 2022 21:58:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=suse.de 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=suse.de header.i=@suse.de header.b="Q5Jt/GzT"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="X3MN5giV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 708C384EB0; Wed, 12 Oct 2022 21:58:35 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (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 44FDF84E53 for ; Wed, 12 Oct 2022 21:58:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=msuchanek@suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 110DC21F7D; Wed, 12 Oct 2022 19:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1665604708; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WKbtfUS1PaYrMyg8belP7jpHDM2L6pw2NjJnY2FEJjI=; b=Q5Jt/GzTWRmR6NEmff0oiPaDeBACU2zNLxphFyIH1KqE3lp6ms/VDQyroIvfxfjlMbRlkl SHCl+boVSe+vmjdPEJfYz1bfWz9E0H7+EQQs3x4Wqw5L/JYh0D7Y+iUfPIu3wMsJpFjdh7 kJPFL1i5aQdT0s7jv+S2FCbjcwGjP7U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1665604708; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WKbtfUS1PaYrMyg8belP7jpHDM2L6pw2NjJnY2FEJjI=; b=X3MN5giVP400zDUbER8VPttwlTAYIqlSN7uw5TtfUdm/5AS1lVNJtr3thgmh8eBo1SICD5 nO3o9/DIrY0yOQDw== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id DBEB62C142; Wed, 12 Oct 2022 19:58:27 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Simon Glass , Vabhav Sharma , Sean Anderson , Stefan Roese Subject: [PATCH v6 01/20] dm: core: Fix uclass_probe_all to really probe all devices Date: Wed, 12 Oct 2022 21:57:50 +0200 Message-Id: <5bd8c43b77f3df8dfa47f7a9d9da7a192f1217da.1665604425.git.msuchanek@suse.de> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 uclass_probe_all uses uclass_first_device/uclass_next_device assigning the return value. The interface for getting meaningful error is uclass_first_device_check/uclass_next_device_check, use it. Also do not stop iteration when an error is encountered. Probing all devices includes those that happen to be after a failing device in the uclass order. Fixes: a59153dfeb ("dm: core: add function uclass_probe_all() to probe all devices") Signed-off-by: Michal Suchanek --- v6: add test --- drivers/core/uclass.c | 12 +++++------- test/dm/test-fdt.c | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 08d9ed82de..a591e22403 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -799,20 +799,18 @@ int uclass_pre_remove_device(struct udevice *dev) int uclass_probe_all(enum uclass_id id) { struct udevice *dev; - int ret; + int ret, err; - ret = uclass_first_device(id, &dev); - if (ret || !dev) - return ret; + err = uclass_first_device_check(id, &dev); /* Scanning uclass to probe all devices */ while (dev) { - ret = uclass_next_device(&dev); + ret = uclass_next_device_check(&dev); if (ret) - return ret; + err = ret; } - return 0; + return err; } int uclass_id_count(enum uclass_id id) diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 012f2f455f..1f14513d9f 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -392,10 +392,10 @@ DM_TEST(dm_test_fdt_offset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE); /** - * Test various error conditions with uclass_first_device() and - * uclass_next_device() + * Test various error conditions with uclass_first_device(), + * uclass_next_device(), and uclass_probe_all() */ -static int dm_test_first_next_device(struct unit_test_state *uts) +static int dm_test_first_next_device_probeall(struct unit_test_state *uts) { struct dm_testprobe_pdata *pdata; struct udevice *dev, *parent = NULL; @@ -428,9 +428,20 @@ static int dm_test_first_next_device(struct unit_test_state *uts) device_remove(parent, DM_REMOVE_NORMAL); ut_asserteq(-ENOENT, uclass_first_device(UCLASS_TEST_PROBE, &dev)); + /* Now that broken devices are set up test probe_all */ + device_remove(parent, DM_REMOVE_NORMAL); + /* There are broken devices so an error should be returned */ + ut_assert(uclass_probe_all(UCLASS_TEST_PROBE) < 0); + /* but non-error device should be probed nonetheless */ + ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 2, &dev)); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); + ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 3, &dev)); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); + return 0; } -DM_TEST(dm_test_first_next_device, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); +DM_TEST(dm_test_first_next_device_probeall, + UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); /* Test iteration through devices in a uclass */ static int dm_test_uclass_foreach(struct unit_test_state *uts) -- 2.37.3