From patchwork Thu Oct 12 09:47:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hejunhao X-Patchwork-Id: 151877 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1100503vqb; Thu, 12 Oct 2023 02:46:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7r8nwubC1g5Tvjw7vY1GChvrY88HnsF3bmvlcMXs+9HGIN08/VC90estsElmjlgKSJYDq X-Received: by 2002:a05:6358:9f93:b0:149:7198:bd46 with SMTP id fy19-20020a0563589f9300b001497198bd46mr16203059rwb.1.1697104018421; Thu, 12 Oct 2023 02:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697104018; cv=none; d=google.com; s=arc-20160816; b=d2JW+zp08KDv5V514uxCnkRIDxa9ywPA28+CD88ix+6SDG2vjjKPvrBbwwG0q91o7e XJhNu+cI/7s08spmGh6G0yytumHZ6522yB2evc5jpJ/sq8lLEf4c5y2tBBq0Qnwg1NBz bixiYbbhQyAHKu/Z8IEm391n8zSCpI55C7NU4166HAmVX94lliZZXzFkgYbsqyEYa8MH lCSWDLv+WRNFRZB6XHbEGp//hPoC/gKljd2dMB6iyBKL5GemCewN1cfL7VEu0/94yq5x Hpx1p+4k0CzODItLLPsFXMCLf9jVyjqiZXN+HVdLP1VdUZpktjMMLb7VUmfY6kQj6wbi 5bJQ== 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=AHdk5XSvkLk4DmX1kzSnltdydhZ1OxwBucFrtWCU0NE=; fh=DAAgJLf4s0smpgJqxZKr7c0el7KScJ0FbfhkC9eFTa4=; b=v4NKdWkKE0TAt486r1UQvAJlabwzU+K4H50VTml+676K1LckK8JHkoBFD79X9vROXT dQJwNp98l5YOgEbTPvcxcE5bCD018Ci4MxMixkrYiEr5UuGgjJkD+3lERj6YovCtJoC2 0KcF9ggq5uBh9zmVrkzmI3IdH6Fkp6pdrgN8CQDS/3CuSf0rlU48fe1e0h+OqhVtOBJO 65dnTv7spYCD0iubQZqmxPxHvYD9Z4pY4NzuZuA9tFTn8B+729H1m2XuWYthK1lc1dDF 0n0e7KZrbyb0ikRhXLmyFNywY4cIATooZppT3bAhniFJYPOvewF1nTnDjRS1ADTeb3xT UZGA== 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:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id bx9-20020a056a00428900b006933e7dcb09si13859638pfb.87.2023.10.12.02.46.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 02:46:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 348118386B6B; Thu, 12 Oct 2023 02:46:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235599AbjJLJqg (ORCPT + 19 others); Thu, 12 Oct 2023 05:46:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbjJLJqe (ORCPT ); Thu, 12 Oct 2023 05:46:34 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A11ED9D for ; Thu, 12 Oct 2023 02:46:32 -0700 (PDT) Received: from dggpeml500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S5l774bjgzVlYB; Thu, 12 Oct 2023 17:42:59 +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; Thu, 12 Oct 2023 17:46:30 +0800 From: Junhao He To: , CC: , , , , , , , Subject: [PATCH 1/3] coresight: ultrasoc-smb: fix sleep while close preempt in enable_smb Date: Thu, 12 Oct 2023 17:47:04 +0800 Message-ID: <20231012094706.21565-2-hejunhao3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231012094706.21565-1-hejunhao3@huawei.com> References: <20231012094706.21565-1-hejunhao3@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Thu, 12 Oct 2023 02:46:53 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779542543120756123 X-GMAIL-MSGID: 1779542543120756123 When we to enable the SMB by perf, the perf sched will call perf_ctx_lock() to close system preempt in event_function_call(). But SMB::enable_smb() use mutex to lock the critical section, which may sleep. BUG: sleeping function called from invalid context at kernel/locking/mutex.c:580 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 153023, name: perf preempt_count: 2, expected: 0 RCU nest depth: 0, expected: 0 INFO: lockdep is turned off. irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [] copy_process+0xae8/0x2b48 softirqs last enabled at (0): [] copy_process+0xae8/0x2b48 softirqs last disabled at (0): [<0000000000000000>] 0x0 CPU: 2 PID: 153023 Comm: perf Kdump: loaded Tainted: G W O 6.5.0-rc4+ #1 Call trace: ... __mutex_lock+0xbc/0xa70 mutex_lock_nested+0x34/0x48 smb_update_buffer+0x58/0x360 [ultrasoc_smb] etm_event_stop+0x204/0x2d8 [coresight] etm_event_del+0x1c/0x30 [coresight] event_sched_out+0x17c/0x3b8 group_sched_out.part.0+0x5c/0x208 __perf_event_disable+0x15c/0x210 event_function+0xe0/0x230 remote_function+0xb4/0xe8 generic_exec_single+0x160/0x268 smp_call_function_single+0x20c/0x2a0 event_function_call+0x20c/0x220 _perf_event_disable+0x5c/0x90 perf_event_for_each_child+0x58/0xc0 _perf_ioctl+0x34c/0x1250 perf_ioctl+0x64/0x98 ... Use spinlock replace mutex to control driver data access to one at a time. But the function copy_to_user() may sleep so spinlock do not to lock it. Fixes: 06f5c2926aaa ("drivers/coresight: Add UltraSoc System Memory Buffer driver") Signed-off-by: Junhao He --- drivers/hwtracing/coresight/ultrasoc-smb.c | 36 ++++++++++------------ drivers/hwtracing/coresight/ultrasoc-smb.h | 6 ++-- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/drivers/hwtracing/coresight/ultrasoc-smb.c b/drivers/hwtracing/coresight/ultrasoc-smb.c index e9a32a97fbee..b08a619d1116 100644 --- a/drivers/hwtracing/coresight/ultrasoc-smb.c +++ b/drivers/hwtracing/coresight/ultrasoc-smb.c @@ -99,7 +99,7 @@ static int smb_open(struct inode *inode, struct file *file) struct smb_drv_data, miscdev); int ret = 0; - mutex_lock(&drvdata->mutex); + spin_lock(&drvdata->spinlock); if (drvdata->reading) { ret = -EBUSY; @@ -115,7 +115,7 @@ static int smb_open(struct inode *inode, struct file *file) drvdata->reading = true; out: - mutex_unlock(&drvdata->mutex); + spin_unlock(&drvdata->spinlock); return ret; } @@ -132,10 +132,8 @@ static ssize_t smb_read(struct file *file, char __user *data, size_t len, if (!len) return 0; - mutex_lock(&drvdata->mutex); - if (!sdb->data_size) - goto out; + return 0; to_copy = min(sdb->data_size, len); @@ -145,20 +143,18 @@ static ssize_t smb_read(struct file *file, char __user *data, size_t len, if (copy_to_user(data, sdb->buf_base + sdb->buf_rdptr, to_copy)) { dev_dbg(dev, "Failed to copy data to user\n"); - to_copy = -EFAULT; - goto out; + return -EFAULT; } + spin_lock(&drvdata->spinlock); *ppos += to_copy; - smb_update_read_ptr(drvdata, to_copy); - dev_dbg(dev, "%zu bytes copied\n", to_copy); -out: if (!sdb->data_size) smb_reset_buffer(drvdata); - mutex_unlock(&drvdata->mutex); + spin_unlock(&drvdata->spinlock); + dev_dbg(dev, "%zu bytes copied\n", to_copy); return to_copy; } @@ -167,9 +163,9 @@ 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); - mutex_lock(&drvdata->mutex); + spin_lock(&drvdata->spinlock); drvdata->reading = false; - mutex_unlock(&drvdata->mutex); + spin_unlock(&drvdata->spinlock); return 0; } @@ -262,7 +258,7 @@ 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; - mutex_lock(&drvdata->mutex); + spin_lock(&drvdata->spinlock); /* Do nothing, the trace data is reading by other interface now */ if (drvdata->reading) { @@ -294,7 +290,7 @@ static int smb_enable(struct coresight_device *csdev, enum cs_mode mode, dev_dbg(&csdev->dev, "Ultrasoc SMB enabled\n"); out: - mutex_unlock(&drvdata->mutex); + spin_unlock(&drvdata->spinlock); return ret; } @@ -304,7 +300,7 @@ static int smb_disable(struct coresight_device *csdev) struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent); int ret = 0; - mutex_lock(&drvdata->mutex); + spin_lock(&drvdata->spinlock); if (drvdata->reading) { ret = -EBUSY; @@ -327,7 +323,7 @@ static int smb_disable(struct coresight_device *csdev) dev_dbg(&csdev->dev, "Ultrasoc SMB disabled\n"); out: - mutex_unlock(&drvdata->mutex); + spin_unlock(&drvdata->spinlock); return ret; } @@ -408,7 +404,7 @@ static unsigned long smb_update_buffer(struct coresight_device *csdev, if (!buf) return 0; - mutex_lock(&drvdata->mutex); + spin_lock(&drvdata->spinlock); /* Don't do anything if another tracer is using this sink. */ if (atomic_read(&csdev->refcnt) != 1) @@ -432,7 +428,7 @@ static unsigned long smb_update_buffer(struct coresight_device *csdev, if (!buf->snapshot && lost) perf_aux_output_flag(handle, PERF_AUX_FLAG_TRUNCATED); out: - mutex_unlock(&drvdata->mutex); + spin_unlock(&drvdata->spinlock); return data_size; } @@ -590,7 +586,7 @@ static int smb_probe(struct platform_device *pdev) return ret; } - mutex_init(&drvdata->mutex); + spin_lock_init(&drvdata->spinlock); drvdata->pid = -1; ret = smb_register_sink(pdev, drvdata); diff --git a/drivers/hwtracing/coresight/ultrasoc-smb.h b/drivers/hwtracing/coresight/ultrasoc-smb.h index d2e14e8d2c8a..82a44c14a882 100644 --- a/drivers/hwtracing/coresight/ultrasoc-smb.h +++ b/drivers/hwtracing/coresight/ultrasoc-smb.h @@ -8,7 +8,7 @@ #define _ULTRASOC_SMB_H #include -#include +#include /* Offset of SMB global registers */ #define SMB_GLB_CFG_REG 0x00 @@ -105,7 +105,7 @@ struct smb_data_buffer { * @csdev: Component vitals needed by the framework. * @sdb: Data buffer for SMB. * @miscdev: Specifics to handle "/dev/xyz.smb" entry. - * @mutex: Control data access to one at a time. + * @spinlock: Control data access to one at a time. * @reading: Synchronise user space access to SMB buffer. * @pid: Process ID of the process being monitored by the * session that is using this component. @@ -116,7 +116,7 @@ struct smb_drv_data { struct coresight_device *csdev; struct smb_data_buffer sdb; struct miscdevice miscdev; - struct mutex mutex; + spinlock_t spinlock; bool reading; pid_t pid; enum cs_mode mode; From patchwork Thu Oct 12 09:47:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hejunhao X-Patchwork-Id: 151879 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1100935vqb; Thu, 12 Oct 2023 02:48:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZEaqVAPBnRSMnmnJgRKEI7KxQGVKY2G++/D5/p474zXFxD0/V5GPMkmLF6uHrGrM6xGmO X-Received: by 2002:a05:6602:368c:b0:792:7c78:55be with SMTP id bf12-20020a056602368c00b007927c7855bemr23154825iob.0.1697104083573; Thu, 12 Oct 2023 02:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697104083; cv=none; d=google.com; s=arc-20160816; b=FvI5n4N14bj1yAOy3musSqcdPsNHDdFhK2nKfWPn96oYpZlZoQv0aVQg+V3ppPiZMC loMplOSKcjdO7W0R+gLB0yQ5gRRjuIqYcTxINcpmzYxdtQA3o647PrCzvHGLE4wUQaN9 c/VB3CuOn7PNoXZZ5OT1TH+08R4RC+3aM1k8L6C0DbBRU7/9ueGD8f6TZF619b2CAhj7 W7L6zhT2DoSTh340EATqGeElrC0sVJrzlhyZtn+GiCxJ19dK1T8IhlEe+/LwEsMCxahq nLZOG4jsUotpi1+IVJouEshi4TC0KjbchkBJinMOJY5qNF4zvYZ9I47AgSsFJBh5eDUO Y0Lg== 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=cv0L0M3BwIJ5+zzhg4R3sMbJzkjA6FGJpSrOnhVS8yg=; fh=DAAgJLf4s0smpgJqxZKr7c0el7KScJ0FbfhkC9eFTa4=; b=iJfZ8Cuz+A83b6LmtvXNLJvmtGuY+QwKaKh8E+F8KHJ9A98+9DibPw1X1wFVn3zU2a xeYljxiN49PgwVqkf8Ox6P/QXMrk7j51FM1ejZH/V2PIqQEVytdk8n6ZIfYE9VXNzL9f HTQ/dcIiIJabPYDZF3KH6hgGOBsoQBQVPYqpAs/nAroVYP+9i9MUR3/xEpTsvdyNg6/m U+7jSoMUk/2gkPoWjKKmzk5nVB8CKInw6ZW8ozg/7aKz0hTpS7cIRs/xH3evIMZDiugh 9aHzyrgZZnxVVnZwSmKLhzETTUi+RLAVrIKM2Oa/HNJuXeYfLYaKv0dU1MoNWyQWNZWi dmQA== 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 k15-20020a056a00134f00b0068e4704fd5bsi14901357pfu.346.2023.10.12.02.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 02:48:03 -0700 (PDT) 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 816B380527CC; Thu, 12 Oct 2023 02:46:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235614AbjJLJqk (ORCPT + 19 others); Thu, 12 Oct 2023 05:46:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234030AbjJLJqf (ORCPT ); Thu, 12 Oct 2023 05:46:35 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ED5BA9 for ; Thu, 12 Oct 2023 02:46:32 -0700 (PDT) Received: from dggpeml500002.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4S5l8C3V6PzrT8v; Thu, 12 Oct 2023 17:43:55 +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; Thu, 12 Oct 2023 17:46:30 +0800 From: Junhao He To: , CC: , , , , , , , Subject: [PATCH 2/3] coresight: ultrasoc-smb: simplify the code for check to_copy valid Date: Thu, 12 Oct 2023 17:47:05 +0800 Message-ID: <20231012094706.21565-3-hejunhao3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231012094706.21565-1-hejunhao3@huawei.com> References: <20231012094706.21565-1-hejunhao3@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 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]); Thu, 12 Oct 2023 02:46:51 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779542611848392635 X-GMAIL-MSGID: 1779542611848392635 We only need to check once when before using the to_copy variable to simplify the code. Signed-off-by: Junhao He --- drivers/hwtracing/coresight/ultrasoc-smb.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/hwtracing/coresight/ultrasoc-smb.c b/drivers/hwtracing/coresight/ultrasoc-smb.c index b08a619d1116..e78edc3480ce 100644 --- a/drivers/hwtracing/coresight/ultrasoc-smb.c +++ b/drivers/hwtracing/coresight/ultrasoc-smb.c @@ -127,20 +127,15 @@ static ssize_t smb_read(struct file *file, char __user *data, size_t len, struct smb_drv_data, miscdev); struct smb_data_buffer *sdb = &drvdata->sdb; struct device *dev = &drvdata->csdev->dev; - ssize_t to_copy = 0; - - if (!len) - return 0; - - if (!sdb->data_size) - return 0; - - to_copy = min(sdb->data_size, len); + ssize_t to_copy = min(sdb->data_size, len); /* Copy parts of trace data when read pointer wrap around SMB buffer */ if (sdb->buf_rdptr + to_copy > sdb->buf_size) to_copy = sdb->buf_size - sdb->buf_rdptr; + if (!to_copy) + return 0; + if (copy_to_user(data, sdb->buf_base + sdb->buf_rdptr, to_copy)) { dev_dbg(dev, "Failed to copy data to user\n"); return -EFAULT; From patchwork Thu Oct 12 09:47:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hejunhao X-Patchwork-Id: 151878 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1100749vqb; Thu, 12 Oct 2023 02:47:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJWrA5S0bMGfFxFj0UeK5eNROZ3TVB5dDGvgLB/VHdopPXW/X2uFmoQVpRcVsA8akpDt0x X-Received: by 2002:a17:902:d352:b0:1c9:e121:ccc1 with SMTP id l18-20020a170902d35200b001c9e121ccc1mr980691plk.5.1697104053979; Thu, 12 Oct 2023 02:47:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697104053; cv=none; d=google.com; s=arc-20160816; b=07mEODpYuGY9aXgagDHjiOWgB4gztu8xj4m9XlND8ZeHwiJ1jAMymWG8EIjjVwU3h6 kZQffZOfeVhoHG8DPouEkxbULKem4PKbDiUy23L7F4uHb++vZM6i0B2DfI8M6e4Q0p5i jz5AXJqpLY39/ENw45IcOYn2WAQyXlFY5k7PFIK2SX/BYzCgmt2OfjSmYdv9mXxfJOvk nK18xmpT+UXrrxpPJugWx8bF18/BELx6XZ0jsG+eSEpk9Xek/J5ScNK46UERKEEWjJH/ HrPz2q11fLhWRywFgojUDLt2y9QsHhq3ksy+VofjOzPvawge73+KGscWdx+zpTgwAsEk /MtQ== 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=ocaHFnXAh/dmVxSx/kePtDLMZoKFskKVe8OeuUuXhtQ=; fh=DAAgJLf4s0smpgJqxZKr7c0el7KScJ0FbfhkC9eFTa4=; b=MBbhIQVsah/LV+9EJmcA1uj6cVEFpAoaBWkI9zGu5jngSohAaStI14PTbpubOslG7u oU1nAVSKbZUd5xJGwGA/7tL94LEteLlRhYEsOpu/welmX98NeLIGvJIrfQITX3Q/Je2R +mg7YhwVUW0VIfaLwzvb9eIhYOHYyr89GTlZjtGxVdz6Hr19mxoiMc4r/4T7Hco0gzY6 vdxQUkzDAlHTDpo3QTEOEFEKupctuVMAsuNoUf0PPBt81eZqJM57gWpq8jy5UR4MCDEq 6eIl3c/BCScZxdICfkmYHYZTuRZA5AfmDHnItB9vRHTWjG6L2exptDTni4+VwAI+iSMA Y2qw== 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:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id 19-20020a170902ee5300b001bbb175a81asi1751943plo.263.2023.10.12.02.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 02:47:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id CE35B80310CE; Thu, 12 Oct 2023 02:47:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235630AbjJLJqo (ORCPT + 19 others); Thu, 12 Oct 2023 05:46:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232594AbjJLJqf (ORCPT ); Thu, 12 Oct 2023 05:46:35 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EF56B7 for ; Thu, 12 Oct 2023 02:46:32 -0700 (PDT) Received: from dggpeml500002.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4S5l6c23QYz1kv1T; Thu, 12 Oct 2023 17:42:32 +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; Thu, 12 Oct 2023 17:46:31 +0800 From: Junhao He To: , CC: , , , , , , , Subject: [PATCH 3/3] coresight: ultrasoc-smb: fix uninitialized before use buf_hw_base Date: Thu, 12 Oct 2023 17:47:06 +0800 Message-ID: <20231012094706.21565-4-hejunhao3@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231012094706.21565-1-hejunhao3@huawei.com> References: <20231012094706.21565-1-hejunhao3@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 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]); Thu, 12 Oct 2023 02:47:12 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779542580300109804 X-GMAIL-MSGID: 1779542580300109804 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 --- 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 e78edc3480ce..21ba473786e5 100644 --- a/drivers/hwtracing/coresight/ultrasoc-smb.c +++ b/drivers/hwtracing/coresight/ultrasoc-smb.c @@ -475,7 +475,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); @@ -597,6 +596,7 @@ static int smb_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, drvdata); + smb_reset_buffer(drvdata); return 0; }