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 B2322C433EF for ; Wed, 19 Jan 2022 11:28:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6C52283811; Wed, 19 Jan 2022 12:28:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.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; secure) header.d=gmx.net header.i=@gmx.net header.b="YeoQA3hs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 968A683820; Wed, 19 Jan 2022 12:28:40 +0100 (CET) Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (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 8B6D5832CD for ; Wed, 19 Jan 2022 12:28:37 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1642591712; bh=DH9SbXeCsi619H6MX72nZtsK3slsw9FbVVN/cdXLG7s=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=YeoQA3hsi8b2GsFIjWrFtlf8zxc86SzUskE9fFBP9TGKsOSh7WGiNdB6rq2i28HxF VS+rPeXls3p1eKGMNtiglqJ5mgU2TtOSYA/Ouyy89ReBRS2wQH4zqSj2sG+DXLFFGD 2Im6BS40vWj8gl9pb6eHwbKLOzb8DVbkf3joQ8qo= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.94] ([88.152.144.107]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MFbW0-1n6Feo2JX4-00H4Sz; Wed, 19 Jan 2022 12:28:32 +0100 Message-ID: Date: Wed, 19 Jan 2022 12:28:31 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v3 06/31] dm: core: Allow finding a uclass device by partial name Content-Language: en-US To: Simon Glass , U-Boot Mailing List Cc: Ilias Apalodimas , Daniel Schwierzeck , Dennis Gilmore , Steffen Jaeckel , Lukas Auer , Michal Simek , Tom Rini , Marek Vasut , Pavel Herrmann References: <20220119014315.1938157-1-sjg@chromium.org> <20220119014315.1938157-7-sjg@chromium.org> From: Heinrich Schuchardt In-Reply-To: <20220119014315.1938157-7-sjg@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:im7nZev6J0NRIK52IGv0/MZauBaJxeRR6LEdGinxJbJuoKXt5TF Cjh6j9xu/z6T5JxNVIIzIIgjkusIqU/weUmaFR/T/NE31lpump2FSlywaiwRFljLZ0zwNPo 4II7RbLUbe7hWFAncvmXB9V6ANTF9HSyALnhHF7+z9EmKR2bqlx57PUIe/PA/xHcDM/1jyS 5x8q3/cRcRxW20BW0Mupw== X-UI-Out-Filterresults: notjunk:1;V03:K0:XVbLbvkPCE0=:4XrXkHOFFk0445EfiibuKC iIsmasuaq+GPxxs0BBlwB30XK6vED+BdMY9aCBzcvpdNGgNzE889fstc8oFjCBhaIhpVBmILr cMQM+C/mg3bzqsBMBd44Qo5hCNq3Ak4eUkQCXbISqKr0pZDsmrL4rvOribK2urv33oVph6gRd zOCtIPSamh5Il4x0ksGYT+Q4MY/BHj9vhIcG6NtXrx6Ww+oT78zjh935sI/nqoRsETRka3Jhn oqD4k46inmjf1Bg9FZg1mOZiILncx+eWx7mraSh/2b3QAO6pHVQDr4snfX+UX1u9Di0ukReMP L6w6+gB417Rawx61VUdjOwsTZQ5CHJKKkWZguki9BQBRtKI6bY9CJzLI+0x+qlN8S6KnKC6ZG 5qP+zQH2YwyJzyJc8ZXeOvvgtMaz5d93rHdZkZztuHI5scwvry6cRsOcPBWYX9XI8q5ildlk+ yzRCmcV8/6Y6ex2oDmL2HjmSmfqBzI87eIo+Iqe8gczBw7gpMI+h8mm2cfoTWkW295L7Yxb6Y s2yrXq8PWNuzn8C8F0Oq4DceOdx6I4C++/PXk0jy3u9z40ae6aIWCYbXyW93sgBvfawOyvOIT P3+HtWRsGWifDBYcrX/WwiAM19iMMcv3t+f6EmW7PhC2xEUPAVztWoC3YZ6tAhD2lvT+MeAJ1 XkDN7ylA39JnFudRslM55tlIFyt2pPR1uoR54PuqXiv8FaUiZ+vVgNKDVCbJz9HK+zqJZfyrn eI3Bj2mfHPkD4hILnBxUgcGajYrX9BWnltZdPWONPxc7H5czv+CWPMUOOa1qVWR0ZfpW0gXqY jCmzAQT7Kj0aKZ6Mwdl85ytEUGnfYsJMahlrApcTzl4lrejiAIMpcdxVbx0HXPGwsBc4G9hJh 6tGLgKY5NlgiLNzBfsNxGc50H6zpoTHlSvlrI1VtOGCNfhKBUww/z5VxpT/IGwKhmcS5q28fo F5ToZ8Zb+Vrc6MXSGmayX3eFvrg8JxW9GnWCFwrbablORlnda+QV6W2sItx3Pub2bXHDLmY3s vCLYKPS7prJllXn496mBE6yN+zzaUKGQ0vVLJzutKU38J/nIK6QhVc80Gl+cxkEb1TvYe0Cc5 WjOr7urod6RG2A= 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 On 1/19/22 02:42, Simon Glass wrote: > 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, co= nst char *name, > return ret; > > uclass_foreach_dev(dev, uc) { > - if (!strcmp(dev->name, name)) { > + if (!strncmp(dev->name, name, len) && > + strlen(dev->name) =3D=3D len) { > *devp =3D dev; > return 0; > } > @@ -298,6 +299,12 @@ int uclass_find_device_by_name(enum uclass_id id, c= onst 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 u= device *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, str= uct 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 len= gth) > + * @devp: Returns pointer to device (the first one with the name) > + * @return 0 if OK, -ve on error Return: https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-= documentation Best regards Heinrich > + */ > +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 n= ame > *