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: Junhao He X-Patchwork-Id: 13418726 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C2B38CDB46E for ; Thu, 12 Oct 2023 09:47:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JQ3lzbaOu/hkGOyeOh14chg9Ha+n+XFfNIPQbPEdDAQ=; b=4ephnlzriOWUGb 0O8Imr51uv13u1Aexr6I3fvzswkOKh5YQsQJoUsHy87n4AQhzOXv0YHTjoLm5ObdTB1uJh2zol/S3 /uxH/AI7PnsuEDSGoMMNz1/uV6RJhweoTSjNK+aqBzd3pQqOWj5u1IvxflLN30cbMBQOUGDnICV/D uFDrBIaaVaTprSx8MoiVy6KtfOuQARPtuCgm/SrxLw19p/y+ukp/YtlS4Zpjg4oQr7o6vWOwedN3t IwwSG3lozZVPxOMSW5gJt6pJsreoz/uEx4shGFL1zcekH0FrBKAbV7wKtkqEaYOHmbjayx3QnBv1f /gqadrcCtrCQHvSuMWvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqsHH-000R6c-0l; Thu, 12 Oct 2023 09:46:47 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqsHD-000R25-2y for linux-arm-kernel@lists.infradead.org; Thu, 12 Oct 2023 09:46:45 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231012_024644_153168_2105313F X-CRM114-Status: GOOD ( 12.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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;