Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp2240083rwl; Sat, 5 Nov 2022 04:16:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4VmTh/7wa/M+X4jCltLCVNlDZvb27WM99+/qLsk9LjUH9hx2jbCOszUkez/2nPcXEj29Nh X-Received: by 2002:a05:6402:414f:b0:456:c2c1:23ec with SMTP id x15-20020a056402414f00b00456c2c123ecmr40712555eda.420.1667646974857; Sat, 05 Nov 2022 04:16:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667646974; cv=none; d=google.com; s=arc-20160816; b=iTuSv/Oab/IfsbONPPwxgq29J+pn3kS9Cw3MohmkEqx1yWGw5K6026M4O0uTeJfB1o 7kXn1mNLmAOmir3jxQhdxtuWZNoX+ynpx/8x3rzzhArgMKUqH+2sUqcwIKPXFC476yZJ AyjcTTZEwfOSLWwDKi6lZTk1F1b9q0z0XLX95RjeLnCjz6IctPvDA25y1qQWgppGnPNL 4sO9A1S2p26xAWhIkwF/rdr/+G+NW8iNH++zd3F826mzU1KIdLzKcdfHgVSdi+XE/xR2 TlPFwFn4YxmHyJgGvs7kokUL/QD4XuaMgHVX6gdfmvdJVCeagSxrQFTtTtwY5NCxeIOc PAKQ== 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 Return-Path: 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.15.51; Sat, 05 Nov 2022 04:16:14 -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 + 97 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 Content-Type: text/plain 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 '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 --- 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) -- 2.17.1