Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp747041rdb; Thu, 19 Oct 2023 19:33:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYFHOjGlCYYmDptFXcxF++Vzj3siK1BIfSqSBs5MMRks9g73N9pwdSQtHuq4WlW1fxILa4 X-Received: by 2002:a25:8584:0:b0:d9a:4556:4669 with SMTP id x4-20020a258584000000b00d9a45564669mr510393ybk.47.1697769236200; Thu, 19 Oct 2023 19:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697769236; cv=none; d=google.com; s=arc-20160816; b=V4OuwW5Sr3nERQp+Oj+BsRmORKJPslK1XVG5A0IDQz6Lm/nppmX7I/D6OhkQT3Bpyx l3LFIiBTEps2kJbVlOErEyolyQATqcWLUGhWYhC+VawzSQiMo/jS+409dho6fZfnLiZf /g8HjCwiGuM6kpnHINjUzOG4Ie3UQUMvQSVIZrIYZ3jFQxGMsYitiW1B/p7BMwbB31uj 0d+7kHkoqVei2MA+KBwZ6JpdXuDfWhbtXt9r+tjcivVIJJzjDXgM4m7Wb3ckG7R642lD w/UISBs99mGYqbJ0TAO8vxjP1+Tqv3Y3DL6eAPNV7cmigslB810qr6jam0ZTBbTud8go TIxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=9ry6ho6n3UI3nDvtED2xr9DaiUzIdXrgHyHVD/G6cBc=; fh=8+aKvmml2qC3nyoA6s8C50FAEBr2Lwoj1boW5JLPzcY=; b=x1I//xnskZ2UOf4dLidQF5PEHemoc0E+GEMt0Z2bD5F4Je9nbWHixXTj1nXg2F610c 0QDQdP4g2f1YZLx8YhEIxEueOo7OzENsRGMB7ywmu9iMuQ3rbXLLQ6mjDDnBj3FXkrnN vk4ZmzdYkzsFkb0/5mx+avGm09bqtsZo0GcO68VDmJDK72/cFg+3C5PEAWXCCpxBw6Eu YBz2LbuofwTdwZq8UTtBpuFu+bhTAhhNj1ROK3vxbfDLhG8Y/mrHnhecGqG6c+k9rB/D myaOet3Dj7AHynJEpKe/8siSAFt7MrE8pFC21yr2UsJi7mKpXkdwVEXh+zqb3aaujXmu idiQ== 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 Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id f4-20020aa79684000000b00690c1e51cdfsi883048pfk.188.2023.10.19.19.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 19:33:56 -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 F242282A8011; Thu, 19 Oct 2023 19:33:53 -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 S1346841AbjJTCdr (ORCPT + 99 others); Thu, 19 Oct 2023 22:33:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235581AbjJTCdq (ORCPT ); Thu, 19 Oct 2023 22:33:46 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32EA598 for ; Thu, 19 Oct 2023 19:33:45 -0700 (PDT) Received: from dggpeml500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SBT7V3cbkzNp1s; Fri, 20 Oct 2023 10:29:42 +0800 (CST) Received: from [10.67.120.218] (10.67.120.218) 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; Fri, 20 Oct 2023 10:33:42 +0800 Subject: Re: [PATCH 2/3] coresight: ultrasoc-smb: simplify the code for check to_copy valid To: Jonathan Cameron , References: <20231012094706.21565-1-hejunhao3@huawei.com> <20231012094706.21565-3-hejunhao3@huawei.com> <20231019143530.00004c75@huawei.com> CC: , , , , , , From: hejunhao Message-ID: <28ab70eb-8b75-6a56-1406-859a51ea4684@huawei.com> Date: Fri, 20 Oct 2023 10:33:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20231019143530.00004c75@huawei.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.120.218] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500002.china.huawei.com (7.185.36.158) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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, 19 Oct 2023 19:33:54 -0700 (PDT) On 2023/10/19 21:35, Jonathan Cameron wrote: > 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 > Thanks, I will drop this patch. Best regards, Junhao. >> --- >> 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; > . >