From patchwork Tue Nov 14 13:33:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hejunhao X-Patchwork-Id: 164900 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1860052vqg; Tue, 14 Nov 2023 05:34:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHq1DVLUyiORRxE1mkgGV4BZokPGouU7k+Fy5l79LMcBbk4JtKyz8mzj1uAZNZiiayTM8fx X-Received: by 2002:a17:902:eb90:b0:1cc:3598:4ba0 with SMTP id q16-20020a170902eb9000b001cc35984ba0mr2368380plg.68.1699968842235; Tue, 14 Nov 2023 05:34:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699968842; cv=none; d=google.com; s=arc-20160816; b=Tds7ClVsIjqBAcFUSACLwYuel5azxGOJ91K+pPY5D6aPnYxFeR+lRE9IS2dVlrIT+s KGeTj2FCjp8EqBIOJGPum17Tip+xbCofHJ3TvTrKF6mVaMLKV5KOGnpoV6gygq1PIFKY z6BFFN7QtPswO2qUBRdjsO0bfWSZ7IZpQMWOF4zJPpNogDbmmkbObINivle4hoOx12lV gAVaYzvHZbtcrWQAU5TbRcqISmZDsu6A7sdCW1E58u+Z8KUHgmUsrjTMlsQXc2jROgT2 ZXNtnbbnjW7xcTsJ1Pwf5dHAMH4Q0Vguse5yrtp1CKPugcsgGewgnyr1LQcU1vio//WQ lUNA== 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; bh=R1+cNJoVUiChig2eq1dQyjEVXpI1mJYN59L39M77hq4=; fh=UHVmWfYpaOpxa5MpZWIHTe5DQ4x7tAMNH9bJWvQ5U9A=; b=Ggi0ew3rm7jQourbwY9nQkeF+lqZEP2vRPFVezJhG+iWYWeqv4SFQmkpgHEUfoEjdP 0x/0x0q2r2x2NMseuJ5WW7WVxel8BzZuPXYjSZxh5xbcCMFsYrrSZIOFOd7oVe9aW1vz 6bPyoMDEMvakV5ZOB5ZYfMn6Pn7Cxxel8g/kcyPo66G7XWEjFoZmBasaTLy3gzKJCl0g l8r5GpSpWp6AU8ss9oWozs69bKkjs9zq4Z5MrI0ZFd75lxELcn2VDg73IMT+oXljc5J3 kfYZxfYBFv5kKlEUpR9B8lJCNEQH7o5d/zNDdDNb/30BAMi0HFmsaePr0B+Mgew99do0 zXJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id g7-20020a170902740700b001cc53d110a6si7815554pll.481.2023.11.14.05.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 05:34:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 16C4780E73C1; Tue, 14 Nov 2023 05:33:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233267AbjKNNdo (ORCPT + 29 others); Tue, 14 Nov 2023 08:33:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbjKNNdl (ORCPT ); Tue, 14 Nov 2023 08:33:41 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AADC1B5 for ; Tue, 14 Nov 2023 05:33:37 -0800 (PST) Received: from dggpeml500002.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4SV6c90R5Qz1P888; Tue, 14 Nov 2023 21:30:17 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpeml500002.china.huawei.com (7.185.36.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 14 Nov 2023 21:33:35 +0800 From: Junhao He To: , CC: , , , , , , , , Subject: [PATCH v3 2/4] coresight: ultrasoc-smb: Config SMB buffer before register sink Date: Tue, 14 Nov 2023 21:33:44 +0800 Message-ID: <20231114133346.30489-3-hejunhao3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231114133346.30489-1-hejunhao3@huawei.com> References: <20231114133346.30489-1-hejunhao3@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500002.china.huawei.com (7.185.36.158) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 14 Nov 2023 05:33:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782546528511825671 X-GMAIL-MSGID: 1782546528511825671 The SMB dirver register the enable/disable sysfs interface in function smb_register_sink(), however the buffer depends on the following configuration to work well. So it'll be possible for user to access an unreset one. Move the config buffer operation to before register_sink(). Ignore the return value, if smb_config_inport() fails. That will cause the hardwares disable trace path to fail, should not affect SMB driver remove. So we make smb_remove() return success, Fixes: 06f5c2926aaa ("drivers/coresight: Add UltraSoc System Memory Buffer driver") Signed-off-by: Junhao He Reviewed-by: James Clark --- drivers/hwtracing/coresight/ultrasoc-smb.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/hwtracing/coresight/ultrasoc-smb.c b/drivers/hwtracing/coresight/ultrasoc-smb.c index 0a0fe9fcc57f..2f2aba90a514 100644 --- a/drivers/hwtracing/coresight/ultrasoc-smb.c +++ b/drivers/hwtracing/coresight/ultrasoc-smb.c @@ -583,37 +583,32 @@ static int smb_probe(struct platform_device *pdev) return ret; } + ret = smb_config_inport(dev, true); + if (ret) + return ret; + + platform_set_drvdata(pdev, drvdata); spin_lock_init(&drvdata->spinlock); drvdata->pid = -1; ret = smb_register_sink(pdev, drvdata); if (ret) { + smb_config_inport(&pdev->dev, false); dev_err(dev, "Failed to register SMB sink\n"); return ret; } - ret = smb_config_inport(dev, true); - if (ret) { - smb_unregister_sink(drvdata); - return ret; - } - - platform_set_drvdata(pdev, drvdata); - return 0; } static int smb_remove(struct platform_device *pdev) { struct smb_drv_data *drvdata = platform_get_drvdata(pdev); - int ret; - - ret = smb_config_inport(&pdev->dev, false); - if (ret) - return ret; smb_unregister_sink(drvdata); + smb_config_inport(&pdev->dev, false); + return 0; } From patchwork Tue Nov 14 13:33:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hejunhao X-Patchwork-Id: 164902 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1860261vqg; Tue, 14 Nov 2023 05:34:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IENfv8fLC5fYR2Hw4E1XoT7F5ShL4D8UENPqiYz0BgPjm5bgmi4ocdRXmTHqnqTQgC6xWNB X-Received: by 2002:a17:902:e88f:b0:1cc:e76d:e7b2 with SMTP id w15-20020a170902e88f00b001cce76de7b2mr2599591plg.22.1699968863340; Tue, 14 Nov 2023 05:34:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699968863; cv=none; d=google.com; s=arc-20160816; b=aW0jFv/4BfFPQanfaVyyfWYqL+tgr6KViDTntfXCtP6SpzWNkabKIaUT6OLMTlo20x +fjb72nHQYSK2Logc55O0GKmjB1WI6PBBlS/bHDt2kVdBnFfEpAi2eT4KMY+dFp3TKHZ g1GwTxKHOCIkOQkKA1vzGGdxupr/miSb31PXFupAmK2ggq8wRZYAoo5u+uM2Shl3oLoH pqqTcXIldjK+w4cZRdtIYfRAMZH3huSVeeyGCtbHDef/ZpLeOuFceH6PPVfxf/nAYCAv EX9BLsy6ZphUVLrWlXCvUyeYDOTFKxSmGf86ysXIQ20y+HxModr7R7+P3beciUJ1eYjB R2Ig== 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; bh=3bYbdl2ypu6dy29DPHfXliEfTolGe6mEDVcTrbOZLBM=; fh=UHVmWfYpaOpxa5MpZWIHTe5DQ4x7tAMNH9bJWvQ5U9A=; b=okBJ6f9O8Ib8SXzMmDW8XDVb3l+WQHiVTilKUMAl3mr7Z8O8pRckMseNzsJ06pVxgC sKj6QP2mIs6+4BvgjPOybKIBw6qoW+jEJrbubFd/OBW+iAjLAWBlz0VPhlO6LUsnQjRW dy2ReMNgwdR6YEJza2AWa5B8baeYHEqLAeUKoRd8HFSCK14URCT3ktY23cq5dbPxB8AF Bzisna4u8ODTiPvGFJgo8Dn2IpoQdKiWT4r56e35bEgBUm5GE9L8oVy2ZhHAzqU3aB6S gDbYDO80+HN552z2RoLnF84eTgZHv6MNw9zPUSUWrG5xmn0xIWQ/8vXu3kMDI2B8yIeL ykZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id u11-20020a170903124b00b001ce2fc160f9si3057270plh.424.2023.11.14.05.34.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 05:34:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B5BAF80407F4; Tue, 14 Nov 2023 05:34:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233296AbjKNNdt (ORCPT + 29 others); Tue, 14 Nov 2023 08:33:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233256AbjKNNdm (ORCPT ); Tue, 14 Nov 2023 08:33:42 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EA001BC for ; Tue, 14 Nov 2023 05:33:37 -0800 (PST) Received: from dggpeml500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV6b74kgmzPpHw; Tue, 14 Nov 2023 21:29:23 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpeml500002.china.huawei.com (7.185.36.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 14 Nov 2023 21:33:35 +0800 From: Junhao He To: , CC: , , , , , , , , Subject: [PATCH v3 3/4] coresight: ultrasoc-smb: Fix uninitialized before use buf_hw_base Date: Tue, 14 Nov 2023 21:33:45 +0800 Message-ID: <20231114133346.30489-4-hejunhao3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231114133346.30489-1-hejunhao3@huawei.com> References: <20231114133346.30489-1-hejunhao3@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500002.china.huawei.com (7.185.36.158) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 14 Nov 2023 05:34:10 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782546551239421150 X-GMAIL-MSGID: 1782546551239421150 In smb_reset_buffer, the sdb->buf_hw_base variable is uninitialized before use, which initializes it in smb_init_data_buffer. And the SMB regiester are set in smb_config_inport. So move the call after smb_config_inport. Fixes: 06f5c2926aaa ("drivers/coresight: Add UltraSoc System Memory Buffer driver") Signed-off-by: Junhao He Reviewed-by: James Clark --- drivers/hwtracing/coresight/ultrasoc-smb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/ultrasoc-smb.c b/drivers/hwtracing/coresight/ultrasoc-smb.c index 2f2aba90a514..6e32d31a95fe 100644 --- a/drivers/hwtracing/coresight/ultrasoc-smb.c +++ b/drivers/hwtracing/coresight/ultrasoc-smb.c @@ -477,7 +477,6 @@ static int smb_init_data_buffer(struct platform_device *pdev, static void smb_init_hw(struct smb_drv_data *drvdata) { smb_disable_hw(drvdata); - smb_reset_buffer(drvdata); writel(SMB_LB_CFG_LO_DEFAULT, drvdata->base + SMB_LB_CFG_LO_REG); writel(SMB_LB_CFG_HI_DEFAULT, drvdata->base + SMB_LB_CFG_HI_REG); @@ -587,6 +586,7 @@ static int smb_probe(struct platform_device *pdev) if (ret) return ret; + smb_reset_buffer(drvdata); platform_set_drvdata(pdev, drvdata); spin_lock_init(&drvdata->spinlock); drvdata->pid = -1; From patchwork Tue Nov 14 13:33:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hejunhao X-Patchwork-Id: 164901 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1860058vqg; Tue, 14 Nov 2023 05:34:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6dClv0ScN3bJh6qH7o/n1q6DtsIhf1sf9ecMk3T3fFXhdf6qswt4lVC+zcvZHUauDMQmI X-Received: by 2002:a17:902:6bc6:b0:1cc:6fdb:b640 with SMTP id m6-20020a1709026bc600b001cc6fdbb640mr2199785plt.56.1699968842878; Tue, 14 Nov 2023 05:34:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699968842; cv=none; d=google.com; s=arc-20160816; b=dL6fE+VPdZ038sgnYWE6nFM11KknzKhL9rIyWvo07lyRMUzYG9oDMwOJXK/5iOfdUs GzpR3dJr+Z184KuSlS+8hwnhTg/Wb9Iw6eIZKpAUjLOPNCzpqET/8YLxE2bSz5OLX0w2 bXndyoEnHT5ojYf1SJHks3tHtzaXAdkx5U4i2CEjf81e54fW+jnzwTxc04/tIuD96zFd anEV3QupnO3SG5RiYIqB/DLJB61qbXByM0Q9m1o3qOnFMEWtbWrpHpDn7BuETyVje0jP dJQle7Yx/Whx6G7DFheK1jr1+0smqwpKlFuXGjjIXzu9Rrb7KfgUgWrBIzMWCXP5YOKt 6owA== 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; bh=88In9CO2yB2UB2bksIk5W96VZEmfrV52VVwZpcb9OG8=; fh=UHVmWfYpaOpxa5MpZWIHTe5DQ4x7tAMNH9bJWvQ5U9A=; b=v64AU438gfRT0a+V72r9RaRtBRk7a+wfeWiEZODodXY6ivPVfriNQBmsHkWefydEvU a8Fv0Ifac3vzWqzW0oT1B7oUtLdpWKOgDsocPdLK6TsDAma2ogTnhVlOP9EHuafLbQmQ 7krsD4eMxA5Oa89Xv0MH1yYWCmrNwXsF1mVnF2W3ZY9qmKTpV5OIeis4+iz4vChaku6R MXNSyWGcb59mw9ng1M5FjcFuAA3buBgaScgT0Ew8eEuXSnLcHCV6ObUJEVFnsCPxLw6m BPFlw/jCHF2+Mx9Xiak+wFS/00xedUOpXpMpyGLzcNG5cm72+unoMNxMqHk4jai5eDzF OmdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id g4-20020a170902934400b001c754e83e06si7554732plp.164.2023.11.14.05.33.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 05:34:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7F65F80E73DA; Tue, 14 Nov 2023 05:33:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233277AbjKNNdp (ORCPT + 29 others); Tue, 14 Nov 2023 08:33:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233225AbjKNNdm (ORCPT ); Tue, 14 Nov 2023 08:33:42 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A99921BE for ; Tue, 14 Nov 2023 05:33:37 -0800 (PST) Received: from dggpeml500002.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SV6gZ1VG7zWh5x; Tue, 14 Nov 2023 21:33:14 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpeml500002.china.huawei.com (7.185.36.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 14 Nov 2023 21:33:35 +0800 From: Junhao He To: , CC: , , , , , , , , Subject: [PATCH v3 4/4] coresight: ultrasoc-smb: Use guards to cleanup Date: Tue, 14 Nov 2023 21:33:46 +0800 Message-ID: <20231114133346.30489-5-hejunhao3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231114133346.30489-1-hejunhao3@huawei.com> References: <20231114133346.30489-1-hejunhao3@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500002.china.huawei.com (7.185.36.158) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 14 Nov 2023 05:33:50 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782546529663352534 X-GMAIL-MSGID: 1782546529663352534 Use guards to reduce gotos and simplify control flow. Signed-off-by: Junhao He 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; }