Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp274859ybk; Sat, 9 May 2020 02:30:53 -0700 (PDT) X-Google-Smtp-Source: APiQypKVM6BdBz//5Vtobk0xXlRdpzbkF5mhEgAeJKZROFNW0GmGT9/NSMe+8+5LhsZeYf3rqdJB X-Received: by 2002:a17:906:6a48:: with SMTP id n8mr5144432ejs.315.1589016653780; Sat, 09 May 2020 02:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589016653; cv=none; d=google.com; s=arc-20160816; b=QbpjS1eln+uthhjPHZGoAhXagg3Cp9lEWeFZL6W5sPTxtUZwwwOJBTDv96244dIcP2 uxlUr/tZDW+lI+A/tSIP8Lquqx+Jy6FsuSboxGThZjc5E7BlJrTRh3lsZd8wk8yyaNXf 3jSK9uN/5uacMXyKNkT/DygzndMS3qXVAnp0MufEI5geSnHhC5jpsBpVrV3NFfgvbf2A 6BuFlHh5xkS7yk4VMd4HS8IFlDy1L15FLXWPEBMpqZIPGK9YJfcL4KG1QTWCC3r1iDVK Vxs1WPqzaqtZ2JD9P3WNgjIn7SV0kuQtIdyTID9C2qoYEqtlyFYflN152iOf1VjzANnw mKSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=o4fJBf2//E7pKrdX5AUX9BqKNksYip2AnzGnfJnPOY0=; b=M2L6rJ8hJb357rhOeYO3LbMkG1sl8hgu5dAzys1HIfANkRGTWS7vyzOg4C2EBPj/4t zROBhTdgLtfAJrXTMAQFwYrBofzF/BS9KlozlVAuVEWkMHGBHH3FGTwwo88/wby+Fxoa NKiZWQS+0pn6xI4Xb+WBMPQ2+K7pzaNYOXNg7S+PmiGFwFVjghMJN4Kki1r/TW9IuP10 hLKgi90/gjAlbMf/sUtw0h1GEeosgreSCNwWhhiqoEO8valBuTRcr3C8k8yWJb2IaoF9 U88AeRPUDkdb8MNdzY0m64MwK7Ez/tvltSTB/HDyUY8snRLTXZRYKnaNU3uIGmd9cs8/ +rgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v3si2527545eja.72.2020.05.09.02.30.30; Sat, 09 May 2020 02:30:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728164AbgEIJ3F (ORCPT + 99 others); Sat, 9 May 2020 05:29:05 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4379 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728126AbgEIJ3C (ORCPT ); Sat, 9 May 2020 05:29:02 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 6A64B25B68EA0FD6FCBA; Sat, 9 May 2020 17:29:00 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Sat, 9 May 2020 17:28:49 +0800 From: Huazhong Tan To: CC: , , , , , , Yufeng Mo , Huazhong Tan Subject: [PATCH net-next 4/5] net: hns3: optimized the judgment of the input parameters of dump ncl config Date: Sat, 9 May 2020 17:27:40 +0800 Message-ID: <1589016461-10130-5-git-send-email-tanhuazhong@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1589016461-10130-1-git-send-email-tanhuazhong@huawei.com> References: <1589016461-10130-1-git-send-email-tanhuazhong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yufeng Mo This patch optimizes the judgment of the input parameters of dump ncl config by checking the number and value of the input parameters apart. It's clearer and more reasonable. Signed-off-by: Yufeng Mo Signed-off-by: Huazhong Tan --- .../net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c index 6cfa825..48c115c 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c @@ -1258,6 +1258,7 @@ static void hclge_dbg_dump_ncl_config(struct hclge_dev *hdev, { #define HCLGE_MAX_NCL_CONFIG_OFFSET 4096 #define HCLGE_NCL_CONFIG_LENGTH_IN_EACH_CMD (20 + 24 * 4) +#define HCLGE_NCL_CONFIG_PARAM_NUM 2 struct hclge_desc desc[HCLGE_CMD_NCL_CONFIG_BD_NUM]; int bd_num = HCLGE_CMD_NCL_CONFIG_BD_NUM; @@ -1267,13 +1268,17 @@ static void hclge_dbg_dump_ncl_config(struct hclge_dev *hdev, int ret; ret = sscanf(cmd_buf, "%x %x", &offset, &length); - if (ret != 2 || offset >= HCLGE_MAX_NCL_CONFIG_OFFSET || - length > HCLGE_MAX_NCL_CONFIG_OFFSET - offset) { - dev_err(&hdev->pdev->dev, "Invalid offset or length.\n"); + if (ret != HCLGE_NCL_CONFIG_PARAM_NUM) { + dev_err(&hdev->pdev->dev, + "Too few parameters, num = %d.\n", ret); return; } - if (offset < 0 || length <= 0) { - dev_err(&hdev->pdev->dev, "Non-positive offset or length.\n"); + + if (offset < 0 || offset >= HCLGE_MAX_NCL_CONFIG_OFFSET || + length <= 0 || length > HCLGE_MAX_NCL_CONFIG_OFFSET - offset) { + dev_err(&hdev->pdev->dev, + "Invalid input, offset = %d, length = %d.\n", + offset, length); return; } -- 2.7.4