Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1818914pxb; Mon, 13 Sep 2021 06:16:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXdEm3PJNJiwd7Yp3p48G11L2q8oM1qbYc0HJB1JbGhdnfSlPVuF25ZJUAhCk3+8SeYvMo X-Received: by 2002:a17:907:9723:: with SMTP id jg35mr12393837ejc.187.1631539006813; Mon, 13 Sep 2021 06:16:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631539006; cv=none; d=google.com; s=arc-20160816; b=mm7+kGa+PzObhThE5kyWFbolfOGGqPGLaIT6KiyOhp5EpkKYpq15RpGzbIzl6NtVUq K6NSdA7TIiDHNSBb+U3a4u2h4IICaX66uzQbEknTlOwqFLgYzXoTYvTkivHx3eXMIH4b Zu1QwR1IJoRbVWm5u4KwR14z8CSvZxif6/bOUHNQl+U40aNLoTWtJjg+Dr1TErMhXAOs kaUcCKer5yje27No+cWGSMizeKcC0v8v4Vq+IHWgBEMZcQw9rdEMl746lu3xwB1NkE2g 0O3U65AX48qj1Ee74k05aFGMo6rhVOqre0g5fSfd+Y9TBVwKV2r4dcqD0S68oNgRtBWV E7Sg== 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=zVDthSbT6c6gUfw4VLK2fvIGVKQsmob6u+mWzaOEB78=; b=kt6xjY61lxSkETGuujEvYfdZYZUBh9j+8oppxELFMoI5FUVz60NnaUXYLD34kKLhej MlLYEx2sTr1kmU0VcqzI1j2Ky6BSA3CcLmkvXaeWy5ZVVBT+vf2Xg2xrEa1aVgM8v8RG FUhtLmzr08MczkB9+Iv9tlJCRh8jCU7XgqNB9gNb8+0XKcAdCXcqf5ge3vKnB4KHDVLq z56engwliBNyQn9RfJPmP63W40RlWlSClRpPdmczsJ5mnZO1Z8+JsqwMaMe84K4XeWkU OHA94AO6tqHnTQ7oWRj2E0FKO9pMcYTH0ne/JmDtMPPK8dT4aSlycnMbvhhWLpg65P5q mJzw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l1si7167528edt.613.2021.09.13.06.16.21; Mon, 13 Sep 2021 06:16:46 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240050AbhIMNOP (ORCPT + 99 others); Mon, 13 Sep 2021 09:14:15 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:9862 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238400AbhIMNN5 (ORCPT ); Mon, 13 Sep 2021 09:13:57 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H7Rc62nSXz8yW0; Mon, 13 Sep 2021 21:08:06 +0800 (CST) Received: from kwepemm600016.china.huawei.com (7.193.23.20) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Mon, 13 Sep 2021 21:12:29 +0800 Received: from localhost.localdomain (10.67.165.24) by kwepemm600016.china.huawei.com (7.193.23.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Mon, 13 Sep 2021 21:12:29 +0800 From: Guangbin Huang To: , CC: , , , Subject: [PATCH net 5/6] net: hns3: fix the exception when query imp info Date: Mon, 13 Sep 2021 21:08:24 +0800 Message-ID: <20210913130825.27025-6-huangguangbin2@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913130825.27025-1-huangguangbin2@huawei.com> References: <20210913130825.27025-1-huangguangbin2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600016.china.huawei.com (7.193.23.20) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiaran Zhang When the command for querying imp info is issued to the firmware, if the firmware does not support the command, the returned value of bd num is 0. Add protection mechanism before alloc memory to prevent apply for 0-length memory. Fixes: 0b198b0d80ea ("net: hns3: refactor dump m7 info of debugfs") Signed-off-by: Jiaran Zhang Signed-off-by: Guangbin Huang --- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c index 68ed1715ac52..87d96f82c318 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c @@ -1724,6 +1724,10 @@ hclge_dbg_get_imp_stats_info(struct hclge_dev *hdev, char *buf, int len) } bd_num = le32_to_cpu(req->bd_num); + if (!bd_num) { + dev_err(&hdev->pdev->dev, "imp statistics bd number is 0!\n"); + return -EINVAL; + } desc_src = kcalloc(bd_num, sizeof(struct hclge_desc), GFP_KERNEL); if (!desc_src) -- 2.33.0