From mboxrd@z Thu Jan 1 00:00:00 1970 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 BF5ADCDB465 for ; Thu, 19 Oct 2023 13:36:27 +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:Subject:CC:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=csEVuzSDcxT2bfz2/qKVP1zsWwvWYw1+LAeiDuKFnsw=; b=cyAzsJQp2Mz6BA dtIfqXufoC58I5LCzXfonXrsZEp1PJZoJibKQ3K/kx+IOgRmMBbtwMIY7y9rAhpXIjZFWkFifT21m z29CGdRqpvt0YsbU0H7DY96vCjZ3yJzzEfHXtSAfvD/Hi2aEDhuK3WOfdwjPLF4MMUTt8/ifAF4nP ajq/f2OLF2V1XGYyoiqNE8rpE2EUXUUXm46Wl3e9OTvLQy8TfwDW8TEfbJ8fuYXmfLngicMfg/+wy YUUOTiJt/yQbj11ZITcuaR6ykhTJTz8ryO2J7LrDPd3q8Do62ZfHS4L3VYs653k1ZMBxEHtpVTLYF nkXu6fApsHDktbg34t7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtTBy-00HXJ3-2f; Thu, 19 Oct 2023 13:36:02 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtTBv-00HXHW-2L for linux-arm-kernel@lists.infradead.org; Thu, 19 Oct 2023 13:36:01 +0000 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4SB7vl5PP2z6H7w9; Thu, 19 Oct 2023 21:33:23 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Thu, 19 Oct 2023 14:35:50 +0100 Date: Thu, 19 Oct 2023 14:35:48 +0100 From: Jonathan Cameron To: Junhao He , CC: , , , , , , , Subject: Re: [PATCH 2/3] coresight: ultrasoc-smb: simplify the code for check to_copy valid Message-ID: <20231019143530.00004c75@huawei.com> In-Reply-To: <20231012094706.21565-3-hejunhao3@huawei.com> References: <20231012094706.21565-1-hejunhao3@huawei.com> <20231012094706.21565-3-hejunhao3@huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 X-Originating-IP: [10.202.227.76] X-ClientProxiedBy: lhrpeml500006.china.huawei.com (7.191.161.198) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_063559_948584_6BD5E583 X-CRM114-Status: GOOD ( 20.62 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 12 Oct 2023 17:47:05 +0800 Junhao He wrote: > We only need to check once when before using the to_copy variable > to simplify the code. > > Signed-off-by: Junhao He I'm not convinced this one is an improvement. Sometimes it's easier to just see the individual conditions checked even if we could combine them. It's easy to understand we don't copy data if: a) We ask for 0 data. b) There is 0 data Less easy to establish that with the extra wrap around code in there (even though that has no impact on to_copy if it is 0) Jonathan > --- > 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; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel