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 80AB9C2BB41 for ; Wed, 17 Aug 2022 08:28:13 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C4DF984998; Wed, 17 Aug 2022 10:28:07 +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="gAR8stLU"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="NZVKacVN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 475EF8498F; Wed, 17 Aug 2022 10:28:05 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) (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 86A8E84979 for ; Wed, 17 Aug 2022 10:27:59 +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-out2.suse.de (Postfix) with ESMTP id 44C981FB5C; Wed, 17 Aug 2022 08:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1660724879; 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=Vt1C0/ZRsUmwN2tvekgg8N6vf/BjTCWmYJIQN3CdO7Q=; b=gAR8stLUGWLCXSUiRlZgmHV1WXPOjcC6jqTICdcRMml609NxYsG9NXrr5QDGLwg4LvPwwi GGBuRnlqc4ERyfUsviAK5DWi5xHQ25aVRc0yyWJR7d2gqCoCffCkLBL66aEHXqYx7tbp/P y6oEXo4VkoC7urGBkqgeo67c+jI5XA4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1660724879; 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=Vt1C0/ZRsUmwN2tvekgg8N6vf/BjTCWmYJIQN3CdO7Q=; b=NZVKacVNGREzfj9E1+g/D+c6Lm6Di6GdeI+wVUjYfovYnGn/iznFHGa9gMiWyxWQUJcO3l p0VaiEJ1OzU3K5Cg== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id 0B7B42C178; Wed, 17 Aug 2022 08:27:59 +0000 (UTC) From: Michal Suchanek To: Simon Glass , U-Boot Mailing List Cc: Michal Suchanek , Tomas Hlavacek , Marek Vasut , =?UTF-8?q?Viktor=20K=C5=99iv=C3=A1k?= , Pavel Herrmann Subject: [PATCH v2] dm: core: Do not stop uclass iteration on error. Date: Wed, 17 Aug 2022 10:27:52 +0200 Message-Id: <20220817082752.12160-1-msuchanek@suse.de> X-Mailer: git-send-email 2.37.1 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 When probing a device fails NULL pointer is returned, and other devices cannot be iterated. Skip to next device on error instead. Fixes: 6494d708bf ("dm: Add base driver model support") Signed-off-by: Michal Suchanek --- v2: Fix up tests Note: there is seemingly bogus repeated device_remove(parent, DM_REMOVE_NORMAL); but I have no idea what the intent was, and fixing that is out of the scope of this patch anyway. drivers/core/uclass.c | 30 +++++++++++++++++++++--------- test/dm/test-fdt.c | 20 ++++++++++++++++---- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 08d9ed82de..ccf7d59141 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -574,16 +574,31 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent, } #endif +/* Starting from the given device return first device in the uclass that probes successfully */ +static int __uclass_next_device(struct udevice *dev, int ret, struct udevice **devp) +{ + if (!dev) { + *devp = dev; + return 0; + } + while ((ret = uclass_get_device_tail(dev, ret, devp))) { + ret = uclass_find_next_device(&dev); + if (!dev) { + *devp = dev; + return 0; + } + } + + return ret; +} + int uclass_first_device(enum uclass_id id, struct udevice **devp) { - struct udevice *dev; + struct udevice *dev = NULL; int ret; - *devp = NULL; ret = uclass_find_first_device(id, &dev); - if (!dev) - return 0; - return uclass_get_device_tail(dev, ret, devp); + return __uclass_next_device(dev, ret, devp); } int uclass_first_device_err(enum uclass_id id, struct udevice **devp) @@ -604,11 +619,8 @@ int uclass_next_device(struct udevice **devp) struct udevice *dev = *devp; int ret; - *devp = NULL; ret = uclass_find_next_device(&dev); - if (!dev) - return 0; - return uclass_get_device_tail(dev, ret, devp); + return __uclass_next_device(dev, ret, devp); } int uclass_next_device_err(struct udevice **devp) diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 6118ad42ca..165b4f5554 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -417,16 +417,28 @@ static int dm_test_first_next_device(struct unit_test_state *uts) pdata = dev_get_plat(dev); pdata->probe_err = -ENOMEM; device_remove(parent, DM_REMOVE_NORMAL); - ut_assertok(uclass_first_device(UCLASS_TEST_PROBE, &dev)); - ut_asserteq(-ENOMEM, uclass_next_device(&dev)); - ut_asserteq_ptr(dev, NULL); + for (ret = uclass_first_device(UCLASS_TEST_PROBE, &dev), count = 0; + dev; + ret = uclass_next_device(&dev)) { + count++; + parent = dev_get_parent(dev); + } + ut_assertok(ret); + ut_asserteq(3, count); /* Now an error on the first one */ ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 0, &dev)); pdata = dev_get_plat(dev); pdata->probe_err = -ENOENT; device_remove(parent, DM_REMOVE_NORMAL); - ut_asserteq(-ENOENT, uclass_first_device(UCLASS_TEST_PROBE, &dev)); + for (ret = uclass_first_device(UCLASS_TEST_PROBE, &dev), count = 0; + dev; + ret = uclass_next_device(&dev)) { + count++; + parent = dev_get_parent(dev); + } + ut_assertok(ret); + ut_asserteq(2, count); return 0; } -- 2.37.1