From patchwork Tue Aug 27 07:06:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhangzekun (A)" X-Patchwork-Id: 13779004 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 874DD14C59A for ; Tue, 27 Aug 2024 07:20:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724743213; cv=none; b=EdHBGTwGbrEW0ZP2a80tJ+yQHQOJAulomQIhTkt6cKEdg7sJxvoqqfAnNTXT1+GXdKwAdkbbt00nE2aM218Q0nu6jADlQa7LidFfLKXN2+fAi5PFl3326QAbJ2UijXNIcRQBmNGf92ovs+cQEZ+1E8+R6DoCxknAiUqHWyV3lJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724743213; c=relaxed/simple; bh=OA9nb4uPtm55m/VXsW1phs7FIinhWfeuVWaaZiNHVGM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=scnqb2Iv1O2IeFE5ieSl2ZgyOBQbUVo4pvuHBmZno7FlCjSrue+z7SqXUxRlKU9S9JiKUlSqWe6+qYzDj9akHhEYml5B8eTVKaH28PATuEXIm8I654Kmme2QR/mtW3fRpMR3F59Es5cIyDvnWpMQxpCMRm3nw5/HeRlJeloDmuU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WtJmD48ZSzfbVN; Tue, 27 Aug 2024 15:18:04 +0800 (CST) Received: from kwepemf500003.china.huawei.com (unknown [7.202.181.241]) by mail.maildlp.com (Postfix) with ESMTPS id E4E13140137; Tue, 27 Aug 2024 15:20:07 +0800 (CST) Received: from huawei.com (10.175.112.208) by kwepemf500003.china.huawei.com (7.202.181.241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 27 Aug 2024 15:20:07 +0800 From: Zhang Zekun To: , , , , CC: Subject: [PATCH v2 1/2] ASoC: audio-graph-card: Use for_each_child_of_node_scoped() to simplify code Date: Tue, 27 Aug 2024 15:06:49 +0800 Message-ID: <20240827070650.11424-2-zhangzekun11@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240827070650.11424-1-zhangzekun11@huawei.com> References: <20240827070650.11424-1-zhangzekun11@huawei.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemf500003.china.huawei.com (7.202.181.241) for_each_child_of_node_scoped() can put the device_node automatically. So, using it to make the code logic more simple and remove the device_node clean up code. Signed-off-by: Zhang Zekun --- sound/soc/generic/audio-graph-card.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c index 3425fbbcbd7e..30152a681aa8 100644 --- a/sound/soc/generic/audio-graph-card.c +++ b/sound/soc/generic/audio-graph-card.c @@ -363,7 +363,6 @@ static int __graph_for_each_link(struct simple_util_priv *priv, struct device *dev = simple_priv_to_dev(priv); struct device_node *node = dev->of_node; struct device_node *cpu_port; - struct device_node *cpu_ep; struct device_node *codec_ep; struct device_node *codec_port; struct device_node *codec_port_old = NULL; @@ -373,14 +372,9 @@ static int __graph_for_each_link(struct simple_util_priv *priv, /* loop for all listed CPU port */ of_for_each_phandle(&it, rc, node, "dais", NULL, 0) { cpu_port = it.node; - cpu_ep = NULL; /* loop for all CPU endpoint */ - while (1) { - cpu_ep = of_get_next_child(cpu_port, cpu_ep); - if (!cpu_ep) - break; - + for_each_child_of_node_scoped(cpu_port, cpu_ep) { /* get codec */ codec_ep = of_graph_get_remote_endpoint(cpu_ep); codec_port = ep_to_port(codec_ep); @@ -410,10 +404,8 @@ static int __graph_for_each_link(struct simple_util_priv *priv, of_node_put(codec_ep); of_node_put(codec_port); - if (ret < 0) { - of_node_put(cpu_ep); + if (ret < 0) return ret; - } codec_port_old = codec_port; } From patchwork Tue Aug 27 07:06:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhangzekun (A)" X-Patchwork-Id: 13779003 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C60B314D2B3 for ; Tue, 27 Aug 2024 07:20:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724743213; cv=none; b=XNbdUqQW68iJpoNr3Vpo+TabOHInukkRl5we7a5lc55oFBiqTLrew73Q5U+Kw3EP2peF/N3mfVBuQ01Fn48r/8NCok8nzp9k75MO6+LPMN2UvZtNuoyLoPlhTB3cI+CUmL9cEFmCtfV317xSyPYQGCjxOIQp9boLllCjsKHQe5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724743213; c=relaxed/simple; bh=vjV3k0HFFp5C7DEFWtEAMP7t4IbkwjP8TU05lebKjew=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kKwcDBFSkZPGE2EDvvUQs8Vo7ifTOnM/yOT0ll7q4s9Vm2V6jwwrs9pVA24BB5rfRGFMgdcN6/mRXyzCo3qzUQpX2aQPwWbIbA5PKRmuwSdjjwAT9cCtoJf/FAz68AC9/2Mv0SihSTeMixLV/bUtEnthb3g5SopkS1BvNSGF7xQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WtJpQ4h6xz2Cnl6; Tue, 27 Aug 2024 15:19:58 +0800 (CST) Received: from kwepemf500003.china.huawei.com (unknown [7.202.181.241]) by mail.maildlp.com (Postfix) with ESMTPS id 7BE43140136; Tue, 27 Aug 2024 15:20:08 +0800 (CST) Received: from huawei.com (10.175.112.208) by kwepemf500003.china.huawei.com (7.202.181.241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 27 Aug 2024 15:20:07 +0800 From: Zhang Zekun To: , , , , CC: Subject: [PATCH v2 2/2] ASoC: audio-graph-card2: Use helper function of_get_child_count() Date: Tue, 27 Aug 2024 15:06:50 +0800 Message-ID: <20240827070650.11424-3-zhangzekun11@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240827070650.11424-1-zhangzekun11@huawei.com> References: <20240827070650.11424-1-zhangzekun11@huawei.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemf500003.china.huawei.com (7.202.181.241) of_get_child_count() can help to get the num of child directly and we don't need to manually count the child num. No functional change with this conversion. Signed-off-by: Zhang Zekun --- v2: Remove the use of for_each_child_of_node() to avoid code logic broken and add the comment back. sound/soc/generic/audio-graph-card2.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/sound/soc/generic/audio-graph-card2.c b/sound/soc/generic/audio-graph-card2.c index 56f7f946882e..ebbe12692f57 100644 --- a/sound/soc/generic/audio-graph-card2.c +++ b/sound/soc/generic/audio-graph-card2.c @@ -1141,21 +1141,12 @@ static int graph_counter(struct device_node *lnk) */ if (graph_lnk_is_multi(lnk)) { struct device_node *ports = port_to_ports(lnk); - struct device_node *port = NULL; - int cnt = 0; /* * CPU/Codec = N:M case has many endpoints. * We can't use of_graph_get_endpoint_count() here */ - while(1) { - port = of_get_next_child(ports, port); - if (!port) - break; - cnt++; - } - - return cnt - 1; + return of_get_child_count(ports) - 1; } /* * Single CPU / Codec