From patchwork Wed Nov 30 13:21:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 27781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp908816wrr; Wed, 30 Nov 2022 05:01:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf4wMtxbxotVEoR5BPyJLR3USbKQqRNVkVntrwg+Wbf3SR+oF6DeUqHdMHzjomMq3I/Tr7Rj X-Received: by 2002:a17:903:3302:b0:189:9590:4f98 with SMTP id jk2-20020a170903330200b0018995904f98mr10937747plb.148.1669813292218; Wed, 30 Nov 2022 05:01:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669813292; cv=none; d=google.com; s=arc-20160816; b=qlustpzatjBqlFKjGIocx/z+KoR/Ok7XjsTtKS7ZtL0m70R9y/L9e3k96ZOH/xYnsr XuhTI+EILES4PEmu4GcTvq4iApXfiqO8NxwhNjtDpmr7hCBp4UKeiqK7SmTr4BbEDVWp 6Qu1BQ0tGzPMK3WweJlJCThZCzkJEf1wQh4DzsdbcRVWrEgYxFHTW+LKlwuXv+KND0du 65m0K3rUFfPWOtwAS9785nHvOsrGggF+wKOU0nOdpzTaStabEynlTA1tgGOqhCi9/Cn9 PWMp4hzCT/16zHzEz+YyWkbelhlVn7NhZcDhhavUIJgAjet0IRtvrMgCZMNbX3JlMzmc bKEg== 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=c7rGZ4APFzB+cgHnBPRWoJMtj5nvD1dQb2Q2zIAsuWio8yXVIQdSDs1hL4/E6XuCJw ggV3X1kDEp/9vomzgeZ2sqZQBzhWiaDuuBjqL+wHY6Nd2anR5uq75doMkBEukAOBc4Bz RN1jaTEn5ZBEOsE2rPojWy92v4ZFprGVOzwWtVDV0H4jDn/HF892qHz5un4jJsTSL5Ro /fE6vXh78sbXFTTyOgoDh8UUIXfR8JQqBqBdcVh1JCywdKQYavcSAk2uXDmVo3Ls+P3q RX02+lPEQ4EC9f8evSo8hqPZqmGq9obC9LYwi0xc8H+7CjAsYlIfkWtvvndpzI9ig8NO GVCw== 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 d14-20020a655ace000000b004775cf62c5dsi1253937pgt.297.2022.11.30.05.01.18; Wed, 30 Nov 2022 05:01:32 -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 S235367AbiK3NBC (ORCPT + 99 others); Wed, 30 Nov 2022 08:01:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232924AbiK3NA4 (ORCPT ); Wed, 30 Nov 2022 08:00:56 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AF594AF34; Wed, 30 Nov 2022 05:00:54 -0800 (PST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NMfST1lmDzHwFM; Wed, 30 Nov 2022 21:00:09 +0800 (CST) Received: from dggpeml500003.china.huawei.com (7.185.36.200) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 30 Nov 2022 21:00:51 +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; Wed, 30 Nov 2022 21:00:51 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next v2 2/9] blk-iocost: improve hanlder of match_u64() Date: Wed, 30 Nov 2022 21:21:49 +0800 Message-ID: <20221130132156.2836184-3-linan122@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221130132156.2836184-1-linan122@huawei.com> References: <20221130132156.2836184-1-linan122@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750926142602633428?= X-GMAIL-MSGID: =?utf-8?q?1750926142602633428?= 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; }