From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BD4AC433F5 for ; Sat, 23 Oct 2021 23:28:55 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C516460E9C for ; Sat, 23 Oct 2021 23:28:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C516460E9C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 17D3E8331C; Sun, 24 Oct 2021 01:28:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org 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=chromium.org header.i=@chromium.org header.b="CSUwKpIZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A3C258356E; Sun, 24 Oct 2021 01:27:28 +0200 (CEST) Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4C8288353E for ; Sun, 24 Oct 2021 01:27:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x329.google.com with SMTP id y15-20020a9d460f000000b0055337e17a55so9282885ote.10 for ; Sat, 23 Oct 2021 16:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EWftrgvN0MHFjkxxqaVk2cPQkbBmttiZshI3AGmZgak=; b=CSUwKpIZ8mLkiWRM2QTkHs9Cj/6jp8FuU5nP+KY3j66Dm8w7T1XK9zym/w7NC0lR23 Ir8bqRghqymyZ7bCzaB682ja4x5tt8vJ1EgvJGsLp2p7n96gXUOSQTD06w9ueW1fBp8m nR8n/0RBbSNsKcHdXFOnKoSXPYiGyb9Cm3Pgk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EWftrgvN0MHFjkxxqaVk2cPQkbBmttiZshI3AGmZgak=; b=lHjqIUWvfzB9wp84ZNUsSs8DH0EArIm0NSGJgmQb24o4X7c/cTCrbpxhp856lj/e2g SEoFXrwM57tabXLlvAU9bzvkZ5apvSqQCwd1OUJ+43E0CbaVg9FiF0CnXFk++lOCrlC8 0KSV4s2NGEZPg7drj48x/xR8cr7Vn9kpvEVNc7ZJw9hO7anhIBkcECne2qbbIHVmynK8 1KXegtcxXzVLCuCDUMxs0jQnVelaKyUws4sHCX6BoyY+Vy0rGo1KiFxzfpLY1MHAo4UM vHHwOZu5GsnUnNHMIBkKnsHzFERFYsuskuaWxlNuE5JuP9t6KyaLtNsryJ+jhskDVcML X2zw== X-Gm-Message-State: AOAM531T8+HYHsoay/rXDNviZMH9XWosMTkL3Ga9EdnXXGbof1GdY5qF HZiNg9Cj+9emN8jFHATfHXkTnbXe5k3JGg== X-Google-Smtp-Source: ABdhPJz25wUapvm2hNUdEANsBPPHYpnlvpnGoNW9+nENHgYP+zJqQGqGBWbRbcL4IXLaILTpHSSAgQ== X-Received: by 2002:a05:6830:14d2:: with SMTP id t18mr6818237otq.271.1635031620866; Sat, 23 Oct 2021 16:27:00 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id l24sm2253885oop.4.2021.10.23.16.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Oct 2021 16:27:00 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Michal Simek , Heinrich Schuchardt , Tom Rini , Ilias Apalodimas , Daniel Schwierzeck , Steffen Jaeckel , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Lukas Auer , Dennis Gilmore , Simon Glass , Marek Vasut , Pavel Herrmann Subject: [PATCH v2 15/41] dm: core: Add a way to count the devices in a uclass Date: Sat, 23 Oct 2021 17:26:09 -0600 Message-Id: <20211023232635.9195-14-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog In-Reply-To: <20211023232635.9195-1-sjg@chromium.org> References: <20211023232635.9195-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean Add a function that returns the number of devices in a uclass. This can be helpful in sizing an array that needs to hold a list of them. Signed-off-by: Simon Glass --- (no changes since v1) drivers/core/uclass.c | 12 ++++++++++++ include/dm/uclass.h | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 3de5f27fe4a..2aa21430775 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -794,6 +794,18 @@ int uclass_probe_all(enum uclass_id id) return 0; } +int uclass_id_count(enum uclass_id id) +{ + struct udevice *dev; + struct uclass *uc; + int count = 0; + + uclass_id_foreach_dev(id, dev, uc) + count++; + + return count; +} + UCLASS_DRIVER(nop) = { .id = UCLASS_NOP, .name = "nop", diff --git a/include/dm/uclass.h b/include/dm/uclass.h index aea2f34fce1..f1fd2ba2463 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -425,6 +425,14 @@ int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data, */ int uclass_probe_all(enum uclass_id id); +/** + * uclass_id_count() - Count the number of devices in a uclass + * + * @id: uclass ID to look up + * @return number of devices in that uclass (0 if none) + */ +int uclass_id_count(enum uclass_id id); + /** * uclass_id_foreach_dev() - Helper function to iteration through devices * -- 2.33.0.1079.g6e70778dc9-goog