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;