From patchwork Tue Sep 27 21:37:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683597 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=NvsXx4LU; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Fve4TWwg; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY030MK2z1yqJ for ; Wed, 28 Sep 2022 07:38:27 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2587484E41; Tue, 27 Sep 2022 23:38:22 +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="NvsXx4LU"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Fve4TWwg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0FBA584E31; Tue, 27 Sep 2022 23:38:20 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 E5D8C84DE0 for ; Tue, 27 Sep 2022 23:38:17 +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 B1F8F21BCF; Tue, 27 Sep 2022 21:38:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314697; 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=APDVvUeTrg57gdisK6o0RvLEA4mnuYDl7Dj1IudHsxY=; b=NvsXx4LUVHT8yllFM4EF9XOy7h5hUOpCc7sP7FUWB0GGmtH/5gpSuX4nP1HxS2obONjuqI x62UW5wWL0mQbX9MdVI8gLAKbL088qJvwqkYW7qm4MG7TgT7Eq8f1gu6YTtcntTac/Oig4 2yJZTxYH0LSwBleM/J0bsP5PJIAyfkY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314697; 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=APDVvUeTrg57gdisK6o0RvLEA4mnuYDl7Dj1IudHsxY=; b=Fve4TWwgQdAxcTLR5LBI/cgaQasG/T08aCr5QooiUVxMy4Y7GuvFiksYUdaY3JJLkFwO6t u5LHck5SjsCImODw== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id 7F0052C188; Tue, 27 Sep 2022 21:38:17 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Simon Glass , Sean Anderson , Stefan Roese , Vabhav Sharma Subject: [PATCH v5 01/15] dm: core: Fix uclass_probe_all to really probe all devices Date: Tue, 27 Sep 2022 23:37:53 +0200 Message-Id: <420f314d458db9d40e104773254a61dab954442e.1664314043.git.msuchanek@suse.de> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 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 Reviewed-by: Simon Glass --- drivers/core/uclass.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 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) From patchwork Tue Sep 27 21:37:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683598 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 (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=cgTzQKb7; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=9F9gzpO8; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY0H3zn4z1yqJ for ; Wed, 28 Sep 2022 07:38:39 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E636184E16; Tue, 27 Sep 2022 23:38: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=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="cgTzQKb7"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="9F9gzpO8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 05EF484E0D; Tue, 27 Sep 2022 23:38:23 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 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 5E18384E08 for ; Tue, 27 Sep 2022 23:38:18 +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 28C6C21C08; Tue, 27 Sep 2022 21:38:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314698; 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=Yxr1lUP55kwCQQrGhrW8mMNyOhoXxktuP46uBmitetE=; b=cgTzQKb75M+2KmiFoOWni/Cl9C6h90po+Xe7o+SzB78kwc4BtERj2KS1t0uIXZyuH1D2DF 8hLmMXrdpkj5gebKmLSoTk3i2H3i+GfwYSR4EypuM1M5k5D8LAdus7j4Rkv4XafNRXg4Px yr+6IASvElmYw9kcXoFZnMsNbK/u/ec= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314698; 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=Yxr1lUP55kwCQQrGhrW8mMNyOhoXxktuP46uBmitetE=; b=9F9gzpO8mNgRvXTTMD0/ByVaakApAbyY7Fseq+QVj32kozZ6sNOvnEWDu6wYLpIfa2wqB6 hqker5fx/QOz09CQ== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id B89EE2C189; Tue, 27 Sep 2022 21:38:17 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Bin Meng , Simon Glass , Ovidiu Panait , Michal Simek , Heinrich Schuchardt Subject: [PATCH v5 02/15] dm: treewide: Do not opencode uclass_probe_all() Date: Tue, 27 Sep 2022 23:37:54 +0200 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 We already have a function for probing all devices of a specific class, use it. Signed-off-by: Michal Suchanek Reviewed-by: Simon Glass --- drivers/cpu/cpu-uclass.c | 20 ++++---------------- drivers/virtio/virtio-uclass.c | 15 +-------------- test/dm/core.c | 17 +++-------------- test/test-main.c | 11 +---------- 4 files changed, 9 insertions(+), 54 deletions(-) diff --git a/drivers/cpu/cpu-uclass.c b/drivers/cpu/cpu-uclass.c index 71e5900d70..a754832526 100644 --- a/drivers/cpu/cpu-uclass.c +++ b/drivers/cpu/cpu-uclass.c @@ -20,25 +20,13 @@ DECLARE_GLOBAL_DATA_PTR; int cpu_probe_all(void) { - struct udevice *cpu; - int ret; + int ret = uclass_probe_all(UCLASS_CPU); - ret = uclass_first_device(UCLASS_CPU, &cpu); if (ret) { - debug("%s: No CPU found (err = %d)\n", __func__, ret); - return ret; - } - - while (cpu) { - ret = uclass_next_device(&cpu); - if (ret) { - debug("%s: Error while probing CPU (err = %d)\n", - __func__, ret); - return ret; - } + debug("%s: Error while probing CPUs (err = %d %s)\n", + __func__, ret, errno_str(ret)); } - - return 0; + return ret; } int cpu_is_current(struct udevice *cpu) diff --git a/drivers/virtio/virtio-uclass.c b/drivers/virtio/virtio-uclass.c index 9e2d0e06a1..da4f2f26a6 100644 --- a/drivers/virtio/virtio-uclass.c +++ b/drivers/virtio/virtio-uclass.c @@ -183,21 +183,8 @@ void virtio_driver_features_init(struct virtio_dev_priv *priv, int virtio_init(void) { - struct udevice *bus; - int ret; - /* Enumerate all known virtio devices */ - ret = uclass_first_device(UCLASS_VIRTIO, &bus); - if (ret) - return ret; - - while (bus) { - ret = uclass_next_device(&bus); - if (ret) - break; - } - - return ret; + return uclass_probe_all(UCLASS_VIRTIO); } static int virtio_uclass_pre_probe(struct udevice *udev) diff --git a/test/dm/core.c b/test/dm/core.c index fd4d756972..84eb76ed5f 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -512,23 +512,15 @@ static int dm_test_leak(struct unit_test_state *uts) int i; for (i = 0; i < 2; i++) { - struct udevice *dev; int ret; - int id; dm_leak_check_start(uts); ut_assertok(dm_scan_plat(false)); ut_assertok(dm_scan_fdt(false)); - /* Scanning the uclass is enough to probe all the devices */ - for (id = UCLASS_ROOT; id < UCLASS_COUNT; id++) { - for (ret = uclass_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_next_device(&dev)) - ; - ut_assertok(ret); - } + ret = uclass_probe_all(UCLASS_TEST); + ut_assertok(ret); ut_assertok(dm_leak_check_end(uts)); } @@ -653,10 +645,7 @@ static int dm_test_children(struct unit_test_state *uts) ut_asserteq(2 + NODE_COUNT, dm_testdrv_op_count[DM_TEST_OP_PROBE]); /* Probe everything */ - for (ret = uclass_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_next_device(&dev)) - ; + ret = uclass_probe_all(UCLASS_TEST); ut_assertok(ret); ut_asserteq(total, dm_testdrv_op_count[DM_TEST_OP_PROBE]); diff --git a/test/test-main.c b/test/test-main.c index 31837e57a8..be0bf9d52c 100644 --- a/test/test-main.c +++ b/test/test-main.c @@ -89,16 +89,7 @@ static int dm_test_post_run(struct unit_test_state *uts) /* Ensure all the test devices are probed */ static int do_autoprobe(struct unit_test_state *uts) { - struct udevice *dev; - int ret; - - /* Scanning the uclass is enough to probe all the devices */ - for (ret = uclass_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_next_device(&dev)) - ; - - return ret; + return uclass_probe_all(UCLASS_TEST); } /* From patchwork Tue Sep 27 21:37:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683600 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=I89RKaP5; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=O7glX8sJ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY0Z6tGnz1yqJ for ; Wed, 28 Sep 2022 07:38:54 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CB65984E19; Tue, 27 Sep 2022 23:38:31 +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="I89RKaP5"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="O7glX8sJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E076084E46; Tue, 27 Sep 2022 23:38:22 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 B266684E0F for ; Tue, 27 Sep 2022 23:38:18 +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 7F73821C1B; Tue, 27 Sep 2022 21:38:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314698; 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=WwnFAMGWlZ4iRBG6GRfRKdEZ9sQvC99TiEF04Xonwjw=; b=I89RKaP5NNkVa8+DPDXQLC+bOczYWOTWip8EIofgAlE1H7JZ0WVIfpNnZEooLs4Jw3E+SB qYZbc1pwiVizSBb++SnX/r2ffoTTNEei+6ZTRnC2bWwEjDt0eyHNsrMYSRykCimvgxUiFq 3+0+2lIPAmIHJl1WClLO4kOUFscF0XY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314698; 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=WwnFAMGWlZ4iRBG6GRfRKdEZ9sQvC99TiEF04Xonwjw=; b=O7glX8sJiCJOtlfa5HE5EAx2q2AzPNYFNNFPKCkVFIgRHXxK+sIp41WJKIzXUKHheti7e2 Yx+samjnWDnLhwCg== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id 4997C2C18A; Tue, 27 Sep 2022 21:38:18 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Bin Meng , Andrew Scull , Stefan Roese , Vladimir Oltean , =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Pierre-Cl=C3=A9men?= =?utf-8?q?t_Tosi?= , Simon Glass Subject: [PATCH v5 03/15] dm: pci: Fix device PCI iteration Date: Tue, 27 Sep 2022 23:37:55 +0200 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 When there is no PCI bus uclass_first_device will return no bus and no error which will result in pci_find_first_device calling skip_to_next_device with no bus, and the bus is only checked at the end of the while cycle, not the beginning. Also stop dealing with the return value of uclass_first_device/uclass_next_device - once the iteration is fixed to continue after an error there is nothing meaningful to get anymore. Fixes: 76c3fbcd3d ("dm: pci: Add a way to iterate through all PCI devices") Signed-off-by: Michal Suchanek Reviewed-by: Simon Glass --- drivers/pci/pci-uclass.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 16a6a699f9..00e3828d95 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -1211,22 +1211,19 @@ static int pci_bridge_write_config(struct udevice *bus, pci_dev_t bdf, static int skip_to_next_device(struct udevice *bus, struct udevice **devp) { struct udevice *dev; - int ret = 0; /* * Scan through all the PCI controllers. On x86 there will only be one * but that is not necessarily true on other hardware. */ - do { + while (bus) { device_find_first_child(bus, &dev); if (dev) { *devp = dev; return 0; } - ret = uclass_next_device(&bus); - if (ret) - return ret; - } while (bus); + uclass_next_device(&bus); + } return 0; } @@ -1235,7 +1232,6 @@ int pci_find_next_device(struct udevice **devp) { struct udevice *child = *devp; struct udevice *bus = child->parent; - int ret; /* First try all the siblings */ *devp = NULL; @@ -1248,9 +1244,7 @@ int pci_find_next_device(struct udevice **devp) } /* We ran out of siblings. Try the next bus */ - ret = uclass_next_device(&bus); - if (ret) - return ret; + uclass_next_device(&bus); return bus ? skip_to_next_device(bus, devp) : 0; } @@ -1258,12 +1252,9 @@ int pci_find_next_device(struct udevice **devp) int pci_find_first_device(struct udevice **devp) { struct udevice *bus; - int ret; *devp = NULL; - ret = uclass_first_device(UCLASS_PCI, &bus); - if (ret) - return ret; + uclass_first_device(UCLASS_PCI, &bus); return skip_to_next_device(bus, devp); } From patchwork Tue Sep 27 21:37:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683601 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=MTg2fzAP; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=hEXuOcIQ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY114dnlz1yqJ for ; Wed, 28 Sep 2022 07:39:17 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 560A784E10; Tue, 27 Sep 2022 23:38:35 +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="MTg2fzAP"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="hEXuOcIQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4B3B084DF6; Tue, 27 Sep 2022 23:38:25 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 CE2EB84E16 for ; Tue, 27 Sep 2022 23:38:18 +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 9F0D921BCF; Tue, 27 Sep 2022 21:38:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314698; 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=pnUBVr+AYs/4ij3GFcDIkbmEOVPTO4FudwY/nL3SeLo=; b=MTg2fzAPBGDI7o3VAxJ64LSxg/qQRQuK44wcpbciDjrdiozqTLhtfskveyAkp7BjWvr8Ms 0050jGoDCuvUFNDd9gKVrVqLP+jm1KhwZZh2K/UfhfESxP3jG49rj/AbtqeZ3ZdQyPeIFx QYeRsw3+dgQC533ThYXTsnuT1Ai3aic= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314698; 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=pnUBVr+AYs/4ij3GFcDIkbmEOVPTO4FudwY/nL3SeLo=; b=hEXuOcIQI1YtMq53/mHhyALcAseK9ZkBIVJXxO/D9MCFEa0uFAEnSPfYsRG64wjb3Nt9Dk zlSS6cP9i5u87rAg== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id 845812C18B; Tue, 27 Sep 2022 21:38:18 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Simon Glass Subject: [PATCH v5 04/15] bootstd: Fix listing boot devices Date: Tue, 27 Sep 2022 23:37:56 +0200 Message-Id: <357a0d89a6557783b991fd7a4db60ce55d7ff930.1664314043.git.msuchanek@suse.de> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 bootdev_list() uses uclass_*_device_err() to iterate devices. However, the only value _err adds is returning an error when the device pointer is null, and that's checked anyway. Also there is some intent to report errors, and that's what uclass_*_device_check() is for, use it. Also print the symbolic error. Signed-off-by: Michal Suchanek Reviewed-by: Simon Glass --- boot/bootdev-uclass.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c index 13ac69eb39..e7115c5750 100644 --- a/boot/bootdev-uclass.c +++ b/boot/bootdev-uclass.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -195,16 +196,16 @@ void bootdev_list(bool probe) printf("Seq Probed Status Uclass Name\n"); printf("--- ------ ------ -------- ------------------\n"); if (probe) - ret = uclass_first_device_err(UCLASS_BOOTDEV, &dev); + ret = uclass_first_device_check(UCLASS_BOOTDEV, &dev); else ret = uclass_find_first_device(UCLASS_BOOTDEV, &dev); for (i = 0; dev; i++) { printf("%3x [ %c ] %6s %-9.9s %s\n", dev_seq(dev), device_active(dev) ? '+' : ' ', - ret ? simple_itoa(ret) : "OK", + ret ? errno_str(ret) : "OK", dev_get_uclass_name(dev_get_parent(dev)), dev->name); if (probe) - ret = uclass_next_device_err(&dev); + ret = uclass_next_device_check(&dev); else ret = uclass_find_next_device(&dev); } From patchwork Tue Sep 27 21:37:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683604 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Gbl0jj1L; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=aEVEQIrl; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY1W3PQFz1yqJ for ; Wed, 28 Sep 2022 07:39:43 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7DC5584DFC; Tue, 27 Sep 2022 23:38:40 +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="Gbl0jj1L"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="aEVEQIrl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8969784E0D; Tue, 27 Sep 2022 23:38:25 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (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 0304C84E19 for ; Tue, 27 Sep 2022 23:38:19 +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 C470A1FA2A; Tue, 27 Sep 2022 21:38:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314698; 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=1YUWMs5IjXHCUB+cDdGY773MmKHYhifyiV6UC7QGuQA=; b=Gbl0jj1Li4/k6GQxC+qv+E7qQ2xQcZKtAtW0pyiZUDKnpS70nyDV5nHuW5e1uy2oH/pZpX 9ift8WTmh30Zg5j5TioQKz7Ncj/rgPUZDioR9n6KZUEcYEkXh+tzf6eO0kQR0zFnZwODMs n3HWB4wy4jSKAxQoMqmPZjT+F6l1lBs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314698; 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=1YUWMs5IjXHCUB+cDdGY773MmKHYhifyiV6UC7QGuQA=; b=aEVEQIrlTPjy8uaPd2J5CmPd7kv1qzvzftNZAQ8gixK4UhCR8LPR+lET4bPIh34U0wmsGN DXvG7t3Drbwj2cAQ== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id A590A2C18C; Tue, 27 Sep 2022 21:38:18 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Lukasz Majewski , Marek Vasut Subject: [PATCH v5 05/15] usb: ether: Fix error handling in usb_ether_init Date: Tue, 27 Sep 2022 23:37:57 +0200 Message-Id: <210ad5fa296e04285453ae1aebacdd0a5101366b.1664314043.git.msuchanek@suse.de> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 The code checks the return value from uclass_first_device as well as that the device exists but it passes on the return value which may be zero if there are no gadget devices. Just check that a device was returned and return -ENODEV otherwise. Also remove the dev variable which is not really used for anything. Signed-off-by: Michal Suchanek --- drivers/usb/gadget/ether.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index abb5332f13..ad394c80fc 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -2636,18 +2636,17 @@ static const struct eth_ops usb_eth_ops = { int usb_ether_init(void) { - struct udevice *dev; struct udevice *usb_dev; int ret; - ret = uclass_first_device(UCLASS_USB_GADGET_GENERIC, &usb_dev); - if (!usb_dev || ret) { + uclass_first_device(UCLASS_USB_GADGET_GENERIC, &usb_dev); + if (!usb_dev) { pr_err("No USB device found\n"); - return ret; + return -ENODEV; } - ret = device_bind_driver(usb_dev, "usb_ether", "usb_ether", &dev); - if (!dev || ret) { + ret = device_bind_driver(usb_dev, "usb_ether", "usb_ether", NULL); + if (ret) { pr_err("usb - not able to bind usb_ether device\n"); return ret; } From patchwork Tue Sep 27 21:37:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683602 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 (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=HDxhRehk; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=a3OuxrTQ; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY1G542cz1yqJ for ; Wed, 28 Sep 2022 07:39:30 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B8B6184E0D; Tue, 27 Sep 2022 23:38:37 +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="HDxhRehk"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="a3OuxrTQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A9FD184E13; Tue, 27 Sep 2022 23:38:25 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (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 417BA84E21 for ; Tue, 27 Sep 2022 23:38:19 +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 075951FA2D; Tue, 27 Sep 2022 21:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314699; 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=m5zX/C7K4wRuEM9Iv9hSFvHw1koEPIcpIZ8akKx4sfA=; b=HDxhRehkRDb8pNsDv0Vt/5otluW4sMMcZD0YWaRmARqRBWnpOBmCV57vV6BJkMn0mHWBfx mN6PrknGW1QEIHvpyFnQNR44cRatW+LJi9o6Y6BkY/sAwCTTX8/lBu2Pn5ufYSaZnoSgAD IkA3egh/irkkGols9cXlHXZQl4UMMrg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314699; 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=m5zX/C7K4wRuEM9Iv9hSFvHw1koEPIcpIZ8akKx4sfA=; b=a3OuxrTQ0KR5ZNee03RI/6HBkD7oQZvahPfYj14SGS3n/MthsyqrVTVKZ/zj6bdjqBtodK S2klal1GVjsAJDBA== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id CA6CF2C18D; Tue, 27 Sep 2022 21:38:18 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Simon Glass , Jason Liu , Heinrich Schuchardt , Loic Poulain , Bin Meng , Anatolij Gustschin Subject: [PATCH v5 06/15] stdio: Fix class iteration in stdio_add_devices() Date: Tue, 27 Sep 2022 23:37:58 +0200 Message-Id: <8a5ad0e735976d28e92ff6384c04a4ae07c2f60d.1664314043.git.msuchanek@suse.de> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 There is a complaint in the code that iterates keyboards that we don't have the _check variant of class iterator but we in fact do, use it. In the code that iterates video devices there is an attempt to print errors but the simple iterator does not return a device when there is an error. Use the _check variant of the iterator as well. Also print the symbolic error. Fixes: b206cd7372 ("dm: stdio: Plumb in the new keyboard uclass") Fixes: e3b81c1c0d ("dm: stdio: video: Plumb the video uclass into stdio") Signed-off-by: Michal Suchanek Reviewed-by: Simon Glass --- common/stdio.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/common/stdio.c b/common/stdio.c index 92161a0df8..17f0aef76d 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -306,7 +306,6 @@ int stdio_init_tables(void) int stdio_add_devices(void) { struct udevice *dev; - struct uclass *uc; int ret; if (IS_ENABLED(CONFIG_DM_KEYBOARD)) { @@ -316,24 +315,18 @@ int stdio_add_devices(void) * have a list of input devices to start up in the stdin * environment variable. That work probably makes more sense * when stdio itself is converted to driver model. - * - * TODO(sjg@chromium.org): Convert changing - * uclass_first_device() etc. to return the device even on - * error. Then we could use that here. */ - ret = uclass_get(UCLASS_KEYBOARD, &uc); - if (ret) - return ret; /* * Don't report errors to the caller - assume that they are * non-fatal */ - uclass_foreach_dev(dev, uc) { - ret = device_probe(dev); + for (ret = uclass_first_device_check(UCLASS_KEYBOARD, &dev); + dev; + ret = uclass_next_device_check(&dev)) { if (ret) - printf("Failed to probe keyboard '%s'\n", - dev->name); + printf("%s: Failed to probe keyboard '%s' (ret=%d %s)\n", + __func__, dev->name, ret, errno_str(ret)); } } #if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) @@ -353,13 +346,15 @@ int stdio_add_devices(void) int ret; if (!IS_ENABLED(CONFIG_SYS_CONSOLE_IS_IN_ENV)) { - for (ret = uclass_first_device(UCLASS_VIDEO, &vdev); - vdev; - ret = uclass_next_device(&vdev)) - ; - if (ret) - printf("%s: Video device failed (ret=%d)\n", - __func__, ret); + for (ret = uclass_first_device_check(UCLASS_VIDEO, + &vdev); + vdev; + ret = uclass_next_device_check(&vdev)) { + if (ret) + printf("%s: Failed to probe video device '%s' (ret=%d %s)\n", + __func__, dev->name, + ret, errno_str(ret)); + } } if (IS_ENABLED(CONFIG_SPLASH_SCREEN) && IS_ENABLED(CONFIG_CMD_BMP)) From patchwork Tue Sep 27 21:37:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683606 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=XU5ebJ90; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=XfleRuQ4; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY1y1jwMz1yq7 for ; Wed, 28 Sep 2022 07:40:06 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 266DD84E2A; Tue, 27 Sep 2022 23:39:13 +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="XU5ebJ90"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="XfleRuQ4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D8A4F84E18; Tue, 27 Sep 2022 23:38:32 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 7AF6B84E27 for ; Tue, 27 Sep 2022 23:38:19 +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 4AF5B21BCF; Tue, 27 Sep 2022 21:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314699; 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=D3uLX6l4BYJckfnme2IepQv0DFDMXti8MZE/H0oEfqU=; b=XU5ebJ90NMwp3ONt0b/RQZw6rmrJWBCdzK3sW4GnOZ23eEYhSQIKKrXpbC658MLZ17xwuK jWO9cl9Szurb3p59Ja1STB0SFzU5Xl2eZKVBkEbr7W0+60vDNpR++PP/VbYU0SM0+0/7Iw WGlq6O9tjjrmTKSN1CdGohATN5uNk6o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314699; 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=D3uLX6l4BYJckfnme2IepQv0DFDMXti8MZE/H0oEfqU=; b=XfleRuQ4lxFfKwlBJRZIf3DctJR3WyFto0btwtNoCy77e+1T4T4twTLl1ODFYgnVtF1XXw ibDLt384LoX/KuBw== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id 0F01E2C18E; Tue, 27 Sep 2022 21:38:19 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Anatolij Gustschin , Simon Glass , Heinrich Schuchardt , Heiko Schocher Subject: [PATCH v5 07/15] video: ipuv3: Fix error handling when getting the display Date: Tue, 27 Sep 2022 23:37:59 +0200 Message-Id: <039c21c48a05f2f41ace57b91efebb4a974758d7.1664314043.git.msuchanek@suse.de> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 The code checks that uclass_first_device returned a device but the returned value that is assigned is never used. Use uclass_first_device_err instead, and move the error return outside of the if block. Fixes: f4ec1ae08e ("mxc_ipuv3_fb.c: call display_enable") Signed-off-by: Michal Suchanek Reviewed-by: Simon Glass --- drivers/video/imx/mxc_ipuv3_fb.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/video/imx/mxc_ipuv3_fb.c b/drivers/video/imx/mxc_ipuv3_fb.c index 49bbeefdd8..8b01a1be11 100644 --- a/drivers/video/imx/mxc_ipuv3_fb.c +++ b/drivers/video/imx/mxc_ipuv3_fb.c @@ -609,12 +609,11 @@ static int ipuv3_video_probe(struct udevice *dev) return ret; #if defined(CONFIG_DISPLAY) - ret = uclass_first_device(UCLASS_DISPLAY, &disp_dev); - if (disp_dev) { + ret = uclass_first_device_err(UCLASS_DISPLAY, &disp_dev); + if (!ret) ret = display_enable(disp_dev, 16, NULL); - if (ret < 0) - return ret; - } + if (ret < 0) + return ret; #endif if (CONFIG_IS_ENABLED(PANEL)) { struct udevice *panel_dev; From patchwork Tue Sep 27 21:38:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683611 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=liqRfNIk; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=VCC+18wY; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY2x6V1Nz1yq7 for ; Wed, 28 Sep 2022 07:40:57 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 66F7F84E47; Tue, 27 Sep 2022 23:39:26 +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="liqRfNIk"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="VCC+18wY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ACFE984DEF; Tue, 27 Sep 2022 23:38:31 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 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 9A8CB84E29 for ; Tue, 27 Sep 2022 23:38:19 +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 6942D1FA2A; Tue, 27 Sep 2022 21:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314699; 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=xm1+OZ8gmuLEC5V4OOfKXl8Mx+G8AaEs9OiPfbJ2Ef0=; b=liqRfNIkM8Zm5p0G97uE/xhewYeeIByHXZ9+68QHJv0+pcNDyHGyo82G2nfVIIns11cB25 EY10XPmZse5VxS2VClYj3MX6etwEp4x3Zmyz+uYl9PkYiwaoACpeWApLOFKj1DXxtE7OXj P/hIDHmdjcarqp7a8kB9XRRxMEkpMhQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314699; 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=xm1+OZ8gmuLEC5V4OOfKXl8Mx+G8AaEs9OiPfbJ2Ef0=; b=VCC+18wYSKM+thov+35QOgsqbbCNLG77TVnTeaef5FCePhGDkCXZoQneXK28Mft3AYHE3J t0BdZX7Lg6y9sPAw== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id 485E22C18F; Tue, 27 Sep 2022 21:38:19 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Maxime Ripard , Eugen Hristev Subject: [PATCH v5 08/15] w1: Fix bus counting in w1_get_bus Date: Tue, 27 Sep 2022 23:38:00 +0200 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 Use uclass_first_device_check/uclass_next_device_check to correctly count buses that fail to probe. Fixes: d3e19cf919 ("w1: Add 1-Wire uclass") Signed-off-by: Michal Suchanek Reviewed-by: Simon Glass --- drivers/w1/w1-uclass.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/w1/w1-uclass.c b/drivers/w1/w1-uclass.c index 52b519c21d..de4f25bcf9 100644 --- a/drivers/w1/w1-uclass.c +++ b/drivers/w1/w1-uclass.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -182,24 +183,25 @@ static int w1_enumerate(struct udevice *bus) int w1_get_bus(int busnum, struct udevice **busp) { int ret, i = 0; - struct udevice *dev; - for (ret = uclass_first_device(UCLASS_W1, &dev); - dev && !ret; - ret = uclass_next_device(&dev), i++) { + for (ret = uclass_first_device_check(UCLASS_W1, &dev); + dev; + ret = uclass_next_device_check(&dev), i++) { if (i == busnum) { + if (ret) { + debug("Cannot probe w1 bus %d: %d (%s)\n", + busnum, ret, errno_str(ret)); + return ret; + } *busp = dev; return 0; } } - if (!ret) { - debug("Cannot find w1 bus %d\n", busnum); - ret = -ENODEV; - } + debug("Cannot find w1 bus %d\n", busnum); - return ret; + return -ENODEV; } u8 w1_get_device_family(struct udevice *dev) From patchwork Tue Sep 27 21:38:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683605 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=yR8HgmZz; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=sv1XpUIx; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY1l4cPgz1yqJ for ; Wed, 28 Sep 2022 07:39:55 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A49BE84E1A; Tue, 27 Sep 2022 23:39:00 +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="yR8HgmZz"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="sv1XpUIx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0290384E1F; Tue, 27 Sep 2022 23:38:32 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 D4F6B84E2A for ; Tue, 27 Sep 2022 23:38:19 +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 A461921BCF; Tue, 27 Sep 2022 21:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314699; 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=ciXsIOdhcRGriMuyE5LdYOb7EJwHqJeGfQLXgEY50RE=; b=yR8HgmZzsJoY1MJNX/gVzazTpFZ+jhenowTE6nWZpwjwSKJSJJj1VhtiQJiMNIdlKbpJAO sNQgno23RY4gsRVqCnLYfDOO13sXPAZHLawsP5bZcqZm+AvJAr30Q9ZiNT57mbv1VC8mo0 CG/F+jySZky6icTExphUJczL9uhtlVM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314699; 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=ciXsIOdhcRGriMuyE5LdYOb7EJwHqJeGfQLXgEY50RE=; b=sv1XpUIx4iGbaaJvlC2hHDbzc3I+jIhxIi2LMb0dWNaMaT4BCOnqcKMdP9eDLTPmaci8tb UuWkQu8SVW7besAg== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id 706FD2C190; Tue, 27 Sep 2022 21:38:19 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Heinrich Schuchardt , Simon Glass , Marek Vasut , Samuel Dionne-Riel , Vyacheslav Bocharov , Diego Rondini Subject: [PATCH v5 09/15] cmd: List all uclass devices regardless of probe error Date: Tue, 27 Sep 2022 23:38:01 +0200 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 There are a few commands that iterate uclass with uclass_first_device/uclass_next_device or the _err variant. Use the _check class iterator variant to get devices that fail to probe as well, and print the status. Signed-off-by: Michal Suchanek Reviewed-by: Simon Glass --- cmd/adc.c | 22 ++++++++++------------ cmd/demo.c | 16 ++++++++++------ cmd/gpio.c | 15 +++++++++++---- cmd/pmic.c | 15 ++++++++------- cmd/regulator.c | 13 +++++++------ 5 files changed, 46 insertions(+), 35 deletions(-) diff --git a/cmd/adc.c b/cmd/adc.c index 1c5d3e10a3..7dcb44eb61 100644 --- a/cmd/adc.c +++ b/cmd/adc.c @@ -6,29 +6,27 @@ #include #include #include +#include #include static int do_adc_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct udevice *dev; - int ret; + int ret, err; - ret = uclass_first_device_err(UCLASS_ADC, &dev); - if (ret) { - printf("No available ADC device\n"); - return CMD_RET_FAILURE; - } + ret = err = uclass_first_device_check(UCLASS_ADC, &dev); - do { - printf("- %s\n", dev->name); + while (dev) { + printf("- %s status: %s\n", dev->name, + ret ? errno_str(ret) : "OK"); - ret = uclass_next_device(&dev); + ret = uclass_next_device_check(&dev); if (ret) - return CMD_RET_FAILURE; - } while (dev); + err = ret; + } - return CMD_RET_SUCCESS; + return err ? CMD_RET_FAILURE : CMD_RET_SUCCESS; } static int do_adc_info(struct cmd_tbl *cmdtp, int flag, int argc, diff --git a/cmd/demo.c b/cmd/demo.c index 571f562ec6..56551f269d 100644 --- a/cmd/demo.c +++ b/cmd/demo.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -64,20 +65,23 @@ static int do_demo_light(struct cmd_tbl *cmdtp, int flag, int argc, int do_demo_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct udevice *dev; - int i, ret; + int i, ret, err = 0; puts("Demo uclass entries:\n"); - for (i = 0, ret = uclass_first_device(UCLASS_DEMO, &dev); + for (i = 0, ret = uclass_first_device_check(UCLASS_DEMO, &dev); dev; - ret = uclass_next_device(&dev)) { - printf("entry %d - instance %08x, ops %08x, plat %08x\n", + ret = uclass_next_device_check(&dev)) { + printf("entry %d - instance %08x, ops %08x, plat %08x, probe %i (%s)\n", i++, (uint)map_to_sysmem(dev), (uint)map_to_sysmem(dev->driver->ops), - (uint)map_to_sysmem(dev_get_plat(dev))); + (uint)map_to_sysmem(dev_get_plat(dev)), + ret, errno_str(ret)); + if (ret) + err = ret; } - return cmd_process_error(cmdtp, ret); + return cmd_process_error(cmdtp, err); } static struct cmd_tbl demo_commands[] = { diff --git a/cmd/gpio.c b/cmd/gpio.c index 53e9ce666f..4bf410a9e7 100644 --- a/cmd/gpio.c +++ b/cmd/gpio.c @@ -77,17 +77,24 @@ static int do_gpio_status(bool all, const char *gpio_name) struct udevice *dev; int banklen; int flags; - int ret; + int ret, err = 0; flags = 0; if (gpio_name && !*gpio_name) gpio_name = NULL; - for (ret = uclass_first_device(UCLASS_GPIO, &dev); + for (ret = uclass_first_device_check(UCLASS_GPIO, &dev); dev; - ret = uclass_next_device(&dev)) { + ret = uclass_next_device_check(&dev)) { const char *bank_name; int num_bits; + if (ret) { + printf("GPIO device %s probe error %i (%s)\n", + dev->name, ret, errno_str(ret)); + err = ret; + continue; + } + flags |= FLAG_SHOW_BANK; if (all) flags |= FLAG_SHOW_ALL; @@ -120,7 +127,7 @@ static int do_gpio_status(bool all, const char *gpio_name) flags |= FLAG_SHOW_NEWLINE; } - return ret; + return err; } #endif diff --git a/cmd/pmic.c b/cmd/pmic.c index 0cb44d0740..d5624241e6 100644 --- a/cmd/pmic.c +++ b/cmd/pmic.c @@ -51,25 +51,26 @@ static int do_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct udevice *dev; - int ret; + int ret, err = 0; printf("| %-*.*s| %-*.*s| %s @ %s\n", LIMIT_DEV, LIMIT_DEV, "Name", LIMIT_PARENT, LIMIT_PARENT, "Parent name", "Parent uclass", "seq"); - for (ret = uclass_first_device(UCLASS_PMIC, &dev); dev; - ret = uclass_next_device(&dev)) { + for (ret = uclass_first_device_check(UCLASS_PMIC, &dev); dev; + ret = uclass_next_device_check(&dev)) { if (ret) - continue; + err = ret; - printf("| %-*.*s| %-*.*s| %s @ %d\n", + printf("| %-*.*s| %-*.*s| %s @ %d | probe: %i (%s)\n", LIMIT_DEV, LIMIT_DEV, dev->name, LIMIT_PARENT, LIMIT_PARENT, dev->parent->name, - dev_get_uclass_name(dev->parent), dev_seq(dev->parent)); + dev_get_uclass_name(dev->parent), dev_seq(dev->parent), + ret, errno_str(ret)); } - if (ret) + if (err) return CMD_RET_FAILURE; return CMD_RET_SUCCESS; diff --git a/cmd/regulator.c b/cmd/regulator.c index 60a70036d6..129c9fec20 100644 --- a/cmd/regulator.c +++ b/cmd/regulator.c @@ -205,7 +205,7 @@ static void do_status_detail(struct udevice *dev, constraint(" * mode id:", mode, mode_name); } -static void do_status_line(struct udevice *dev) +static void do_status_line(struct udevice *dev, int status) { struct dm_regulator_uclass_plat *pdata; int current, value, mode; @@ -231,6 +231,7 @@ static void do_status_line(struct udevice *dev) printf("%-10s", mode_name); else printf("%-10s", "-"); + printf(" %s", status ? errno_str(status) : "OK"); printf("\n"); } @@ -250,11 +251,11 @@ static int do_status(struct cmd_tbl *cmdtp, int flag, int argc, } /* Show all of them in a list, probing them as needed */ - printf("%-20s %-10s %10s %10s %-10s\n", "Name", "Enabled", "uV", "mA", - "Mode"); - for (ret = uclass_first_device(UCLASS_REGULATOR, &dev); dev; - ret = uclass_next_device(&dev)) - do_status_line(dev); + printf("%-20s %-10s %10s %10s %-10s %s\n", "Name", "Enabled", "uV", "mA", + "Mode", "Status"); + for (ret = uclass_first_device_check(UCLASS_REGULATOR, &dev); dev; + ret = uclass_next_device_check(&dev)) + do_status_line(dev, ret); return CMD_RET_SUCCESS; } From patchwork Tue Sep 27 21:38:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683608 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=gpHYG7nP; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=sDBCSsGG; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY2L0l73z1yq7 for ; Wed, 28 Sep 2022 07:40:26 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 01CE484E32; Tue, 27 Sep 2022 23:39:18 +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="gpHYG7nP"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="sDBCSsGG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B982B84E10; Tue, 27 Sep 2022 23:38:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (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 7341D84E38 for ; Tue, 27 Sep 2022 23:38:20 +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 3F3F51FA3B; Tue, 27 Sep 2022 21:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314700; 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=Pm6KZ6ltO8jWeh9DISkoMnE1m9ikBgku9ZZTMuIh0vI=; b=gpHYG7nPmQlk0vGD5BpK1CblO0rq+Pwf6m0NGMEomBvgxB/DOqFckB95AiG3cikUQOXTYB nwUhEu6qT0sWs1Q6qGyoDhRg0mUL7Xbi5JDe+svdDHKfk8LvzL7ipnJ2Bz57C8qV2mrMMO DTTfIedgH3k8OjlZapbqhEkqbxWWkS4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314700; 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=Pm6KZ6ltO8jWeh9DISkoMnE1m9ikBgku9ZZTMuIh0vI=; b=sDBCSsGGv5Zsmi9MnHQEAr5BW8J8sy+8YTxIGPNvSDKolPa9ecRHmDBpTY1uxWtYGt0y0Y vWOFBmmfMkzjYIBg== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id B1C912C191; Tue, 27 Sep 2022 21:38:19 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Simon Glass , Bin Meng , Peng Fan , Jaehoon Chung , Matthias Brugger , Anatolij Gustschin , Liviu Dudau , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Ilias Apalodimas , Joe Hershberger , Ramon Fried , Sean Anderson , Heiko Schocher , Mark Kettenis , Peter Robinson , Tom Warren , Andrew Scull , uboot-stm32@st-md-mailman.stormreply.com (moderated list:ARM STM STM32MP) Subject: [PATCH v5 10/15] dm: treewide: Use uclass_first_device_err when accessing one device Date: Tue, 27 Sep 2022 23:38:02 +0200 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 There is a number of users that use uclass_first_device to access the first and (assumed) only device in uclass. Some check the return value of uclass_first_device and also that a device was returned which is exactly what uclass_first_device_err does. Some are not checking that a device was returned and can potentially crash if no device exists in the uclass. Finally there is one that returns NULL on error either way. Convert all of these to use uclass_first_device_err instead, the return value will be removed from uclass_first_device in a later patch. Also print the symbolic error when the return value is printed. Signed-off-by: Michal Suchanek Reviewed-by: Simon Glass --- arch/arm/mach-omap2/am33xx/board.c | 4 ++-- arch/x86/cpu/broadwell/cpu.c | 4 +--- arch/x86/cpu/intel_common/cpu.c | 4 +--- arch/x86/lib/pinctrl_ich6.c | 4 +--- board/intel/cougarcanyon2/cougarcanyon2.c | 4 +--- drivers/mmc/omap_hsmmc.c | 2 +- drivers/serial/serial-uclass.c | 2 +- drivers/serial/serial_bcm283x_mu.c | 2 +- drivers/serial/serial_bcm283x_pl011.c | 2 +- drivers/sysreset/sysreset_ast.c | 2 +- drivers/video/exynos/exynos_fb.c | 24 ++++++++++------------- drivers/video/mali_dp.c | 2 +- drivers/video/stm32/stm32_dsi.c | 6 ++++-- drivers/video/tegra124/dp.c | 7 ++++--- lib/acpi/acpi_table.c | 2 +- lib/efi_loader/efi_gop.c | 2 +- net/eth-uclass.c | 4 ++-- test/boot/bootmeth.c | 2 +- test/dm/acpi.c | 14 ++++++------- test/dm/devres.c | 4 ++-- test/dm/i2c.c | 8 ++++---- test/dm/virtio_device.c | 8 ++++---- test/dm/virtio_rng.c | 2 +- test/fuzz/cmd_fuzz.c | 2 +- test/fuzz/virtio.c | 2 +- 25 files changed, 55 insertions(+), 64 deletions(-) diff --git a/arch/arm/mach-omap2/am33xx/board.c b/arch/arm/mach-omap2/am33xx/board.c index 7f1b84e466..f393ff9144 100644 --- a/arch/arm/mach-omap2/am33xx/board.c +++ b/arch/arm/mach-omap2/am33xx/board.c @@ -265,8 +265,8 @@ int arch_misc_init(void) struct udevice *dev; int ret; - ret = uclass_first_device(UCLASS_MISC, &dev); - if (ret || !dev) + ret = uclass_first_device_err(UCLASS_MISC, &dev); + if (ret) return ret; #if defined(CONFIG_DM_ETH) && defined(CONFIG_USB_ETHER) diff --git a/arch/x86/cpu/broadwell/cpu.c b/arch/x86/cpu/broadwell/cpu.c index 2adcf4b242..7877961451 100644 --- a/arch/x86/cpu/broadwell/cpu.c +++ b/arch/x86/cpu/broadwell/cpu.c @@ -31,11 +31,9 @@ static int broadwell_init_cpu(void *ctx, struct event *event) int ret; /* Start up the LPC so we have serial */ - ret = uclass_first_device(UCLASS_LPC, &dev); + ret = uclass_first_device_err(UCLASS_LPC, &dev); if (ret) return ret; - if (!dev) - return -ENODEV; ret = cpu_set_flex_ratio_to_tdp_nominal(); if (ret) return ret; diff --git a/arch/x86/cpu/intel_common/cpu.c b/arch/x86/cpu/intel_common/cpu.c index 96d05e2eb3..8f489e6c65 100644 --- a/arch/x86/cpu/intel_common/cpu.c +++ b/arch/x86/cpu/intel_common/cpu.c @@ -61,11 +61,9 @@ int cpu_common_init(void) /* Early chipset init required before RAM init can work */ uclass_first_device(UCLASS_NORTHBRIDGE, &dev); - ret = uclass_first_device(UCLASS_LPC, &lpc); + ret = uclass_first_device_err(UCLASS_LPC, &lpc); if (ret) return ret; - if (!lpc) - return -ENODEV; /* Cause the SATA device to do its early init */ uclass_first_device(UCLASS_AHCI, &dev); diff --git a/arch/x86/lib/pinctrl_ich6.c b/arch/x86/lib/pinctrl_ich6.c index fd5e311b29..c93f245845 100644 --- a/arch/x86/lib/pinctrl_ich6.c +++ b/arch/x86/lib/pinctrl_ich6.c @@ -160,11 +160,9 @@ static int ich6_pinctrl_probe(struct udevice *dev) u32 iobase = -1; debug("%s: start\n", __func__); - ret = uclass_first_device(UCLASS_PCH, &pch); + ret = uclass_first_device_err(UCLASS_PCH, &pch); if (ret) return ret; - if (!pch) - return -ENODEV; /* * Get the memory/io base address to configure every pins. diff --git a/board/intel/cougarcanyon2/cougarcanyon2.c b/board/intel/cougarcanyon2/cougarcanyon2.c index ce11eae59d..7f61ef8b36 100644 --- a/board/intel/cougarcanyon2/cougarcanyon2.c +++ b/board/intel/cougarcanyon2/cougarcanyon2.c @@ -21,11 +21,9 @@ int board_early_init_f(void) struct udevice *pch; int ret; - ret = uclass_first_device(UCLASS_PCH, &pch); + ret = uclass_first_device_err(UCLASS_PCH, &pch); if (ret) return ret; - if (!pch) - return -ENODEV; /* Initialize LPC interface to turn on superio chipset decode range */ dm_pci_write_config16(pch, LPC_IO_DEC, COMA_DEC_RANGE | COMB_DEC_RANGE); diff --git a/drivers/mmc/omap_hsmmc.c b/drivers/mmc/omap_hsmmc.c index b2f4a4e721..a2595d19e7 100644 --- a/drivers/mmc/omap_hsmmc.c +++ b/drivers/mmc/omap_hsmmc.c @@ -644,7 +644,7 @@ static int omap_hsmmc_execute_tuning(struct udevice *dev, uint opcode) ((mmc->selected_mode == UHS_SDR50) && (val & CAPA2_TSDR50)))) return 0; - ret = uclass_first_device(UCLASS_THERMAL, &thermal_dev); + ret = uclass_first_device_err(UCLASS_THERMAL, &thermal_dev); if (ret) { printf("Couldn't get thermal device for tuning\n"); return ret; diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index 30650e37b0..012b349511 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -143,7 +143,7 @@ static void serial_find_console_or_panic(void) #else if (!uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &dev) || !uclass_get_device(UCLASS_SERIAL, INDEX, &dev) || - (!uclass_first_device(UCLASS_SERIAL, &dev) && dev)) { + !uclass_first_device_err(UCLASS_SERIAL, &dev)) { gd->cur_serial_dev = dev; return; } diff --git a/drivers/serial/serial_bcm283x_mu.c b/drivers/serial/serial_bcm283x_mu.c index f0756c37c8..32c6e9ffc1 100644 --- a/drivers/serial/serial_bcm283x_mu.c +++ b/drivers/serial/serial_bcm283x_mu.c @@ -147,7 +147,7 @@ static bool bcm283x_is_serial_muxed(void) int serial_gpio = 15; struct udevice *dev; - if (uclass_first_device(UCLASS_PINCTRL, &dev) || !dev) + if (uclass_first_device_err(UCLASS_PINCTRL, &dev)) return false; if (pinctrl_get_gpio_mux(dev, 0, serial_gpio) != BCM2835_GPIO_ALT5) diff --git a/drivers/serial/serial_bcm283x_pl011.c b/drivers/serial/serial_bcm283x_pl011.c index fe746294cd..7d172cdac0 100644 --- a/drivers/serial/serial_bcm283x_pl011.c +++ b/drivers/serial/serial_bcm283x_pl011.c @@ -24,7 +24,7 @@ static bool bcm283x_is_serial_muxed(void) int serial_gpio = 15; struct udevice *dev; - if (uclass_first_device(UCLASS_PINCTRL, &dev) || !dev) + if (uclass_first_device_err(UCLASS_PINCTRL, &dev)) return false; if (pinctrl_get_gpio_mux(dev, 0, serial_gpio) != BCM2835_GPIO_ALT0) diff --git a/drivers/sysreset/sysreset_ast.c b/drivers/sysreset/sysreset_ast.c index d747ed00a7..92fad96871 100644 --- a/drivers/sysreset/sysreset_ast.c +++ b/drivers/sysreset/sysreset_ast.c @@ -18,7 +18,7 @@ static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type) { struct udevice *wdt; u32 reset_mode; - int ret = uclass_first_device(UCLASS_WDT, &wdt); + int ret = uclass_first_device_err(UCLASS_WDT, &wdt); if (ret) return ret; diff --git a/drivers/video/exynos/exynos_fb.c b/drivers/video/exynos/exynos_fb.c index 69992b3c2b..13f5317d11 100644 --- a/drivers/video/exynos/exynos_fb.c +++ b/drivers/video/exynos/exynos_fb.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include DECLARE_GLOBAL_DATA_PTR; @@ -640,28 +640,24 @@ static int exynos_fb_probe(struct udevice *dev) #endif exynos_fimd_lcd_init(dev); - ret = uclass_first_device(UCLASS_PANEL, &panel); + ret = uclass_first_device_err(UCLASS_PANEL, &panel); if (ret) { - printf("LCD panel failed to probe\n"); + printf("%s: LCD panel failed to probe %d (%s)\n", + __func__, ret, errno_str(ret)); return ret; } - if (!panel) { - printf("LCD panel not found\n"); - return -ENODEV; - } - ret = uclass_first_device(UCLASS_DISPLAY, &dp); + ret = uclass_first_device_err(UCLASS_DISPLAY, &dp); if (ret) { - debug("%s: Display device error %d\n", __func__, ret); + debug("%s: Display device error %d (%s)\n", + __func__, ret, errno_str(ret)); return ret; } - if (!dev) { - debug("%s: Display device missing\n", __func__); - return -ENODEV; - } + ret = display_enable(dp, 18, NULL); if (ret) { - debug("%s: Display enable error %d\n", __func__, ret); + debug("%s: Display enable error %d (%s)\n", + __func__, ret, errno_str(ret)); return ret; } diff --git a/drivers/video/mali_dp.c b/drivers/video/mali_dp.c index ba1ddd64e0..cbcdb99e1f 100644 --- a/drivers/video/mali_dp.c +++ b/drivers/video/mali_dp.c @@ -244,7 +244,7 @@ static int malidp_update_timings_from_edid(struct udevice *dev, struct udevice *disp_dev; int err; - err = uclass_first_device(UCLASS_DISPLAY, &disp_dev); + err = uclass_first_device_err(UCLASS_DISPLAY, &disp_dev); if (err) return err; diff --git a/drivers/video/stm32/stm32_dsi.c b/drivers/video/stm32/stm32_dsi.c index 5871ac7c4f..0924789f5e 100644 --- a/drivers/video/stm32/stm32_dsi.c +++ b/drivers/video/stm32/stm32_dsi.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -346,9 +347,10 @@ static int stm32_dsi_attach(struct udevice *dev) struct display_timing timings; int ret; - ret = uclass_first_device(UCLASS_PANEL, &priv->panel); + ret = uclass_first_device_err(UCLASS_PANEL, &priv->panel); if (ret) { - dev_err(dev, "panel device error %d\n", ret); + dev_err(dev, "panel device error %d (%s)\n", + ret, errno_str(ret)); return ret; } diff --git a/drivers/video/tegra124/dp.c b/drivers/video/tegra124/dp.c index ee4f09a0c4..d4c0ba148e 100644 --- a/drivers/video/tegra124/dp.c +++ b/drivers/video/tegra124/dp.c @@ -1494,9 +1494,10 @@ int tegra_dp_enable(struct udevice *dev, int panel_bpp, return -ENOLINK; } - ret = uclass_first_device(UCLASS_VIDEO_BRIDGE, &sor); - if (ret || !sor) { - debug("dp: failed to find SOR device: ret=%d\n", ret); + ret = uclass_first_device_err(UCLASS_VIDEO_BRIDGE, &sor); + if (ret) { + debug("dp: failed to find SOR device: ret=%d (%s)\n", + ret, errno_str(ret)); return ret; } priv->sor = sor; diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index f8642f9942..7c4189e243 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -40,7 +40,7 @@ int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags) struct udevice *cpu; int ret; - ret = uclass_first_device(UCLASS_CPU, &cpu); + ret = uclass_first_device_err(UCLASS_CPU, &cpu); if (ret) return log_msg_ret("cpu", ret); ret = cpu_get_info(cpu, &info); diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index 5908b5c646..20bd7fff08 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -482,7 +482,7 @@ efi_status_t efi_gop_register(void) struct video_priv *priv; /* We only support a single video output device for now */ - if (uclass_first_device(UCLASS_VIDEO, &vdev) || !vdev) { + if (uclass_first_device_err(UCLASS_VIDEO, &vdev)) { debug("WARNING: No video device\n"); return EFI_SUCCESS; } diff --git a/net/eth-uclass.c b/net/eth-uclass.c index 0f6b45b002..8c3f9cc31b 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -91,8 +91,8 @@ struct udevice *eth_get_dev(void) eth_errno = uclass_get_device_by_seq(UCLASS_ETH, 0, &uc_priv->current); if (eth_errno) - eth_errno = uclass_first_device(UCLASS_ETH, - &uc_priv->current); + eth_errno = uclass_first_device_err(UCLASS_ETH, + &uc_priv->current); } return uc_priv->current; } diff --git a/test/boot/bootmeth.c b/test/boot/bootmeth.c index fb62731339..f0b5ab9adb 100644 --- a/test/boot/bootmeth.c +++ b/test/boot/bootmeth.c @@ -156,7 +156,7 @@ static int bootmeth_state(struct unit_test_state *uts) struct udevice *dev; char buf[50]; - ut_assertok(uclass_first_device(UCLASS_BOOTMETH, &dev)); + ut_assertok(uclass_first_device_err(UCLASS_BOOTMETH, &dev)); ut_assertnonnull(dev); ut_assertok(bootmeth_get_state_desc(dev, buf, sizeof(buf))); diff --git a/test/dm/acpi.c b/test/dm/acpi.c index edad91329f..9634fc2e90 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -169,28 +169,28 @@ static int dm_test_acpi_get_name(struct unit_test_state *uts) ut_asserteq_str("GHIJ", name); /* Test getting the name from acpi_device_get_name() */ - ut_assertok(uclass_first_device(UCLASS_I2C, &i2c)); + ut_assertok(uclass_first_device_err(UCLASS_I2C, &i2c)); ut_assertok(acpi_get_name(i2c, name)); ut_asserteq_str("I2C0", name); - ut_assertok(uclass_first_device(UCLASS_SPI, &spi)); + ut_assertok(uclass_first_device_err(UCLASS_SPI, &spi)); ut_assertok(acpi_get_name(spi, name)); ut_asserteq_str("SPI0", name); /* ACPI doesn't know about the timer */ - ut_assertok(uclass_first_device(UCLASS_TIMER, &timer)); + ut_assertok(uclass_first_device_err(UCLASS_TIMER, &timer)); ut_asserteq(-ENOENT, acpi_get_name(timer, name)); /* May as well test the rest of the cases */ - ut_assertok(uclass_first_device(UCLASS_SOUND, &sound)); + ut_assertok(uclass_first_device_err(UCLASS_SOUND, &sound)); ut_assertok(acpi_get_name(sound, name)); ut_asserteq_str("HDAS", name); - ut_assertok(uclass_first_device(UCLASS_PCI, &pci)); + ut_assertok(uclass_first_device_err(UCLASS_PCI, &pci)); ut_assertok(acpi_get_name(pci, name)); ut_asserteq_str("PCI0", name); - ut_assertok(uclass_first_device(UCLASS_ROOT, &root)); + ut_assertok(uclass_first_device_err(UCLASS_ROOT, &root)); ut_assertok(acpi_get_name(root, name)); ut_asserteq_str("\\_SB", name); @@ -219,7 +219,7 @@ static int dm_test_acpi_create_dmar(struct unit_test_state *uts) struct acpi_dmar dmar; struct udevice *cpu; - ut_assertok(uclass_first_device(UCLASS_CPU, &cpu)); + ut_assertok(uclass_first_device_err(UCLASS_CPU, &cpu)); ut_assertnonnull(cpu); ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP)); ut_asserteq(DMAR_INTR_REMAP, dmar.flags); diff --git a/test/dm/devres.c b/test/dm/devres.c index 524114c833..3df0f64362 100644 --- a/test/dm/devres.c +++ b/test/dm/devres.c @@ -165,8 +165,8 @@ static int dm_test_devres_phase(struct unit_test_state *uts) ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE3, stats.total_size); /* Probing the device should add one allocation */ - ut_assertok(uclass_first_device(UCLASS_TEST_DEVRES, &dev)); - ut_assert(dev != NULL); + ut_assertok(uclass_first_device_err(UCLASS_TEST_DEVRES, &dev)); + ut_assertnonnull(dev); devres_get_stats(dev, &stats); ut_asserteq(3, stats.allocs); ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE2 + TEST_DEVRES_SIZE3, diff --git a/test/dm/i2c.c b/test/dm/i2c.c index 74b2097195..b46a22e79b 100644 --- a/test/dm/i2c.c +++ b/test/dm/i2c.c @@ -124,7 +124,7 @@ static int dm_test_i2c_bytewise(struct unit_test_state *uts) ut_asserteq_mem(buf, "\0\0\0\0\0", sizeof(buf)); /* Tell the EEPROM to only read/write one register at a time */ - ut_assertok(uclass_first_device(UCLASS_I2C_EMUL, &eeprom)); + ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom)); ut_assertnonnull(eeprom); sandbox_i2c_eeprom_set_test_mode(eeprom, SIE_TEST_MODE_SINGLE_BYTE); @@ -177,7 +177,7 @@ static int dm_test_i2c_offset(struct unit_test_state *uts) /* Do a transfer so we can find the emulator */ ut_assertok(dm_i2c_read(dev, 0, buf, 5)); - ut_assertok(uclass_first_device(UCLASS_I2C_EMUL, &eeprom)); + ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom)); /* Offset length 0 */ sandbox_i2c_eeprom_set_offset_len(eeprom, 0); @@ -250,7 +250,7 @@ static int dm_test_i2c_addr_offset(struct unit_test_state *uts) /* Do a transfer so we can find the emulator */ ut_assertok(dm_i2c_read(dev, 0, buf, 5)); - ut_assertok(uclass_first_device(UCLASS_I2C_EMUL, &eeprom)); + ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom)); /* Offset length 0 */ sandbox_i2c_eeprom_set_offset_len(eeprom, 0); @@ -315,7 +315,7 @@ static int dm_test_i2c_reg_clrset(struct unit_test_state *uts) /* Do a transfer so we can find the emulator */ ut_assertok(dm_i2c_read(dev, 0, buf, 5)); - ut_assertok(uclass_first_device(UCLASS_I2C_EMUL, &eeprom)); + ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom)); /* Dummy data for the test */ ut_assertok(dm_i2c_write(dev, 0, "\xff\x00\xff\x00\x10", 5)); diff --git a/test/dm/virtio_device.c b/test/dm/virtio_device.c index d0195e6bf0..b5c4523a02 100644 --- a/test/dm/virtio_device.c +++ b/test/dm/virtio_device.c @@ -22,7 +22,7 @@ static int dm_test_virtio_base(struct unit_test_state *uts) u8 status; /* check probe success */ - ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus)); + ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus)); ut_assertnonnull(bus); /* check the child virtio-rng device is bound */ @@ -60,7 +60,7 @@ static int dm_test_virtio_all_ops(struct unit_test_state *uts) struct virtqueue *vqs[2]; /* check probe success */ - ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus)); + ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus)); ut_assertnonnull(bus); /* check the child virtio-rng device is bound */ @@ -102,7 +102,7 @@ static int dm_test_virtio_remove(struct unit_test_state *uts) struct udevice *bus, *dev; /* check probe success */ - ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus)); + ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus)); ut_assertnonnull(bus); /* check the child virtio-rng device is bound */ @@ -134,7 +134,7 @@ static int dm_test_virtio_ring(struct unit_test_state *uts) u8 buffer[2][32]; /* check probe success */ - ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus)); + ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus)); ut_assertnonnull(bus); /* check the child virtio-blk device is bound */ diff --git a/test/dm/virtio_rng.c b/test/dm/virtio_rng.c index ff5646b4e1..8b9a04b1fd 100644 --- a/test/dm/virtio_rng.c +++ b/test/dm/virtio_rng.c @@ -28,7 +28,7 @@ static int dm_test_virtio_rng_check_len(struct unit_test_state *uts) u8 buffer[16]; /* check probe success */ - ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus)); + ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus)); ut_assertnonnull(bus); /* check the child virtio-rng device is bound */ diff --git a/test/fuzz/cmd_fuzz.c b/test/fuzz/cmd_fuzz.c index 0cc01dc199..e2f44f3ecb 100644 --- a/test/fuzz/cmd_fuzz.c +++ b/test/fuzz/cmd_fuzz.c @@ -29,7 +29,7 @@ static struct udevice *find_fuzzing_engine(void) { struct udevice *dev; - if (uclass_first_device(UCLASS_FUZZING_ENGINE, &dev)) + if (uclass_first_device_err(UCLASS_FUZZING_ENGINE, &dev)) return NULL; return dev; diff --git a/test/fuzz/virtio.c b/test/fuzz/virtio.c index e5363d5638..8a47667e77 100644 --- a/test/fuzz/virtio.c +++ b/test/fuzz/virtio.c @@ -30,7 +30,7 @@ static int fuzz_vring(const uint8_t *data, size_t size) return 0; /* check probe success */ - if (uclass_first_device(UCLASS_VIRTIO, &bus) || !bus) + if (uclass_first_device_err(UCLASS_VIRTIO, &bus)) panic("Could not find virtio bus\n"); /* check the child virtio-rng device is bound */ From patchwork Tue Sep 27 21:38:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683607 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=xpB2VkfV; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=F7vIX5vh; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY274wxNz1yq7 for ; Wed, 28 Sep 2022 07:40:15 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 64E6584E37; Tue, 27 Sep 2022 23:39:15 +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="xpB2VkfV"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="F7vIX5vh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 436B684E10; Tue, 27 Sep 2022 23:38:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 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 9488184E3A for ; Tue, 27 Sep 2022 23:38:20 +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 6557221C08; Tue, 27 Sep 2022 21:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314700; 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=SZcR6AI43qRd2/2HwzNMzof3XHNZpGg97COCEyD6LBo=; b=xpB2VkfV2GqShQM2m0ZeEcAXEat19oruIOFXhoBxnzAybRqaQRHqMQA5RFor1oVKkX/68F ZpfWxeThk5Yi5Xt/O7ldziOkP8c5cxbUgqau0VGg7zCQuSuWmra5inujlvcW0eQeyDbsQI T4Ns5DK8xlyRrWm2l0m4mOHFgoPcQDU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314700; 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=SZcR6AI43qRd2/2HwzNMzof3XHNZpGg97COCEyD6LBo=; b=F7vIX5vh+54vB41dzYvXJKNY22EjLe1hsRs7aJ7eRc/HQVJC7dc+aLNOfbZ/TGtH1l6oZE JNofItAYShsedLAw== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id 44E5A2C192; Tue, 27 Sep 2022 21:38:20 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Eugen Hristev Subject: [PATCH v5 11/15] dm: treewide: Use uclass_next_device_err when accessing second device Date: Tue, 27 Sep 2022 23:38:03 +0200 Message-Id: <2adaf2730dc7be56cd2ce27fa32d0e7294e02cbe.1664314043.git.msuchanek@suse.de> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 There are a couple users of uclass_next_device return value that get the first device by other means and use uclass_next_device assuming the following device in the uclass is related to the first one. Use uclass_next_device_err because the return value from uclass_next_device will be removed in a later patch. Signed-off-by: Michal Suchanek Reviewed-by: Simon Glass --- arch/arm/mach-k3/j721s2_init.c | 2 +- board/atmel/common/mac_eeprom.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/mach-k3/j721s2_init.c b/arch/arm/mach-k3/j721s2_init.c index 12da8136f9..dd0c7ba18f 100644 --- a/arch/arm/mach-k3/j721s2_init.c +++ b/arch/arm/mach-k3/j721s2_init.c @@ -164,7 +164,7 @@ void board_init_f(ulong dummy) if (ret) panic("DRAM 0 init failed: %d\n", ret); - ret = uclass_next_device(&dev); + ret = uclass_next_device_err(&dev); if (ret) panic("DRAM 1 init failed: %d\n", ret); } diff --git a/board/atmel/common/mac_eeprom.c b/board/atmel/common/mac_eeprom.c index a723ba723c..4606008c69 100644 --- a/board/atmel/common/mac_eeprom.c +++ b/board/atmel/common/mac_eeprom.c @@ -56,7 +56,7 @@ int at91_set_eth1addr(int offset) return ret; /* attempt to obtain a second eeprom device */ - ret = uclass_next_device(&dev); + ret = uclass_next_device_err(&dev); if (ret) return ret; From patchwork Tue Sep 27 21:38:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683609 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 (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=t5w0Zqjw; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=g+DXCXUC; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY2X120Qz1yq7 for ; Wed, 28 Sep 2022 07:40:36 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AFE2A84E46; Tue, 27 Sep 2022 23:39:20 +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="t5w0Zqjw"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="g+DXCXUC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BF15C84E24; Tue, 27 Sep 2022 23:38:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (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 CC61184E3B for ; Tue, 27 Sep 2022 23:38:20 +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 9A8771FA40; Tue, 27 Sep 2022 21:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314700; 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=m6tfCLpyNGCi6iF2NIjQ6E0Smljc8HUvczRnie1XbQg=; b=t5w0Zqjw2VVTEO+sqmCWJPvbGzA5MOhE997jgQMQYAj+XPg8QvpI7fndV5AuYtPwZpqalL Bk5DOSi6ynvOs+9GhKSF/M+qZ2MbjegKvnQvXIGSD1RwbJYkqXIpu29S03LZ40cSce2tjk DhVXY/ktuTQeJwjMmv0lJm/2uayiilc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314700; 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=m6tfCLpyNGCi6iF2NIjQ6E0Smljc8HUvczRnie1XbQg=; b=g+DXCXUCID1Oq/tcBGXZP5md521SB3lC6xIlXH3Jg6iKSM1K+Tv6zCuNl7i71ePzI4IsY1 SEj5N+Q9VYCse+BA== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id 721FD2C193; Tue, 27 Sep 2022 21:38:20 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Simon Glass , Heinrich Schuchardt , AKASHI Takahiro Subject: [PATCH v5 12/15] dm: blk: Do not use uclass_next_device_err Date: Tue, 27 Sep 2022 23:38:04 +0200 Message-Id: <7bf8aa436f4456433d06dd8c76fbf0cb5672bd35.1664314043.git.msuchanek@suse.de> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 blk_first_device_err/blk_next_device_err uses uclass_first_device_err/uclass_next_device_err for device iteration. Although the function names superficially match the return value from uclass_first_device_err/uclass_next_device_err is never used meaningfully, and uclass_first_device/uclass_next_device works equally well for this purpose. In the following patch the semantic of uclass_first_device_err/uclass_next_device_err will be changed to be based on uclass_first_device_check/uclass_next_device_check breaking this sole user that uses uclass_next_device_err for iteration. Signed-off-by: Michal Suchanek Reviewed-by: Simon Glass --- drivers/block/blk-uclass.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index 21c5209bb6..676f2444bf 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -585,11 +585,9 @@ int blk_find_next(enum blk_flag_t flags, struct udevice **devp) int blk_first_device_err(enum blk_flag_t flags, struct udevice **devp) { - int ret; - - for (ret = uclass_first_device_err(UCLASS_BLK, devp); - !ret; - ret = uclass_next_device_err(devp)) { + for (uclass_first_device(UCLASS_BLK, devp); + *devp; + uclass_next_device(devp)) { if (!blk_flags_check(*devp, flags)) return 0; } @@ -599,11 +597,9 @@ int blk_first_device_err(enum blk_flag_t flags, struct udevice **devp) int blk_next_device_err(enum blk_flag_t flags, struct udevice **devp) { - int ret; - - for (ret = uclass_next_device_err(devp); - !ret; - ret = uclass_next_device_err(devp)) { + for (uclass_next_device(devp); + *devp; + uclass_next_device(devp)) { if (!blk_flags_check(*devp, flags)) return 0; } From patchwork Tue Sep 27 21:38:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683612 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=GzIvvsaV; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=UjM1b+0r; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY38060Jz1yq7 for ; Wed, 28 Sep 2022 07:41:08 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id ECC6C84E3E; Tue, 27 Sep 2022 23:39: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=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="GzIvvsaV"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="UjM1b+0r"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B155184E0D; Tue, 27 Sep 2022 23:38:36 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 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 2177884E3C for ; Tue, 27 Sep 2022 23:38:21 +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 E6BDC1FA4F; Tue, 27 Sep 2022 21:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314700; 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=4J/9ZK/MhndNL4gvDTJHgjgSYaHTJchqJCi8VscsfTQ=; b=GzIvvsaVwoXEjHLKMEEUiCqJgBozmo5fpYNJtjqzdJvvhCH3Ym6Q7jQfKGzvbcs7KFo+BM Q2t4jroTa95pUwvTaIOxaSd66ByANiVQPOHqtJSah8yq1zYQbe/4OIz7xDPJZGVNuEYKbd lw/gmzd7yfwHDpe8MfLR7Z0y1tlYLrc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314700; 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=4J/9ZK/MhndNL4gvDTJHgjgSYaHTJchqJCi8VscsfTQ=; b=UjM1b+0rORyrDmxmG6N1+Lk74XF85+6/BoPRu8da7Tl+1RvpPfU3ReQdsfTwJcb9IxeifU MtPW8mdimb8/75Bg== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id A46302C194; Tue, 27 Sep 2022 21:38:20 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Simon Glass , Joe Hershberger , Ramon Fried , Bin Meng , Andrew Scull , Stefan Roese , Vladimir Oltean , =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Pierre-Cl=C3=A9men?= =?utf-8?q?t_Tosi?= Subject: [PATCH v5 13/15] dm: core: Switch uclass_*_device_err to use uclass_*_device_check Date: Tue, 27 Sep 2022 23:38:05 +0200 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 The _err variant iterators use the simple iterators without suffix as basis. However, there is no user that uclass_next_device_err for iteration, many users of uclass_first_device_err use it to get the first and (assumed) only device of an uclass, and a couple that use uclass_next_device_err to get the device following a known device in the uclass list. While there are some truly singleton device classes in which more than one device cannot exist these are quite rare, and most classes can have multiple devices even if it is not the case on the SoC's EVB. In a later patch the simple iterators will be updated to not stop on error and return next device instead. With this in many cases the code that expects the first device or an error if it fails to probe may get the next device instead. Use the _check iterators as the basis of _err iterators to preserve the old behavior. This is problematic for eth_get_dev: it relies on the broken behavior that returns an error but not the device on which the error happened which gives the caller no reasonable way to report or handle the error. With this change the device is returned but eth_get_dev stores the returned device pointer directly in a global state without checking the return value. Unset the pointer again in the error case. Do the same for sysinfo_get because it is not clear how exactly the sysinfo is used by some callers, and fix up a call to pci_get_bus that checks the returned device and not the return value. Switch uclass_foreach_dev_probe to the simple iterator - it does not use the returned value, and did not give out the failing devices previously. Note in documentation that a non-activated device can be returned on error. Signed-off-by: Michal Suchanek --- v5: - udate documentation - fix up a few more cases where device returned on error may cause problem --- drivers/core/uclass.c | 28 ++++++++++++------------- drivers/pci/pci-uclass.c | 7 +++---- drivers/sysinfo/sysinfo-uclass.c | 10 ++++++++- include/dm/uclass.h | 36 ++++++++++++++++++-------------- net/eth-uclass.c | 2 ++ 5 files changed, 48 insertions(+), 35 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index a591e22403..b7d11bdd23 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -586,19 +586,6 @@ int uclass_first_device(enum uclass_id id, struct udevice **devp) return uclass_get_device_tail(dev, ret, devp); } -int uclass_first_device_err(enum uclass_id id, struct udevice **devp) -{ - int ret; - - ret = uclass_first_device(id, devp); - if (ret) - return ret; - else if (!*devp) - return -ENODEV; - - return 0; -} - int uclass_next_device(struct udevice **devp) { struct udevice *dev = *devp; @@ -611,11 +598,24 @@ int uclass_next_device(struct udevice **devp) return uclass_get_device_tail(dev, ret, devp); } +int uclass_first_device_err(enum uclass_id id, struct udevice **devp) +{ + int ret; + + ret = uclass_first_device_check(id, devp); + if (ret) + return ret; + else if (!*devp) + return -ENODEV; + + return 0; +} + int uclass_next_device_err(struct udevice **devp) { int ret; - ret = uclass_next_device(devp); + ret = uclass_next_device_check(devp); if (ret) return ret; else if (!*devp) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 00e3828d95..2aa1043604 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -1768,10 +1768,9 @@ int pci_sriov_init(struct udevice *pdev, int vf_en) bdf = dm_pci_get_bdf(pdev); - pci_get_bus(PCI_BUS(bdf), &bus); - - if (!bus) - return -ENODEV; + ret = pci_get_bus(PCI_BUS(bdf), &bus); + if (ret) + return ret; bdf += PCI_BDF(0, 0, vf_offset); diff --git a/drivers/sysinfo/sysinfo-uclass.c b/drivers/sysinfo/sysinfo-uclass.c index c5cc3cb959..10194d0e14 100644 --- a/drivers/sysinfo/sysinfo-uclass.c +++ b/drivers/sysinfo/sysinfo-uclass.c @@ -16,7 +16,15 @@ struct sysinfo_priv { int sysinfo_get(struct udevice **devp) { - return uclass_first_device_err(UCLASS_SYSINFO, devp); + int ret = uclass_first_device_err(UCLASS_SYSINFO, devp); + + /* + * There is some very dodgy error handling in gazerbeam, + * do not return a device on error. + */ + if (ret) + *devp = NULL; + return ret; } int sysinfo_detect(struct udevice *dev) diff --git a/include/dm/uclass.h b/include/dm/uclass.h index f6c0110b06..b1c016ef9f 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -332,17 +332,6 @@ int uclass_get_device_by_driver(enum uclass_id id, const struct driver *drv, */ int uclass_first_device(enum uclass_id id, struct udevice **devp); -/** - * uclass_first_device_err() - Get the first device in a uclass - * - * The device returned is probed if necessary, and ready for use - * - * @id: Uclass ID to look up - * @devp: Returns pointer to the first device in that uclass, or NULL if none - * Return: 0 if found, -ENODEV if not found, other -ve on error - */ -int uclass_first_device_err(enum uclass_id id, struct udevice **devp); - /** * uclass_next_device() - Get the next device in a uclass * @@ -358,10 +347,23 @@ int uclass_first_device_err(enum uclass_id id, struct udevice **devp); */ int uclass_next_device(struct udevice **devp); +/** + * uclass_first_device_err() - Get the first device in a uclass + * + * The device returned is probed if necessary, and ready for use if no error is + * returned + * + * @id: Uclass ID to look up + * @devp: Returns pointer to the first device in that uclass, or NULL if none + * Return: 0 if found, -ENODEV if not found, other -ve on error + */ +int uclass_first_device_err(enum uclass_id id, struct udevice **devp); + /** * uclass_next_device_err() - Get the next device in a uclass * - * The device returned is probed if necessary, and ready for use + * The device returned is probed if necessary, and ready for use if no error is + * returned * * @devp: On entry, pointer to device to lookup. On exit, returns pointer * to the next device in the uclass if no error occurred, or NULL if @@ -373,7 +375,8 @@ int uclass_next_device_err(struct udevice **devp); /** * uclass_first_device_check() - Get the first device in a uclass * - * The device returned is probed if necessary, and ready for use + * The device returned is probed if necessary, and ready for use if no error is + * returned * * This function is useful to start iterating through a list of devices which * are functioning correctly and can be probed. @@ -389,7 +392,8 @@ int uclass_first_device_check(enum uclass_id id, struct udevice **devp); /** * uclass_next_device_check() - Get the next device in a uclass * - * The device returned is probed if necessary, and ready for use + * The device returned is probed if necessary, and ready for use if no error is + * returned * * This function is useful to start iterating through a list of devices which * are functioning correctly and can be probed. @@ -491,7 +495,7 @@ int uclass_id_count(enum uclass_id id); * are no more devices. */ #define uclass_foreach_dev_probe(id, dev) \ - for (int _ret = uclass_first_device_err(id, &dev); !_ret && dev; \ - _ret = uclass_next_device_err(&dev)) + for (uclass_first_device(id, &dev); dev; \ + uclass_next_device(&dev)) #endif diff --git a/net/eth-uclass.c b/net/eth-uclass.c index 8c3f9cc31b..f41da4b37b 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -93,6 +93,8 @@ struct udevice *eth_get_dev(void) if (eth_errno) eth_errno = uclass_first_device_err(UCLASS_ETH, &uc_priv->current); + if (eth_errno) + uc_priv->current = NULL; } return uc_priv->current; } From patchwork Tue Sep 27 21:38:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683610 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=AfaxMTk6; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=w92rECFW; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY2l3Y9Mz1yq7 for ; Wed, 28 Sep 2022 07:40:47 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 93AB184E40; Tue, 27 Sep 2022 23:39:23 +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="AfaxMTk6"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="w92rECFW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6B06A84E2A; Tue, 27 Sep 2022 23:38:36 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 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 9D7C384E3D for ; Tue, 27 Sep 2022 23:38:21 +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 6D54E21C27; Tue, 27 Sep 2022 21:38:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314701; 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=unXU465X/Yyh0Hzvs+5D25GW8WMQKuJwmxlsc7dMYWo=; b=AfaxMTk6nYyFgZ5wa7BOExNXl9RjFAqUEoJjc5fNrcqhwjwG/8FmUas/XcxiwUNU0WXKGX 9TDsEDDWN92KD3r59f2AqjmymwIOgg2+KJjUQA1UcWLzpkmueD//zLd08wJVCbRm4Nsl8o Vt46mm4F4gVwNIh69TQpcIHZJ4I5Liw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314701; 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=unXU465X/Yyh0Hzvs+5D25GW8WMQKuJwmxlsc7dMYWo=; b=w92rECFWeWEW3/0DUEaSXVCFaZpstSW9reyRr5sSR4WynYcs+vUyhV1tsrciZHFuiv3ceU tk7psZqPIUMBuABA== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id EE0672C195; Tue, 27 Sep 2022 21:38:20 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Bin Meng , Alexander Dahl , Sean Anderson , Simon Glass , Samuel Holland , Eddie James , Andrew Jeffery , Heinrich Schuchardt Subject: [PATCH v5 14/15] dm: treewide: Do not use the return value of simple uclass iterator Date: Tue, 27 Sep 2022 23:38:06 +0200 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 uclass_first_device/uclass_next_device return value will be removed, don't use it. With the current implementation bus is equivalent to !ret. It i redundant to check both, ret check can be replaced with bus check, and ret check inside the iteration is dead code. Signed-off-by: Michal Suchanek Reviewed-by: Simon Glass --- v5: - consolidate multiple similar patches --- cmd/virtio.c | 9 +++------ drivers/dma/dma-uclass.c | 7 +++---- drivers/gpio/gpio-uclass.c | 14 ++++++-------- drivers/w1/w1-uclass.c | 9 ++------- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/cmd/virtio.c b/cmd/virtio.c index ea3ed2e631..f7a2ef4313 100644 --- a/cmd/virtio.c +++ b/cmd/virtio.c @@ -23,18 +23,15 @@ static int do_virtio(struct cmd_tbl *cmdtp, int flag, int argc, * device_probe() for children (i.e. virtio devices) */ struct udevice *bus, *child; - int ret; - ret = uclass_first_device(UCLASS_VIRTIO, &bus); - if (ret) + uclass_first_device(UCLASS_VIRTIO, &bus); + if (!bus) return CMD_RET_FAILURE; while (bus) { device_foreach_child_probe(child, bus) ; - ret = uclass_next_device(&bus); - if (ret) - break; + uclass_next_device(&bus); } return CMD_RET_SUCCESS; diff --git a/drivers/dma/dma-uclass.c b/drivers/dma/dma-uclass.c index 012609bb53..952cbc2170 100644 --- a/drivers/dma/dma-uclass.c +++ b/drivers/dma/dma-uclass.c @@ -209,10 +209,9 @@ int dma_get_cfg(struct dma *dma, u32 cfg_id, void **cfg_data) int dma_get_device(u32 transfer_type, struct udevice **devp) { struct udevice *dev; - int ret; - for (ret = uclass_first_device(UCLASS_DMA, &dev); dev && !ret; - ret = uclass_next_device(&dev)) { + for (uclass_first_device(UCLASS_DMA, &dev); dev; + uclass_next_device(&dev)) { struct dma_dev_priv *uc_priv; uc_priv = dev_get_uclass_priv(dev); @@ -228,7 +227,7 @@ int dma_get_device(u32 transfer_type, struct udevice **devp) *devp = dev; - return ret; + return 0; } int dma_memcpy(void *dst, void *src, size_t len) diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 0ed32b7217..3a35f1e30a 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -59,11 +59,10 @@ static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc) { struct gpio_dev_priv *uc_priv; struct udevice *dev; - int ret; - for (ret = uclass_first_device(UCLASS_GPIO, &dev); + for (uclass_first_device(UCLASS_GPIO, &dev); dev; - ret = uclass_next_device(&dev)) { + uclass_next_device(&dev)) { uc_priv = dev_get_uclass_priv(dev); if (gpio >= uc_priv->gpio_base && gpio < uc_priv->gpio_base + uc_priv->gpio_count) { @@ -73,7 +72,7 @@ static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc) } /* No such GPIO */ - return ret ? ret : -ENOENT; + return -ENOENT; } #if CONFIG_IS_ENABLED(DM_GPIO_LOOKUP_LABEL) @@ -121,12 +120,11 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc) struct udevice *dev; ulong offset; int numeric; - int ret; numeric = isdigit(*name) ? dectoul(name, NULL) : -1; - for (ret = uclass_first_device(UCLASS_GPIO, &dev); + for (uclass_first_device(UCLASS_GPIO, &dev); dev; - ret = uclass_next_device(&dev)) { + uclass_next_device(&dev)) { int len; uc_priv = dev_get_uclass_priv(dev); @@ -154,7 +152,7 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc) } if (!dev) - return ret ? ret : -EINVAL; + return -EINVAL; gpio_desc_init(desc, dev, offset); diff --git a/drivers/w1/w1-uclass.c b/drivers/w1/w1-uclass.c index de4f25bcf9..a4247ecd62 100644 --- a/drivers/w1/w1-uclass.c +++ b/drivers/w1/w1-uclass.c @@ -36,15 +36,10 @@ int w1_bus_find_dev(const struct udevice *bus, u64 id, struct udevice { struct udevice *dev; u8 family = id & 0xff; - int ret; - for (ret = uclass_first_device(UCLASS_W1_EEPROM, &dev); - !ret && dev; + for (uclass_first_device(UCLASS_W1_EEPROM, &dev); + dev; uclass_next_device(&dev)) { - if (ret || !dev) { - debug("cannot find w1 eeprom dev\n"); - return -ENODEV; - } if (dev_get_driver_data(dev) == family) { *devp = dev; From patchwork Tue Sep 27 21:38:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1683613 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=HS6yLxSR; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=AX6fAtaA; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McY3L50h9z1yq7 for ; Wed, 28 Sep 2022 07:41:18 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 265CA84E51; Tue, 27 Sep 2022 23:39:31 +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="HS6yLxSR"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="AX6fAtaA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2389984E29; Tue, 27 Sep 2022 23:38:36 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 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 DCE0384E40 for ; Tue, 27 Sep 2022 23:38:21 +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 9ECF921C34; Tue, 27 Sep 2022 21:38:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664314701; 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=eUeVR6yy9L2FG1/nmlogXzUnMqDCLSDLitjzjxkojVY=; b=HS6yLxSRX9bG2hPYMdTLzwM6cq3vUGJ2OTh1C17dyo4/pUQaGq1qadiVpohpsDKaMEpQTx IV3ODqj/35bllVnfK+fJHdYcGOBmJHivKQMNE1IAF6jV+Q32UJST/56oiv4uYzgo/9CzX9 /6iFlAYWhDWCHzIXw1im0J6JWS8M6yk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664314701; 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=eUeVR6yy9L2FG1/nmlogXzUnMqDCLSDLitjzjxkojVY=; b=AX6fAtaAy1x3taMcUc+o3wk0dRB06zp7ukViz4NWZnax7zwNjgWCrC41mpPONPI4RYfu8A x5/8mPH0I+b04mBA== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id 72CDB2C196; Tue, 27 Sep 2022 21:38:21 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Simon Glass , Tomas Hlavacek , =?utf-8?b?VmlrdG9yIEvFmWl2w6Fr?= , Pavel Herrmann , Marek Vasut Subject: [PATCH v5 15/15] dm: core: Do not stop uclass iteration on error Date: Tue, 27 Sep 2022 23:38:07 +0200 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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 When probing a device fails NULL pointer is returned, and following devices in uclass list cannot be iterated. Skip to next device on error instead. With that the only condition under which these simple iteration functions return error is when the dm is not initialized at uclass_get time. This is not all that interesting, change return type to void. Fixes: 6494d708bf ("dm: Add base driver model support") Signed-off-by: Michal Suchanek Reviewed-by: Simon Glass --- v2: - Fix up tests v3: - Fix up API doc - Correctly forward error from uclass_get - Do not return an error when last device fails to probe - Drop redundant initialization - Wrap at 80 columns v4: - change return value to void - further simplify iteration --- drivers/core/uclass.c | 30 ++++++++++++++++++------------ include/dm/uclass.h | 13 ++++++------- test/dm/core.c | 10 ++++------ test/dm/test-fdt.c | 27 ++++++++++++++++++++------- 4 files changed, 48 insertions(+), 32 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index b7d11bdd23..6dec6a3973 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -574,28 +574,34 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent, } #endif -int uclass_first_device(enum uclass_id id, struct udevice **devp) +/* + * Starting from the given device return first device in the uclass that + * probes successfully. + */ +static void _uclass_next_device(struct udevice *dev, struct udevice **devp) +{ + for (; dev; uclass_find_next_device(&dev)) { + if (!device_probe(dev)) + break; + } + *devp = dev; +} + +void uclass_first_device(enum uclass_id id, struct udevice **devp) { struct udevice *dev; int ret; - *devp = NULL; ret = uclass_find_first_device(id, &dev); - if (!dev) - return 0; - return uclass_get_device_tail(dev, ret, devp); + _uclass_next_device(dev, devp); } -int uclass_next_device(struct udevice **devp) +void 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); + uclass_find_next_device(&dev); + _uclass_next_device(dev, devp); } int uclass_first_device_err(enum uclass_id id, struct udevice **devp) diff --git a/include/dm/uclass.h b/include/dm/uclass.h index b1c016ef9f..ee15c92063 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -320,32 +320,31 @@ int uclass_get_device_by_driver(enum uclass_id id, const struct driver *drv, * uclass_first_device() - Get the first device in a uclass * * The device returned is probed if necessary, and ready for use + * Devices that fail to probe are skipped * * This function is useful to start iterating through a list of devices which * are functioning correctly and can be probed. * * @id: Uclass ID to look up * @devp: Returns pointer to the first device in that uclass if no error - * occurred, or NULL if there is no first device, or an error occurred with - * that device. - * Return: 0 if OK (found or not found), other -ve on error + * occurred, or NULL if there is no usable device */ -int uclass_first_device(enum uclass_id id, struct udevice **devp); +void uclass_first_device(enum uclass_id id, struct udevice **devp); /** * uclass_next_device() - Get the next device in a uclass * * The device returned is probed if necessary, and ready for use + * Devices that fail to probe are skipped * * This function is useful to iterate through a list of devices which * are functioning correctly and can be probed. * * @devp: On entry, pointer to device to lookup. On exit, returns pointer * to the next device in the uclass if no error occurred, or NULL if there is - * no next device, or an error occurred with that next device. - * Return: 0 if OK (found or not found), other -ve on error + * no next device */ -int uclass_next_device(struct udevice **devp); +void uclass_next_device(struct udevice **devp); /** * uclass_first_device_err() - Get the first device in a uclass diff --git a/test/dm/core.c b/test/dm/core.c index 84eb76ed5f..7f3f8d183b 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -1078,11 +1078,10 @@ static int dm_test_uclass_devices_get(struct unit_test_state *uts) struct udevice *dev; int ret; - for (ret = uclass_first_device(UCLASS_TEST, &dev); + for (ret = uclass_first_device_check(UCLASS_TEST, &dev); dev; - ret = uclass_next_device(&dev)) { + ret = uclass_next_device_check(&dev)) { ut_assert(!ret); - ut_assert(dev); ut_assert(device_active(dev)); } @@ -1112,11 +1111,10 @@ static int dm_test_uclass_devices_get_by_name(struct unit_test_state *uts) * this will fail on checking condition: testdev == finddev, since the * uclass_get_device_by_name(), returns the first device by given name. */ - for (ret = uclass_first_device(UCLASS_TEST_FDT, &testdev); + for (ret = uclass_first_device_check(UCLASS_TEST_FDT, &testdev); testdev; - ret = uclass_next_device(&testdev)) { + ret = uclass_next_device_check(&testdev)) { ut_assertok(ret); - ut_assert(testdev); ut_assert(device_active(testdev)); findret = uclass_get_device_by_name(UCLASS_TEST_FDT, diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 6118ad42ca..7cbc595c51 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -403,13 +403,12 @@ static int dm_test_first_next_device(struct unit_test_state *uts) int ret; /* There should be 4 devices */ - for (ret = uclass_first_device(UCLASS_TEST_PROBE, &dev), count = 0; + for (uclass_first_device(UCLASS_TEST_PROBE, &dev), count = 0; dev; - ret = uclass_next_device(&dev)) { + uclass_next_device(&dev)) { count++; parent = dev_get_parent(dev); } - ut_assertok(ret); ut_asserteq(4, count); /* Remove them and try again, with an error on the second one */ @@ -417,16 +416,30 @@ 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_check(UCLASS_TEST_PROBE, &dev), + count = 0; + dev; + ret = uclass_next_device_check(&dev)) { + if (!ret) + count++; + else + ut_asserteq(-ENOMEM, ret); + parent = dev_get_parent(dev); + } + 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 (uclass_first_device(UCLASS_TEST_PROBE, &dev), count = 0; + dev; + uclass_next_device(&dev)) { + count++; + parent = dev_get_parent(dev); + } + ut_asserteq(2, count); return 0; }