Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp15068067rwb; Mon, 28 Nov 2022 07:40:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf58cjZG9UWxHl9gzjnwT9DoW4JObprrzE6cJkc2CbLv46b1/rCOFilnxwA6K3CNNXVPqOYm X-Received: by 2002:a17:90a:5aa2:b0:218:e3ea:e6b3 with SMTP id n31-20020a17090a5aa200b00218e3eae6b3mr27235003pji.42.1669650027120; Mon, 28 Nov 2022 07:40:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669650027; cv=none; d=google.com; s=arc-20160816; b=jvyM7YXJtBSOVo+MoMc8AOn2ap+QKcvbNbsdLnxdAjqqbvKafdKJ8UUvNe18lLpoL8 cAhLK6ouKUazQgckhiQ0EO8pHUGyE6Uk3O0MiKcUJ16jnjLGyiLixhq7sXfH0ZHf7T19 8ORXcF065Tj2c5h06nv3QE0LJqjttAN857qjbwtWq0WXDrxy3EJsgc4dGyIJqLMQ/tYU M9ZcJPWWl+AxwBvs22n9J35KXW+LI+OG1MecWjfASBtMjPjYP74Ym1BK4KfCJLa0rig6 I+WBPpqu1js1LAC2PNkXmWRspE+BXbgDuMWc8DkQ+doI6cs2FjL8JaYmfGv1LrpPtq1k TDyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Q8yLqyqzOfGtkIz83RYljVFXFg81+m8W3dZLdJayQB0=; b=E8XTF6Tsf+Qvyx/fCROwx7Wnh6UtI1T2wLI0hX3ugsmqtz8wZU3qY6U1EtPGI3LzxO 9Dh5ICubmcwdBcNXXUAHd3Z3gtRPQH+UPloD3ob8pBCHpIcyYq+L6923gVsrbfrdQWef h0Ov3qY+jdHikx2AAVAbznDOKurF5/81bnSEV17h3pfL/TwOPeGIUjGVqvX5I4apGJVn dQJq5Ur1pJnsX5znHyPXzQGOXXZiNRN3F/jepV2S6/kb2GkgT8ERUQsll9K6K9emASYZ xJpelKG8xYP5T5PLwh5l2uc1rLX3n75L3MgRu9uJjY1LtEneZySpBCsiXn30049BtyYH f4sw== 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 190-20020a6309c7000000b004629ce15656si11158468pgj.196.2022.11.28.07.40.16; Mon, 28 Nov 2022 07:40:27 -0800 (PST) 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 S231246AbiK1PXl (ORCPT + 84 others); Mon, 28 Nov 2022 10:23:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbiK1PXa (ORCPT ); Mon, 28 Nov 2022 10:23:30 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5E8525EA; Mon, 28 Nov 2022 07:23:29 -0800 (PST) Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NLTk223r5z15MtB; Mon, 28 Nov 2022 23:22:50 +0800 (CST) Received: from dggpeml500003.china.huawei.com (7.185.36.200) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 28 Nov 2022 23:23:27 +0800 Received: from huawei.com (10.175.127.227) by dggpeml500003.china.huawei.com (7.185.36.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 28 Nov 2022 23:23:27 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next 2/8] blk-iocost: improve hanlder of match_u64() Date: Mon, 28 Nov 2022 23:44:28 +0800 Message-ID: <20221128154434.4177442-3-linan122@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221128154434.4177442-1-linan122@huawei.com> References: <20221128154434.4177442-1-linan122@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500003.china.huawei.com (7.185.36.200) 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 From: Yu Kuai 1) There are one place that return value of match_u64() is not checked. 2) If match_u64() failed, return value is set to -EINVAL despite that there are other possible errnos. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Signed-off-by: Li Nan --- block/blk-iocost.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index fd495e823db2..c532129a1456 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -3202,6 +3202,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, substring_t args[MAX_OPT_ARGS]; char buf[32]; int tok; + int err; s64 v; if (!*p) @@ -3209,7 +3210,12 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, switch (match_token(p, qos_ctrl_tokens, args)) { case QOS_ENABLE: - match_u64(&args[0], &v); + err = match_u64(&args[0], &v); + if (err) { + ret = err; + goto out_unlock; + } + enable = v; continue; case QOS_CTRL: @@ -3238,8 +3244,12 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, break; case QOS_RLAT: case QOS_WLAT: - if (match_u64(&args[0], &v)) + err = match_u64(&args[0], &v); + if (err) { + ret = err; goto out_unlock; + } + qos[tok] = v; break; case QOS_MIN: @@ -3374,6 +3384,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, substring_t args[MAX_OPT_ARGS]; char buf[32]; int tok; + int err; u64 v; if (!*p) @@ -3399,8 +3410,13 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, tok = match_token(p, i_lcoef_tokens, args); if (tok == NR_I_LCOEFS) goto out_unlock; - if (match_u64(&args[0], &v)) + + err = match_u64(&args[0], &v); + if (err) { + ret = err; goto out_unlock; + } + u[tok] = v; user = true; } -- 2.31.1