From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0512CC433F5 for ; Wed, 19 Jan 2022 01:44:58 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C49AA834A0; Wed, 19 Jan 2022 02:44:21 +0100 (CET) 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="EEYlXOPH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3DC4683281; Wed, 19 Jan 2022 02:43:54 +0100 (CET) Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) (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 D3026836D8 for ; Wed, 19 Jan 2022 02:43:45 +0100 (CET) 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-io1-xd32.google.com with SMTP id y22so957814iof.7 for ; Tue, 18 Jan 2022 17:43:45 -0800 (PST) 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=vpWxnkJksBEvJvRtz4b8OxOPdsYHs6x70ZWl6eLP7rA=; b=EEYlXOPHA2iN3NULnHILLe7y1oPxZ3uOphVCLRKuicX6vw61N2MbI7WvF2ERZfoybS zRmdX9XwELIVLL+tw3JkJOkud0akyLOMBHwFmvj3jcrt6OgXYkLy5Lc6XZagTMrJLJ/V rHIKGIifNogLNPusOTVUwqhtxCChpSrgtykHY= 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=vpWxnkJksBEvJvRtz4b8OxOPdsYHs6x70ZWl6eLP7rA=; b=XwgrlXGOOvKBXTzxI36ym6g025WRqdKU4wAodj9KpRSNIa7wTCkjFmovFo/OdGxExS MmZPWqgEdQsv2JtP+tUi7XpARkJKi2+FjZkmJj0jXA9pD0e3ftFLWMt7k8s7sirO+C0y uNHS4TfSB3lF6lH+qykr/SlaAa9zaSrYvFTatgk57n4DP/Eaqq7Kxo4Pt7hlnAkTL+I1 7SRk35wShTUMh1wtXdP8WOlzj3e8Uh2Fpkq19hCM3iDvoM8NZmFZ+7/UTJQQdodqHBDY 0TCJUZktMma0+dKqiWG5vjcH2mdUayd0wCuhvG3Kh3VEXzU5c6ZPqdK/vlgUN0OmJslj yabQ== X-Gm-Message-State: AOAM533kXmQGb2KWmbcDv9ioQLJ4yB87ObFJRbIf89aFhqAKkuZ/hMY3 6JquOoQvidIqbvsbhQHNtlcAjQ/xLwEg5A== X-Google-Smtp-Source: ABdhPJySBUVm9srJmJwpvQjBHTDRvFZZM4PJvJGhG9b8v4EplUUqNDeU3O8MrPRTn+cIy0WnCPksyw== X-Received: by 2002:a6b:b7d4:: with SMTP id h203mr9366818iof.193.1642556624262; Tue, 18 Jan 2022 17:43:44 -0800 (PST) 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 j18sm10546314ila.86.2022.01.18.17.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 17:43:44 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Ilias Apalodimas , Daniel Schwierzeck , Dennis Gilmore , Steffen Jaeckel , Lukas Auer , Michal Simek , Tom Rini , Heinrich Schuchardt , Simon Glass , Marek Vasut , Pavel Herrmann Subject: [PATCH v3 06/31] dm: core: Allow finding a uclass device by partial name Date: Tue, 18 Jan 2022 18:42:50 -0700 Message-Id: <20220119014315.1938157-7-sjg@chromium.org> X-Mailer: git-send-email 2.34.1.703.g22d0c6ccf7-goog In-Reply-To: <20220119014315.1938157-1-sjg@chromium.org> References: <20220119014315.1938157-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean In some cases two devices are related and the only way to tell is to check that the names partially patch. Add a way to check this without needing to create a new string for the comparison. Fix the comment for device_find_child_by_namelen() while we are here. Signed-off-by: Simon Glass --- Changes in v3: - Add new patch to support finding a uclass device by partial name drivers/core/uclass.c | 13 ++++++++++--- include/dm/device.h | 2 +- include/dm/uclass-internal.h | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 563ff9b2856..a0d3840802b 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -274,8 +274,8 @@ int uclass_find_next_device(struct udevice **devp) return 0; } -int uclass_find_device_by_name(enum uclass_id id, const char *name, - struct udevice **devp) +int uclass_find_device_by_namelen(enum uclass_id id, const char *name, int len, + struct udevice **devp) { struct uclass *uc; struct udevice *dev; @@ -289,7 +289,8 @@ int uclass_find_device_by_name(enum uclass_id id, const char *name, return ret; uclass_foreach_dev(dev, uc) { - if (!strcmp(dev->name, name)) { + if (!strncmp(dev->name, name, len) && + strlen(dev->name) == len) { *devp = dev; return 0; } @@ -298,6 +299,12 @@ int uclass_find_device_by_name(enum uclass_id id, const char *name, return -ENODEV; } +int uclass_find_device_by_name(enum uclass_id id, const char *name, + struct udevice **devp) +{ + return uclass_find_device_by_namelen(id, name, strlen(name), devp); +} + int uclass_find_next_free_seq(struct uclass *uc) { struct udevice *dev; diff --git a/include/dm/device.h b/include/dm/device.h index 435a1114f1c..30703af96e4 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -791,7 +791,7 @@ int device_find_first_child_by_uclass(const struct udevice *parent, struct udevice **devp); /** - * device_find_child_by_name() - Find a child by device name + * device_find_child_by_namelen() - Find a child by device name * * @parent: Parent device to search * @name: Name to look for diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index fb0edcc2969..1118f64bdfd 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -154,6 +154,22 @@ int uclass_find_first_device(enum uclass_id id, struct udevice **devp); */ int uclass_find_next_device(struct udevice **devp); +/** + * uclass_find_device_by_namelen() - Find uclass device based on ID and name + * + * This searches for a device with the exactly given name. + * + * The device is NOT probed, it is merely returned. + * + * @id: ID to look up + * @name: name of a device to find + * @len: Length of @name (the uclass driver name must have the same length) + * @devp: Returns pointer to device (the first one with the name) + * @return 0 if OK, -ve on error + */ +int uclass_find_device_by_namelen(enum uclass_id id, const char *name, int len, + struct udevice **devp); + /** * uclass_find_device_by_name() - Find uclass device based on ID and name * -- 2.34.1.703.g22d0c6ccf7-goog