From patchwork Wed Dec 7 20:58:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 130032 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 5F3171007D5 for ; Thu, 8 Dec 2011 07:58:45 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757909Ab1LGU6p (ORCPT ); Wed, 7 Dec 2011 15:58:45 -0500 Received: from avon.wwwdotorg.org ([70.85.31.133]:59704 "EHLO avon.wwwdotorg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757891Ab1LGU6o (ORCPT ); Wed, 7 Dec 2011 15:58:44 -0500 Received: from severn.wwwdotorg.org (unknown [192.168.65.5]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPS id 979E4643A; Wed, 7 Dec 2011 14:02:11 -0700 (MST) Received: from localhost.localdomain (searspoint.nvidia.com [216.228.112.21]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by severn.wwwdotorg.org (Postfix) with ESMTPSA id A195FE462C; Wed, 7 Dec 2011 13:58:42 -0700 (MST) From: Stephen Warren To: Mark Brown , Liam Girdwood Cc: Rob Herring , alsa-devel@alsa-project.org, linux-tegra@vger.kernel.org, devicetree-discuss@lists.ozlabs.org, Stephen Warren Subject: [PATCH v2 3/6] ASoC: Refactor some conditions and loop in soc_bind_dai_link() Date: Wed, 7 Dec 2011 13:58:27 -0700 Message-Id: <1323291510-22338-3-git-send-email-swarren@nvidia.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1323291510-22338-1-git-send-email-swarren@nvidia.com> References: <1323291510-22338-1-git-send-email-swarren@nvidia.com> X-NVConfidentiality: public X-Virus-Scanned: clamav-milter 0.96.5 at avon.wwwdotorg.org X-Virus-Status: Clean Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Transform some loops from: for_each(x) { if (f(x)) { work_on(x); } } to new structure: for_each(x) { if (!f(x)) continue; work_on(x); } This will allow future modification of f(x) with less impact to the code. Signed-off-by: Stephen Warren --- v2: New patch sound/soc/soc-core.c | 52 ++++++++++++++++++++++++++++--------------------- 1 files changed, 30 insertions(+), 22 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index f60e04f..d2f9df5 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -764,10 +764,11 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num) } /* no, then find CPU DAI from registered DAIs*/ list_for_each_entry(cpu_dai, &dai_list, list) { - if (!strcmp(cpu_dai->name, dai_link->cpu_dai_name)) { - rtd->cpu_dai = cpu_dai; - goto find_codec; - } + if (strcmp(cpu_dai->name, dai_link->cpu_dai_name)) + continue; + + rtd->cpu_dai = cpu_dai; + goto find_codec; } dev_dbg(card->dev, "CPU DAI %s not registered\n", dai_link->cpu_dai_name); @@ -780,22 +781,28 @@ find_codec: /* no, then find CODEC from registered CODECs*/ list_for_each_entry(codec, &codec_list, list) { - if (!strcmp(codec->name, dai_link->codec_name)) { - rtd->codec = codec; - - /* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/ - list_for_each_entry(codec_dai, &dai_list, list) { - if (codec->dev == codec_dai->dev && - !strcmp(codec_dai->name, dai_link->codec_dai_name)) { - rtd->codec_dai = codec_dai; - goto find_platform; - } - } - dev_dbg(card->dev, "CODEC DAI %s not registered\n", - dai_link->codec_dai_name); + if (strcmp(codec->name, dai_link->codec_name)) + continue; + + rtd->codec = codec; - goto find_platform; + /* + * CODEC found, so find CODEC DAI from registered DAIs from + * this CODEC + */ + list_for_each_entry(codec_dai, &dai_list, list) { + if (codec->dev == codec_dai->dev && + !strcmp(codec_dai->name, + dai_link->codec_dai_name)) { + + rtd->codec_dai = codec_dai; + goto find_platform; + } } + dev_dbg(card->dev, "CODEC DAI %s not registered\n", + dai_link->codec_dai_name); + + goto find_platform; } dev_dbg(card->dev, "CODEC %s not registered\n", dai_link->codec_name); @@ -812,10 +819,11 @@ find_platform: /* no, then find one from the set of registered platforms */ list_for_each_entry(platform, &platform_list, list) { - if (!strcmp(platform->name, platform_name)) { - rtd->platform = platform; - goto out; - } + if (strcmp(platform->name, platform_name)) + continue; + + rtd->platform = platform; + goto out; } dev_dbg(card->dev, "platform %s not registered\n",