From patchwork Sat Nov 5 11:06:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yue Haibing X-Patchwork-Id: 15950 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp933150wru; Sat, 5 Nov 2022 04:14:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4XvgC5CHhX4fu1x1hDPIWzmGTmzxjf8kFjnyW/wDWJEIE6fpnsSMVYznd/OyO0OEBwCzKA X-Received: by 2002:a17:907:1b24:b0:76d:7b9d:2f8b with SMTP id mp36-20020a1709071b2400b0076d7b9d2f8bmr38127827ejc.414.1667646898777; Sat, 05 Nov 2022 04:14:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667646898; cv=none; d=google.com; s=arc-20160816; b=W+LgRiRkuMcI4xQIko1k3hTHP3amgri9a4XJNUT3ck6AEaSOzyNFKY8y49HcmEWCJC aP4ExjqKgf+RteSrXjGs5Kt7JT20sZOEGwNB7JuH9emfGrypDQ+iBwxtAFvZ9eSNYS2n I0w9jp8IApSNTYswkDk+q7f6ZBWft/ImOV7/59HIC/+LnTGQVm0aQA1iUXa4P3oKkFCt 0hXMF59NAeAiyQxxopaaEqe5IQBJtdTkSpNTDFP9evZKYolAn3KHP4dCO4j8CFbVeaY7 EHa7utJRsmY1rdRVt1RHpmkWjdygHx5frnGncQ57PC2NMB4h9SKh+03s006HZdlKi3uA 4s0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=FFitpFcK+1fZOD7vQtJ1mtvfLXs87DnHiQ9U0QdBV2o=; b=iHEiUGml0TigN0kfys84Fvzqc+FBU5ulvSUDWchQHU406ruE2CXFZur0+Acji8oif2 Gmq/l6t65FZznefJq7I+pvqEZD+0sbRbo1vI/75Zqvcsx5Q1cSGjGe5WtSlEFi0xIyDQ 3fD/c08j64fxdNgfmQU79aAMaoS6VP8PsNg7rftvpc6wx2pWWJEtIdpU56Ub+5FGB1p1 cCPa5mY+WdrClrU1WugiEJm4q69tttLq3g7niE5SMTrAY/qnP2R8SbHkvWNxQOdkPVzk ck33+gu384BB/gfwBHSOHbXFAsHMFqNWTMn0aMxbHuiGi3sCCMIHghs+2t7xSLsZ+9DO Z4lg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho15-20020a1709070e8f00b007763cc7093csi2218089ejc.884.2022.11.05.04.14.34; Sat, 05 Nov 2022 04:14:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229715AbiKELGx (ORCPT + 99 others); Sat, 5 Nov 2022 07:06:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbiKELGu (ORCPT ); Sat, 5 Nov 2022 07:06:50 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D172DFCE3; Sat, 5 Nov 2022 04:06:49 -0700 (PDT) Received: from canpemm500007.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N4F336TKkzpSsn; Sat, 5 Nov 2022 19:03:11 +0800 (CST) Received: from localhost (10.174.179.215) by canpemm500007.china.huawei.com (7.192.104.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 5 Nov 2022 19:06:48 +0800 From: YueHaibing To: , , , , , , , , CC: , , , YueHaibing Subject: [PATCH] selftests: cgroup: Fix unsigned comparison with less than zero Date: Sat, 5 Nov 2022 19:06:11 +0800 Message-ID: <20221105110611.28920-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.174.179.215] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500007.china.huawei.com (7.192.104.62) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748654514525041400?= X-GMAIL-MSGID: =?utf-8?q?1748654514525041400?= 'size' is unsigned, it never less than zero. Fixes: 6c26df84e1f2 ("selftests: cgroup: return -errno from cg_read()/cg_write() on failure") Signed-off-by: YueHaibing Reviewed-by: Yosry Ahmed Acked-by: Roman Gushchin Reviewed-by: Mukesh Ojha Reviewed-by: Kamalesh Babulal --- tools/testing/selftests/cgroup/cgroup_util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index 4c52cc6f2f9c..e8bbbdb77e0d 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -555,6 +555,7 @@ int proc_mount_contains(const char *option) ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size) { char path[PATH_MAX]; + ssize_t ret; if (!pid) snprintf(path, sizeof(path), "/proc/%s/%s", @@ -562,8 +563,8 @@ ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t else snprintf(path, sizeof(path), "/proc/%d/%s", pid, item); - size = read_text(path, buf, size); - return size < 0 ? -1 : size; + ret = read_text(path, buf, size); + return ret < 0 ? -1 : ret; } int proc_read_strstr(int pid, bool thread, const char *item, const char *needle)