Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2350814rwb; Wed, 30 Nov 2022 05:42:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf5QinFGtWyF4TvQmNvjYSswFEH59uhigNCGHFuq7LVKCxKtUhl4DLV4g8ubvk3I7DS12gjE X-Received: by 2002:a05:6402:e04:b0:469:e6ef:9164 with SMTP id h4-20020a0564020e0400b00469e6ef9164mr7537916edh.185.1669815777938; Wed, 30 Nov 2022 05:42:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669815777; cv=none; d=google.com; s=arc-20160816; b=YruC46JPBQDbSxyA4/W/WZ460WhVKBGaXTUeHU4eWwpJh5/QmwWEsY0cnBs0bKrWed J2w3GNIc2uxUxVQfHCUe0aOzyWfpctPuZ4ezZ8Uw/hGWkmV7lYZFGpHIarN8ymnrCaG6 I9lipLyvdsre53t0sPGdItnpUOJMnQKDA7tlTMvD/fqbNiKOjYrzXXja2bk47MVU2F7a 9U1mf11riLmCtCj6iLfeERftmZAJnils26e99C4WnFghyvdr1MfMXZFfUmfAtRCFtcha XBKLjp6bL/diC6fkl6FCglqWmUYCaOPxTCajdIRRhoBr1BANuv9drQzBou2LKhttYNgR VSiw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la16-20020a170906ad9000b0078da5f6ed9esi977848ejb.779.2022.11.30.05.42.37; Wed, 30 Nov 2022 05:42:57 -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 + 84 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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