Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2353573pxb; Mon, 20 Sep 2021 19:52:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3jE2e1ysuTo1texTBqB7/9JboPIQ4828wk2EwqLiq7fLVtBltbEOofSJxvixL9uZlbaYF X-Received: by 2002:a05:6402:b23:: with SMTP id bo3mr33236481edb.145.1632192723018; Mon, 20 Sep 2021 19:52:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192723; cv=none; d=google.com; s=arc-20160816; b=BEJZH17Cy00J8LaRYnefHoEsZTVaKs5gzmNDuyGa353MXA/1jwAZ2Whtu1+xqNRCGe d7jbmfhP0yFn8oVXEish6uKiMQsWQilwKNmYWHBU4fRF0sAWdRPSSeVICyBmD222tdTD JOCWR8fo7e2NDWSejVf4iegK9T1ntrS6nVj6360B+O8piTIp65lquu2Ve46YeqPt6sKL HNMLT9s9KbZBuzmoWQN0YLTpxiu9wn2+Zqjfm87PUfOPapB1Tno9fP/xGARutPtzWMZO X4CsS85zjwK73Cs4e9N3Tzudy9jtEG4Wj76co1JyGo+GlswEYY8apwbdh1bolO9H2seW xkNw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eJVZrIaU9G2EdMXT3gZ4WIQUVSINh+lw//T/+D1CpAQ=; b=ScWMAQ8+Cnbyo4I4ODjL2RMsaHE0NS9eZ820wTkBs5j1FuWawHcBMCM6ZPO4GMYJGH tBe33IWmsIIyE5khD4A63S5HkEFG7A8SUc60BnhsVG+c7wgKA0PfVp+iT3syHwIUGKFT hKTg3opM1g83pPG1T1GJJ36c7yHjODRElfIy1EEd5s8TpUTO88ey27rZUConYoOrkrif GYciqXKapO5/oH0Ap7X5/gCIC/NsNfDwg99lkiYiLhEkWtdMBYnJshK/Nl7kDReKKeBe 6MLFGR+aZLDbP0DuAXJEfZ9TSkSrBzYY9jOWe7NhlqzxAblvUXFZh/I3jcp0QHtt8rrR Zlgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ObOBA0/d"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m15si17786424ejb.569.2021.09.20.19.51.38; Mon, 20 Sep 2021 19:52:03 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ObOBA0/d"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354106AbhITSrV (ORCPT + 99 others); Mon, 20 Sep 2021 14:47:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:56468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353443AbhITSm2 (ORCPT ); Mon, 20 Sep 2021 14:42:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DB94161AE1; Mon, 20 Sep 2021 17:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159120; bh=GSkFnDIELaBtcinw7Rn4/dyjtsaBin5+Zzcp0Y70OG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ObOBA0/dPjZiizc6uj/oXaESfAdkOX4wuetwE59I2QvySpCqNWUHZvJ2Xo6PrrqKx WbaPu+3Cabi1zVRwyZlUksojlmreG8lVHVK0+3nnYueQD+WyUfzlM5wxK0daZI5fcB 8FKrIWLvLtNE0Cs396wpQr3O64E89iTed4f3UAnk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiaran Zhang , Guangbin Huang , "David S. Miller" , Sasha Levin Subject: [PATCH 5.14 085/168] net: hns3: fix the exception when query imp info Date: Mon, 20 Sep 2021 18:43:43 +0200 Message-Id: <20210920163924.429982624@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiaran Zhang [ Upstream commit 472430a7b066f19afa1b55867d621b2d6d323e0d ] 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 Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 288788186ecc..e6e617aba2a4 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c @@ -1710,6 +1710,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.30.2