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 CD862C433FE for ; Mon, 17 Jan 2022 15:49:55 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 95A22837D0; Mon, 17 Jan 2022 16:49:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.b="uyClMQ6c"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 729FF834A0; Mon, 17 Jan 2022 16:49:36 +0100 (CET) Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 73332834B1 for ; Mon, 17 Jan 2022 16:49:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=7016abadf2=patrick.delaunay@foss.st.com Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20HDZ1Pt009903; Mon, 17 Jan 2022 16:49:29 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=kOn8Sj0wWdfXfhGQ8PYqqz8aCFZf12G+1yxZZHTu8AY=; b=uyClMQ6c7iux4nvuF7VBbVkd82tbXlGKawingKvzK3lb49BXhOM52r7aLMDVnf1FDXZc PxRQmsKTBPArDz2+5vaqAO6ShhCZ/uDYdivqHQSnyZYyVHCVeF4k846ZigDxRNfoWksa Tft/aeJCnC5obuialvSX6/N+8C6ivndOFaWr9gHgK8Q0dCuh5fAGLh5wC9fgfmG+9dSf ruQN5rG1Vn5Qd+W2a++QYrY470lkk2AJ939rnmic+KV0SR8WUdi1ZKJCzjHMNEfHgd1c bIm3pEDE+ctjA0wQcoCPX+hoF3EvZ+dq2ulRA7eLk08aFV0bzMLWk5en5ABjpGUberLi OA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3dmwkwkpbn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Jan 2022 16:49:29 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 04A7F100038; Mon, 17 Jan 2022 16:49:29 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node1.st.com [10.75.127.4]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id F159D21E66D; Mon, 17 Jan 2022 16:49:28 +0100 (CET) Received: from localhost (10.75.127.50) by SFHDAG2NODE1.st.com (10.75.127.4) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Mon, 17 Jan 2022 16:49:28 +0100 From: Patrick Delaunay To: CC: Patrick Delaunay , Simon Glass , U-Boot STM32 Subject: [PATCH v2 2/3] dm: compare full name in uclass_get_by_name Date: Mon, 17 Jan 2022 16:49:21 +0100 Message-ID: <20220117164919.v2.2.I85a4f70465cef5ef600f264706dca84c55c7efdb@changeid> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117154922.1085936-1-patrick.delaunay@foss.st.com> References: <20220117154922.1085936-1-patrick.delaunay@foss.st.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG2NODE1.st.com (10.75.127.4) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-17_07,2022-01-14_01,2021-12-02_01 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 Change uclass_get_by_name to use a strict string compare function "strcmp" with the parameter 'name'. This patch avoids issues when strlen(name)name) as the function uclass_get_by_name() no more use uclass_get_by_name_len(), which limit the check with "strncmp" and length of name. This problem is detected by the sandbox test for log filter: in log_get_cat_by_name(), uclass_get_by_name("spi") = UCLASS_SPI_EMUL for "spi_emul", it is not the expected result = UCLASS_SPI for a search by name. But it is the expected result for search with partial name uclass_get_by_name_len("spi", 3). Signed-off-by: Patrick Delaunay --- (no changes since v1) drivers/core/uclass.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 336ea8d243..32b6cef167 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -196,7 +196,16 @@ enum uclass_id uclass_get_by_name_len(const char *name, int len) enum uclass_id uclass_get_by_name(const char *name) { - return uclass_get_by_name_len(name, strlen(name)); + int i; + + for (i = 0; i < UCLASS_COUNT; i++) { + struct uclass_driver *uc_drv = lists_uclass_lookup(i); + + if (uc_drv && !strcmp(uc_drv->name, name)) + return i; + } + + return UCLASS_INVALID; } int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp) -- 2.25.1