From patchwork Mon Nov 28 15:44:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 26821 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5749951wrr; Mon, 28 Nov 2022 07:27:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf5s/2wfdciK5kMTDJwGFDY2LjbVj+xx7RJHq5KEiKGy6cpAapXcxxSNgcEa9cx0V5WTvELW X-Received: by 2002:a17:906:c283:b0:7ae:2277:9fec with SMTP id r3-20020a170906c28300b007ae22779fecmr42676303ejz.623.1669649269671; Mon, 28 Nov 2022 07:27:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669649269; cv=none; d=google.com; s=arc-20160816; b=pIH5bAGfiNZQJNatDkOLwxGlJoDHZ9p1v56it4VyDdldBj54XdTVy/nAt6ELX0ir1v l/+FrnuOP3aSLuvGdla3VpqheNJ2FiwlDOQ9OMzdwtEl2mlss8QcnxW3GjU+vRniOMtu 9r+Jjx0IVTnwXD/dFnFWQO0ANqKtPS5NXXuLr4Vdyn/byfnEKx1srwFOGFGEjIt9R2EX ezQ2rEEY2cTIlhuvntXHdnyT5escFrOWHQhoEyfN60SOjmbbJWtWv3s+BbOwrShDPfyP DZ26Ndm1ftY/LP3RQgOFdH4IwWLZSVW8nNz+PuAuDc2BN7K0iyf1B+SkVjRNbkd4Vgbt S3Xw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hv11-20020a17090760cb00b0073dda1430b9si10280973ejc.403.2022.11.28.07.27.16; Mon, 28 Nov 2022 07:27:49 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750754152236274328?= X-GMAIL-MSGID: =?utf-8?q?1750754152236274328?= 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; }