From nobody Fri Dec 19 20:22:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA80DCDB46E for ; Thu, 12 Oct 2023 09:46:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235617AbjJLJqk (ORCPT ); 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 Content-Transfer-Encoding: quoted-printable 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 __use= r *data, size_t len, struct smb_drv_data, miscdev); struct smb_data_buffer *sdb =3D &drvdata->sdb; struct device *dev =3D &drvdata->csdev->dev; - ssize_t to_copy =3D 0; - - if (!len) - return 0; - - if (!sdb->data_size) - return 0; - - to_copy =3D min(sdb->data_size, len); + ssize_t to_copy =3D min(sdb->data_size, len); =20 /* Copy parts of trace data when read pointer wrap around SMB buffer */ if (sdb->buf_rdptr + to_copy > sdb->buf_size) to_copy =3D sdb->buf_size - sdb->buf_rdptr; =20 + 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; --=20 2.33.0