From patchwork Fri Jun 2 10:11:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 102437 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp922026vqr; Fri, 2 Jun 2023 03:22:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6JYBC2pFXVxPDcaD5qjJL0o88lk5MEvo1UABGQUhh+P/cgA2SDv4giP8HYS8G7eHJKg7FK X-Received: by 2002:a05:6808:307:b0:398:342a:f491 with SMTP id i7-20020a056808030700b00398342af491mr2068439oie.34.1685701352815; Fri, 02 Jun 2023 03:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685701352; cv=none; d=google.com; s=arc-20160816; b=bGjDeoXjkQeW2u7AVjZ+w/GNe98SLnhQcpAMzHAsyrnXqIbjwhg5I+nSYX4v79mlMi Y17EKtB/nU1uVK2AV1tkbqUSb2yfERmVWZ3IuupoWNEwxvDfldhut+jjYUEjZC32mP4r b7p35vW52X6ZiPX51bU3li/n1+xTDu31F39pRbVw+5E9w4gA2f7jp8TbpfKZEkTFnTGn a9m0MT+toIyaS5mue0kq8eKUCFqwvzmvXqwvEw2oS9vhP1fd/vGLXuCs0+nP+hxHu1wL BgaVyHcHx0dxld98EjBS7mbMXbVSxDvkPwlydRZRLbiz4IL9RWfPV77KCBqyZZ00C7m4 cm7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ekNDg+VFCiYjY12i1sso3YR2oeivSEZ1eM5g+XhkXVk=; b=YFYdLawtiiff7b+6PuTsuFLtI7EibFS7CJ0Y0JchhZl92P2SzmmcAeA1A2eiLlxjhi wMglfNifjqG8IY+bkjUqsGUV/X3mp+Wglug60ZFWjvY6oMJ7O97LmakhWWK6+epBNP/t RWl2dhup0BYwdUSr2Jb/5Nt4pT0T/963/Acdap+A53MKY9gyE3Mk0pjUpYCEclFi5UHY jiBLC9jXodUi5ISLHiFEsuk03ABh6e2JtXBNTwIMGwtJtIT9AWablEAzKxfXGkCdw5Oh 6ExoEOIYetRgdq2hv99n/41F2VAZrDOyeb7z/OkVxMPiK8Yia/NrqFSIKEJvhEsfBeSN gGhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=NwA0aBf3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b10-20020a170903228a00b001afe7fcb257si742652plh.64.2023.06.02.03.22.20; Fri, 02 Jun 2023 03:22:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=NwA0aBf3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234955AbjFBKMI (ORCPT + 99 others); Fri, 2 Jun 2023 06:12:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234752AbjFBKMG (ORCPT ); Fri, 2 Jun 2023 06:12:06 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3F38E7 for ; Fri, 2 Jun 2023 03:12:04 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3529pNL6008786; Fri, 2 Jun 2023 05:11:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=ekNDg+VFCiYjY12i1sso3YR2oeivSEZ1eM5g+XhkXVk=; b=NwA0aBf3TP7NpVjiw0EJV/RbeZGd/UWQBsdeOCVAoHm2dIV1bdvQGWLFpj+QmDsv0Elx rm7ePWFnD3/nRGRpNgikcS0BhQZIlcMXnHS3FDqc4gtTrps94rGMRjRgGGwICe+05tHb BjBzgzZlugbEjjnvPNZxdwUu4YKS+fVjp1am948cd5MhcRFRhDZeCBV5dxpPSd7JVyDQ atsunAqrrWB9YkOsNBU1/qkfUguMiuYm+y0o2IGzChlwAD1MGnLhe2b3rJDI7nIXB70x dn9S5y/4EOVRrAACMbbOuapNl5Eh2NO4w8zzqwnQt6+CgvFzDOTR5kJwMhAVk7105suK fg== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3quf90y83v-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 02 Jun 2023 05:11:44 -0500 Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 2 Jun 2023 11:11:40 +0100 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 2 Jun 2023 11:11:40 +0100 Received: from algalon.ad.cirrus.com (algalon.ad.cirrus.com [198.90.251.122]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id D662E15A4; Fri, 2 Jun 2023 10:11:40 +0000 (UTC) From: Charles Keepax To: CC: , , , , , Subject: [PATCH v2 5/5] soundwire: stream: Remove unnecessary gotos Date: Fri, 2 Jun 2023 11:11:40 +0100 Message-ID: <20230602101140.2040141-5-ckeepax@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230602101140.2040141-1-ckeepax@opensource.cirrus.com> References: <20230602101140.2040141-1-ckeepax@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: uhKsbTLYac5TE4X8JYzcO27_iefRGppW X-Proofpoint-ORIG-GUID: uhKsbTLYac5TE4X8JYzcO27_iefRGppW X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767585981781109294?= X-GMAIL-MSGID: =?utf-8?q?1767585981781109294?= There is a lot of code using gotos to skip small sections of code, this is a fairly dubious use of a goto, especially when the level of intentation is really low. Most of this code doesn't even breach 80 characters when naively shifted over. Simplify the code a bit, by replacing these unnecessary gotos with simple ifs. Signed-off-by: Charles Keepax Reviewed-by: Pierre-Louis Bossart --- Changes since v1: - Split out the inversion of the alloc_*_rt logic Worth noting this patch has no functional corrections it is just a stylistic change, so as Pierre said on v1 we could just leave things as is. Personally, I would prefer to merge it though, whilst the diff is a little more of a pain to review (hopefully eased somewhat by splitting out the alloc_*_rt logic into a separate patch), the resulting code reads much nicer and the code will be read a lot more times than this patch will be. Thanks, Charles drivers/soundwire/stream.c | 124 +++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 68 deletions(-) diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c index df5600a80c174..93baca08a0dea 100644 --- a/drivers/soundwire/stream.c +++ b/drivers/soundwire/stream.c @@ -1355,25 +1355,23 @@ static int _sdw_prepare_stream(struct sdw_stream_runtime *stream, return -EINVAL; } - if (!update_params) - goto program_params; - - /* Increment cumulative bus bandwidth */ - /* TODO: Update this during Device-Device support */ - bus->params.bandwidth += m_rt->stream->params.rate * - m_rt->ch_count * m_rt->stream->params.bps; - - /* Compute params */ - if (bus->compute_params) { - ret = bus->compute_params(bus); - if (ret < 0) { - dev_err(bus->dev, "Compute params failed: %d\n", - ret); - goto restore_params; + if (update_params) { + /* Increment cumulative bus bandwidth */ + /* TODO: Update this during Device-Device support */ + bus->params.bandwidth += m_rt->stream->params.rate * + m_rt->ch_count * m_rt->stream->params.bps; + + /* Compute params */ + if (bus->compute_params) { + ret = bus->compute_params(bus); + if (ret < 0) { + dev_err(bus->dev, "Compute params failed: %d\n", + ret); + goto restore_params; + } } } -program_params: /* Program params */ ret = sdw_program_params(bus, true); if (ret < 0) { @@ -1876,30 +1874,25 @@ int sdw_stream_add_master(struct sdw_bus *bus, * it first), if so skip allocation and go to configuration */ m_rt = sdw_master_rt_find(bus, stream); - if (m_rt) - goto skip_alloc_master_rt; - - m_rt = sdw_master_rt_alloc(bus, stream); if (!m_rt) { - dev_err(bus->dev, "%s: Master runtime alloc failed for stream:%s\n", - __func__, stream->name); - ret = -ENOMEM; - goto unlock; - } - - alloc_master_rt = true; -skip_alloc_master_rt: - - if (sdw_master_port_allocated(m_rt)) - goto skip_alloc_master_port; + m_rt = sdw_master_rt_alloc(bus, stream); + if (!m_rt) { + dev_err(bus->dev, "%s: Master runtime alloc failed for stream:%s\n", + __func__, stream->name); + ret = -ENOMEM; + goto unlock; + } - ret = sdw_master_port_alloc(m_rt, num_ports); - if (ret) - goto alloc_error; + alloc_master_rt = true; + } - stream->m_rt_count++; + if (!sdw_master_port_allocated(m_rt)) { + ret = sdw_master_port_alloc(m_rt, num_ports); + if (ret) + goto alloc_error; -skip_alloc_master_port: + stream->m_rt_count++; + } ret = sdw_master_rt_config(m_rt, stream_config); if (ret < 0) @@ -1992,46 +1985,41 @@ int sdw_stream_add_slave(struct sdw_slave *slave, * and go to configuration */ m_rt = sdw_master_rt_find(slave->bus, stream); - if (m_rt) - goto skip_alloc_master_rt; - - /* - * If this API is invoked by Slave first then m_rt is not valid. - * So, allocate m_rt and add Slave to it. - */ - m_rt = sdw_master_rt_alloc(slave->bus, stream); if (!m_rt) { - dev_err(&slave->dev, "%s: Master runtime alloc failed for stream:%s\n", - __func__, stream->name); - ret = -ENOMEM; - goto unlock; - } + /* + * If this API is invoked by Slave first then m_rt is not valid. + * So, allocate m_rt and add Slave to it. + */ + m_rt = sdw_master_rt_alloc(slave->bus, stream); + if (!m_rt) { + dev_err(&slave->dev, "%s: Master runtime alloc failed for stream:%s\n", + __func__, stream->name); + ret = -ENOMEM; + goto unlock; + } - alloc_master_rt = true; + alloc_master_rt = true; + } -skip_alloc_master_rt: s_rt = sdw_slave_rt_find(slave, stream); - if (s_rt) - goto skip_alloc_slave_rt; - - s_rt = sdw_slave_rt_alloc(slave, m_rt); if (!s_rt) { - dev_err(&slave->dev, "Slave runtime alloc failed for stream:%s\n", stream->name); - ret = -ENOMEM; - goto alloc_error; - } - - alloc_slave_rt = true; + s_rt = sdw_slave_rt_alloc(slave, m_rt); + if (!s_rt) { + dev_err(&slave->dev, "Slave runtime alloc failed for stream:%s\n", + stream->name); + ret = -ENOMEM; + goto alloc_error; + } -skip_alloc_slave_rt: - if (sdw_slave_port_allocated(s_rt)) - goto skip_port_alloc; + alloc_slave_rt = true; + } - ret = sdw_slave_port_alloc(slave, s_rt, num_ports); - if (ret) - goto alloc_error; + if (!sdw_slave_port_allocated(s_rt)) { + ret = sdw_slave_port_alloc(slave, s_rt, num_ports); + if (ret) + goto alloc_error; + } -skip_port_alloc: ret = sdw_master_rt_config(m_rt, stream_config); if (ret) goto unlock;