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 9FEC8C05027 for ; Sun, 12 Feb 2023 17:51:52 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F1CCB851C7; Sun, 12 Feb 2023 18:51:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="l96R4mPe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C1AFA851C7; Sun, 12 Feb 2023 18:51:48 +0100 (CET) Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) (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 6D25F85103 for ; Sun, 12 Feb 2023 18:51:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x836.google.com with SMTP id w3so11608129qts.7 for ; Sun, 12 Feb 2023 09:51:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=bO/JBUpZU5m71yebKbmgIrzQV6l1g1uU5avh9ZIl3Bw=; b=l96R4mPeb7XvKd0Oulg8UN2/rECUGz7hrErIJB14+Kx/g+adsmFIgZRe2iE5pqjJB0 3K2vCBDHQ94DfWl+I27VJ+HMv/14GBzJWw8KcdzWXTNDqnqx7tlS6TB2m8qCfEfaSoWl TH5kOzWxRjZW/Omf9eAvRfPzfR3/j5Oxo4tpQ4o5r/Zxp/ApIKfUmSL65+TesZNBUpbP 3les3mAH+EYpCjYwM9Qa19NKzPY/7k4KAeR2eaRaio16YguFx3A4uC8Y67dEmBRpc9T4 aBC25IMpKBUVXrgd2E/uzYx1JIQh0yWg8q5PaDwW4QrxBrdgSK/jzn1RerbUSQhqzrne qJ5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bO/JBUpZU5m71yebKbmgIrzQV6l1g1uU5avh9ZIl3Bw=; b=VjTI817JX+VsfzdF7h64Xd4f8B/xtr/DRXnFBuBzheYkgGuaEC9YzchSzAE0qw1a0v 7f/5Trcc6LfuVvnWiqQTSzzIWjlPTkpS8+bkTcwGp7UzCm2QVY91HfdboK9OSDTkKKkg JMmwMfeAoH90+tHf8yhbJSemJDx2h8eUOewzCR0vMIMeYfS+il0dUowJs5vsVG5zdSHf BUKDz02g6tsiAscuieaLVbMgWjcQ+DLKHmBcxr2Txx9EsLNBUpOg1Ye/w1illusNh4Iz cMx+Rm8b+Yrl7OKXeQdzj2x71djXTN/+F8SUEcC5ymuEk3qtwLzuyoILK1wdv74hIIcj cfzA== X-Gm-Message-State: AO0yUKUNPiut1QEjlLwtSwaib9pgNCxYErc8TkmW6BM1rBvVJFRhblPX 20DEVD/CH+GYcf6xfaBWr7M= X-Google-Smtp-Source: AK7set/aVbYUe40zGCebb1El9/AoX8tXnvRl7oEhna3Y5BEBUVfD290bIXh2dPbBhtZNuFD+xJeduQ== X-Received: by 2002:a05:622a:c7:b0:3ba:1398:c68d with SMTP id p7-20020a05622a00c700b003ba1398c68dmr37531769qtw.16.1676224304206; Sun, 12 Feb 2023 09:51:44 -0800 (PST) Received: from [192.168.1.201] (pool-173-73-95-180.washdc.fios.verizon.net. [173.73.95.180]) by smtp.gmail.com with ESMTPSA id s15-20020ac85ecf000000b003b62e8b77e7sm7521667qtx.68.2023.02.12.09.51.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Feb 2023 09:51:43 -0800 (PST) Message-ID: <57754ad1-9be0-9280-7912-d3d9a5d6dd8b@gmail.com> Date: Sun, 12 Feb 2023 12:51:42 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v2 1/2] clk: Allow clk_get_by_name() with NULL name Content-Language: en-US To: Samuel Holland , Lukasz Majewski , Simon Glass Cc: Dario Binacchi , Michal Suchanek , u-boot@lists.denx.de References: <20230122000252.53642-1-samuel@sholland.org> From: Sean Anderson In-Reply-To: <20230122000252.53642-1-samuel@sholland.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 On 1/21/23 19:02, Samuel Holland wrote: > This allows devm_clock_get(dev, NULL) to work and get the first clock, > which is common in code ported from Linux. > > Signed-off-by: Samuel Holland > --- > > Changes in v2: > - Move index error check inside if statement > - Update function comment > - Add unit test > > drivers/clk/clk-uclass.c | 12 +++++++----- > include/clk.h | 4 ++-- > test/dm/clk.c | 5 +++++ > 3 files changed, 14 insertions(+), 7 deletions(-) > > diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c > index 2f9635524c..dc3e9d6a26 100644 > --- a/drivers/clk/clk-uclass.c > +++ b/drivers/clk/clk-uclass.c > @@ -399,16 +399,18 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk) > > int clk_get_by_name_nodev(ofnode node, const char *name, struct clk *clk) > { > - int index; > + int index = 0; > > debug("%s(node=%p, name=%s, clk=%p)\n", __func__, > ofnode_get_name(node), name, clk); > clk->dev = NULL; > > - index = ofnode_stringlist_search(node, "clock-names", name); > - if (index < 0) { > - debug("fdt_stringlist_search() failed: %d\n", index); > - return index; > + if (name) { > + index = ofnode_stringlist_search(node, "clock-names", name); > + if (index < 0) { > + debug("fdt_stringlist_search() failed: %d\n", index); > + return index; > + } > } > > return clk_get_by_index_nodev(node, index, clk); > diff --git a/include/clk.h b/include/clk.h > index 138766bd49..d91285235f 100644 > --- a/include/clk.h > +++ b/include/clk.h > @@ -167,7 +167,7 @@ int clk_get_bulk(struct udevice *dev, struct clk_bulk *bulk); > * clk_get_by_name() - Get/request a clock by name. > * @dev: The client device. > * @name: The name of the clock to request, within the client's list of > - * clocks. > + * clocks, or NULL to request the first clock in the list. > * @clk: A pointer to a clock struct to initialize. > * > * This looks up and requests a clock. The name is relative to the client > @@ -184,7 +184,7 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk); > * clk_get_by_name_nodev - Get/request a clock by name without a device. > * @node: The client ofnode. > * @name: The name of the clock to request, within the client's list of > - * clocks. > + * clocks, or NULL to request the first clock in the list. > * @clk: A pointer to a clock struct to initialize. > * > * Return: 0 if OK, or a negative error code. > diff --git a/test/dm/clk.c b/test/dm/clk.c > index 21997ed892..f48de05436 100644 > --- a/test/dm/clk.c > +++ b/test/dm/clk.c > @@ -26,6 +26,11 @@ static int dm_test_clk_base(struct unit_test_state *uts) > ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test", &dev)); > > /* Get the same clk port in 2 different ways and compare */ > + ut_assertok(clk_get_by_index(dev, 0, &clk_method1)); > + ut_assertok(clk_get_by_name(dev, NULL, &clk_method2)); > + ut_asserteq(clk_is_match(&clk_method1, &clk_method2), true); > + ut_asserteq(clk_method1.id, clk_method2.id); > + > ut_assertok(clk_get_by_index(dev, 1, &clk_method1)); > ut_assertok(clk_get_by_index_nodev(dev_ofnode(dev), 1, &clk_method2)); > ut_asserteq(clk_is_match(&clk_method1, &clk_method2), true); Reviewed-by: Sean Anderson