Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2726499rdb; Wed, 15 Nov 2023 08:51:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBnzQ6jUxSXBmfDosrsFvoxAoF8ig5sbllO73T/QdOyg1/dxaJvtXiK6UsaXIIdpB2B0YB X-Received: by 2002:a17:903:22cd:b0:1cc:1e00:f8af with SMTP id y13-20020a17090322cd00b001cc1e00f8afmr6902009plg.37.1700067105586; Wed, 15 Nov 2023 08:51:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700067105; cv=none; d=google.com; s=arc-20160816; b=KgP2EjzP2IxbBCl34qC3qz4W10LuSQUijKzJE6tsTuLpAdFhYFG2zOfwCyYUjKvR8+ DGiVDSb4L6IDtCwLiXz1lQNXY1kUlRkoO3oWw6y/XsO17XguVGVWwNcpY7nfo6ez+SEB gvWVR+KaL/DITvAV8xQEGjvD1jwQYm1iD6WUrPjJeVIX/9kk4yaGjMAj0EXTWE6ZsJmU VV1a2psQhB3KF2bGVUREdNx8tudv3f3gEi8+YfhwpgU921M9R1gskmAUfCiaFYQOYRPz fqRat1LWuRmTz4AfOMJlOMee3M6GuRj7MM2irSygZ+UeoRYFi0vCYCgVcJcXwvj8bFSt 0d4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=ErTquk5EEpiHBL4eMUfyfAV5LhE87H6N7OGdN6FXubU=; fh=dpSTCl+cmlocRsa2Bg6qC0+utd0H5QF9xg9r6tvDcA0=; b=ImvP05POLAdGRXr6PJj45Pes1GLyFG1FOKQQHzKS8wHUXNCs+kSWwZBH+gYC/CP6hR q/o1Fg9nMaWHCuSoYdBdQLaHlbA4QhQyWRc79JYm1cGhBLcU4LiTlB/OSyBtl3LB8NzF y5KL4G6uP/I7BwPS62poWX2rC9YKOMj+pMJ+5wLwREZ/zv91wV71haFaX1071G6wHkZP SuF44QEN8189RgKZr7AzRVutmvHHa18jqVFHAf/SiBMtxzTIGA4O5f4fL/0hjlK9O7ii ZqIRVm7SeGnDZW/1igwPlGgZ4fHMOrNNTeqDWC4WM1cDIzXBTRcnBL6fCQESyPAI8htf K4Sw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id w184-20020a6382c1000000b005b8ebb6d6d7si9882557pgd.117.2023.11.15.08.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 08:51:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id F32578077F9D; Wed, 15 Nov 2023 08:51:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232296AbjKOQvh (ORCPT + 99 others); Wed, 15 Nov 2023 11:51:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231938AbjKOQvf (ORCPT ); Wed, 15 Nov 2023 11:51:35 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 95880196 for ; Wed, 15 Nov 2023 08:51:32 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D6F2ADA7; Wed, 15 Nov 2023 08:52:17 -0800 (PST) Received: from [192.168.1.3] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E91BF3F641; Wed, 15 Nov 2023 08:51:30 -0800 (PST) Message-ID: Date: Wed, 15 Nov 2023 16:51:29 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v3 4/4] coresight: ultrasoc-smb: Use guards to cleanup Content-Language: en-US To: Junhao He , suzuki.poulose@arm.com Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxarm@huawei.com, jonathan.cameron@huawei.com, yangyicong@huawei.com, prime.zeng@hisilicon.com, u.kleine-koenig@pengutronix.de References: <20231114133346.30489-1-hejunhao3@huawei.com> <20231114133346.30489-5-hejunhao3@huawei.com> From: James Clark In-Reply-To: <20231114133346.30489-5-hejunhao3@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 15 Nov 2023 08:51:43 -0800 (PST) On 14/11/2023 13:33, Junhao He wrote: > Use guards to reduce gotos and simplify control flow. > > Signed-off-by: Junhao He Nice cleanup! Reviewed-by: James Clark > --- > drivers/hwtracing/coresight/ultrasoc-smb.c | 70 +++++++--------------- > 1 file changed, 22 insertions(+), 48 deletions(-) > > diff --git a/drivers/hwtracing/coresight/ultrasoc-smb.c b/drivers/hwtracing/coresight/ultrasoc-smb.c > index 6e32d31a95fe..cd14b2eded4e 100644 > --- a/drivers/hwtracing/coresight/ultrasoc-smb.c > +++ b/drivers/hwtracing/coresight/ultrasoc-smb.c > @@ -97,27 +97,19 @@ static int smb_open(struct inode *inode, struct file *file) > { > struct smb_drv_data *drvdata = container_of(file->private_data, > struct smb_drv_data, miscdev); > - int ret = 0; > > - spin_lock(&drvdata->spinlock); > + guard(spinlock)(&drvdata->spinlock); > > - if (drvdata->reading) { > - ret = -EBUSY; > - goto out; > - } > + if (drvdata->reading) > + return -EBUSY; > > - if (atomic_read(&drvdata->csdev->refcnt)) { > - ret = -EBUSY; > - goto out; > - } > + if (atomic_read(&drvdata->csdev->refcnt)) > + return -EBUSY; > > smb_update_data_size(drvdata); > - > drvdata->reading = true; > -out: > - spin_unlock(&drvdata->spinlock); > > - return ret; > + return 0; > } > > static ssize_t smb_read(struct file *file, char __user *data, size_t len, > @@ -160,9 +152,8 @@ static int smb_release(struct inode *inode, struct file *file) > struct smb_drv_data *drvdata = container_of(file->private_data, > struct smb_drv_data, miscdev); > > - spin_lock(&drvdata->spinlock); > + guard(spinlock)(&drvdata->spinlock); > drvdata->reading = false; > - spin_unlock(&drvdata->spinlock); > > return 0; > } > @@ -255,19 +246,15 @@ static int smb_enable(struct coresight_device *csdev, enum cs_mode mode, > struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent); > int ret = 0; > > - spin_lock(&drvdata->spinlock); > + guard(spinlock)(&drvdata->spinlock); > > /* Do nothing, the trace data is reading by other interface now */ > - if (drvdata->reading) { > - ret = -EBUSY; > - goto out; > - } > + if (drvdata->reading) > + return -EBUSY; > > /* Do nothing, the SMB is already enabled as other mode */ > - if (drvdata->mode != CS_MODE_DISABLED && drvdata->mode != mode) { > - ret = -EBUSY; > - goto out; > - } > + if (drvdata->mode != CS_MODE_DISABLED && drvdata->mode != mode) > + return -EBUSY; > > switch (mode) { > case CS_MODE_SYSFS: > @@ -281,13 +268,10 @@ static int smb_enable(struct coresight_device *csdev, enum cs_mode mode, > } > > if (ret) > - goto out; > + return ret; > > atomic_inc(&csdev->refcnt); > - > dev_dbg(&csdev->dev, "Ultrasoc SMB enabled\n"); > -out: > - spin_unlock(&drvdata->spinlock); > > return ret; > } > @@ -295,19 +279,14 @@ static int smb_enable(struct coresight_device *csdev, enum cs_mode mode, > static int smb_disable(struct coresight_device *csdev) > { > struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent); > - int ret = 0; > > - spin_lock(&drvdata->spinlock); > + guard(spinlock)(&drvdata->spinlock); > > - if (drvdata->reading) { > - ret = -EBUSY; > - goto out; > - } > + if (drvdata->reading) > + return -EBUSY; > > - if (atomic_dec_return(&csdev->refcnt)) { > - ret = -EBUSY; > - goto out; > - } > + if (atomic_dec_return(&csdev->refcnt)) > + return -EBUSY; > > /* Complain if we (somehow) got out of sync */ > WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED); > @@ -317,12 +296,9 @@ static int smb_disable(struct coresight_device *csdev) > /* Dissociate from the target process. */ > drvdata->pid = -1; > drvdata->mode = CS_MODE_DISABLED; > - > dev_dbg(&csdev->dev, "Ultrasoc SMB disabled\n"); > -out: > - spin_unlock(&drvdata->spinlock); > > - return ret; > + return 0; > } > > static void *smb_alloc_buffer(struct coresight_device *csdev, > @@ -395,17 +371,17 @@ static unsigned long smb_update_buffer(struct coresight_device *csdev, > struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent); > struct smb_data_buffer *sdb = &drvdata->sdb; > struct cs_buffers *buf = sink_config; > - unsigned long data_size = 0; > + unsigned long data_size; > bool lost = false; > > if (!buf) > return 0; > > - spin_lock(&drvdata->spinlock); > + guard(spinlock)(&drvdata->spinlock); > > /* Don't do anything if another tracer is using this sink. */ > if (atomic_read(&csdev->refcnt) != 1) > - goto out; > + return 0; > > smb_disable_hw(drvdata); > smb_update_data_size(drvdata); > @@ -424,8 +400,6 @@ static unsigned long smb_update_buffer(struct coresight_device *csdev, > smb_sync_perf_buffer(drvdata, buf, handle->head); > if (!buf->snapshot && lost) > perf_aux_output_flag(handle, PERF_AUX_FLAG_TRUNCATED); > -out: > - spin_unlock(&drvdata->spinlock); > > return data_size; > }