From nobody Tue Oct 7 07:18:18 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBD481547CC; Mon, 14 Jul 2025 06:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752473880; cv=none; b=UwFLcPVp0j+E3oMRjQHHZInNeVT/xed0U89Hybdi3A2NKJgWH6sgBDQgBrzItbKi3gCnkkx1Kv/GlGsny+aH8eHp0s6nFllHgdjqZl+YZYUHltJoCRM3t4yHzQfF0/sPPMZOZXoatRlyeaQhx9WATdtciIxhrEXWiIxakvmSvMA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752473880; c=relaxed/simple; bh=hERdZR+kkHYGhOhKQMKBJVnuPqUcLCNOZQAXw5r5yHo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s/+o+MssJAFlL4P499Zaw/b06kzrUkvdTURZsZ6AdC/zoXvLt8qsu7oOmREp/DmsW9Yat3m2yiURU66bTRLJ5ArR55cT6sXOo70BtjzX/hPtEwli5FxgpVI0WNR9Di7Nxusp9a1H3VvHiRGH0ghpeR46l2b28Zf28NWh86FnL+I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4bgX9g3nspz29dqR; Mon, 14 Jul 2025 14:15:19 +0800 (CST) Received: from kwepemk100013.china.huawei.com (unknown [7.202.194.61]) by mail.maildlp.com (Postfix) with ESMTPS id DA598140123; Mon, 14 Jul 2025 14:17:55 +0800 (CST) Received: from localhost.localdomain (10.90.31.46) by kwepemk100013.china.huawei.com (7.202.194.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 14 Jul 2025 14:17:55 +0800 From: Jijie Shao To: , , , , , CC: , , , , , , , , , Subject: [PATCH V3 net-next 02/10] net: hns3: clean up the build warning in debugfs by use seq file Date: Mon, 14 Jul 2025 14:10:29 +0800 Message-ID: <20250714061037.2616413-3-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20250714061037.2616413-1-shaojijie@huawei.com> References: <20250714061037.2616413-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To kwepemk100013.china.huawei.com (7.202.194.61) Content-Type: text/plain; charset="utf-8" From: Jian Shen Arnd reported that there are two build warning for on-stasck buffer oversize. As Arnd's suggestion, using seq file way to avoid the stack buffer or kmalloc buffer allocating. Reported-by: Arnd Bergmann Closes: https://lore.kernel.org/all/20250610092113.2639248-1-arnd@kernel.or= g/ Signed-off-by: Jian Shen Signed-off-by: Jijie Shao Reviewed-by: Andrew Lunn Acked-by: Arnd Bergmann --- ChangeLog: v1 -> v2: - Remove unnecessary cast, suggested by Andrew Lunn v1: https://lore.kernel.org/all/20250708130029.1310872-1-shaojijie@huawei= .com/ --- drivers/net/ethernet/hisilicon/hns3/hnae3.h | 7 + .../ethernet/hisilicon/hns3/hns3_debugfs.c | 128 ++++++++---------- .../net/ethernet/hisilicon/hns3/hns3_enet.c | 2 + 3 files changed, 62 insertions(+), 75 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h b/drivers/net/ethe= rnet/hisilicon/hns3/hnae3.h index 8dc7d6fae224..db9639c3c402 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h +++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h @@ -339,6 +339,10 @@ enum hnae3_dbg_cmd { HNAE3_DBG_CMD_UNKNOWN, }; =20 +#define hnae3_seq_file_to_ae_dev(s) (dev_get_drvdata((s)->private)) +#define hnae3_seq_file_to_handle(s) \ + (((struct hnae3_ae_dev *)hnae3_seq_file_to_ae_dev(s))->handle) + enum hnae3_tc_map_mode { HNAE3_TC_MAP_MODE_PRIO, HNAE3_TC_MAP_MODE_DSCP, @@ -434,8 +438,11 @@ struct hnae3_ae_dev { u32 dev_version; DECLARE_BITMAP(caps, HNAE3_DEV_CAPS_MAX_NUM); void *priv; + struct hnae3_handle *handle; }; =20 +typedef int (*read_func)(struct seq_file *s, void *data); + /* This struct defines the operation on the handle. * * init_ae_dev(): (mandatory) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c b/drivers/n= et/ethernet/hisilicon/hns3/hns3_debugfs.c index aec719ce3ccd..52877ffec928 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c @@ -3,6 +3,7 @@ =20 #include #include +#include #include =20 #include "hnae3.h" @@ -41,6 +42,7 @@ static struct hns3_dbg_dentry_info hns3_dbg_dentry[] =3D { =20 static int hns3_dbg_bd_file_init(struct hnae3_handle *handle, u32 cmd); static int hns3_dbg_common_file_init(struct hnae3_handle *handle, u32 cmd); +static int hns3_dbg_common_init_t1(struct hnae3_handle *handle, u32 cmd); =20 static struct hns3_dbg_cmd_info hns3_dbg_cmd[] =3D { { @@ -300,7 +302,7 @@ static struct hns3_dbg_cmd_info hns3_dbg_cmd[] =3D { .cmd =3D HNAE3_DBG_CMD_TX_QUEUE_INFO, .dentry =3D HNS3_DBG_DENTRY_QUEUE, .buf_len =3D HNS3_DBG_READ_LEN_1MB, - .init =3D hns3_dbg_common_file_init, + .init =3D hns3_dbg_common_init_t1, }, { .name =3D "fd_tcam", @@ -674,77 +676,45 @@ static int hns3_dbg_rx_queue_info(struct hnae3_handle= *h, return 0; } =20 -static const struct hns3_dbg_item tx_queue_info_items[] =3D { - { "QUEUE_ID", 2 }, - { "BD_NUM", 2 }, - { "TC", 2 }, - { "TAIL", 2 }, - { "HEAD", 2 }, - { "FBDNUM", 2 }, - { "OFFSET", 2 }, - { "PKTNUM", 5 }, - { "RING_EN", 2 }, - { "TX_RING_EN", 2 }, - { "BASE_ADDR", 10 }, -}; - static void hns3_dump_tx_queue_info(struct hns3_enet_ring *ring, - struct hnae3_ae_dev *ae_dev, char **result, - u32 index) + struct seq_file *s, u32 index) { + struct hnae3_ae_dev *ae_dev =3D hnae3_seq_file_to_ae_dev(s); + void __iomem *base =3D ring->tqp->io_base; u32 base_add_l, base_add_h; - u32 j =3D 0; =20 - sprintf(result[j++], "%u", index); - sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base + - HNS3_RING_TX_RING_BD_NUM_REG)); - - sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base + - HNS3_RING_TX_RING_TC_REG)); - - sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base + - HNS3_RING_TX_RING_TAIL_REG)); - - sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base + - HNS3_RING_TX_RING_HEAD_REG)); - - sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base + - HNS3_RING_TX_RING_FBDNUM_REG)); - - sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base + - HNS3_RING_TX_RING_OFFSET_REG)); - - sprintf(result[j++], "%u", readl_relaxed(ring->tqp->io_base + - HNS3_RING_TX_RING_PKTNUM_RECORD_REG)); - - sprintf(result[j++], "%s", - str_on_off(readl_relaxed(ring->tqp->io_base + - HNS3_RING_EN_REG))); + seq_printf(s, "%-10u", index); + seq_printf(s, "%-8u", + readl_relaxed(base + HNS3_RING_TX_RING_BD_NUM_REG)); + seq_printf(s, "%-4u", readl_relaxed(base + HNS3_RING_TX_RING_TC_REG)); + seq_printf(s, "%-6u", readl_relaxed(base + HNS3_RING_TX_RING_TAIL_REG)); + seq_printf(s, "%-6u", readl_relaxed(base + HNS3_RING_TX_RING_HEAD_REG)); + seq_printf(s, "%-8u", + readl_relaxed(base + HNS3_RING_TX_RING_FBDNUM_REG)); + seq_printf(s, "%-8u", + readl_relaxed(base + HNS3_RING_TX_RING_OFFSET_REG)); + seq_printf(s, "%-11u", + readl_relaxed(base + HNS3_RING_TX_RING_PKTNUM_RECORD_REG)); + seq_printf(s, "%-9s", + str_on_off(readl_relaxed(base + HNS3_RING_EN_REG))); =20 if (hnae3_ae_dev_tqp_txrx_indep_supported(ae_dev)) - sprintf(result[j++], "%s", - str_on_off(readl_relaxed(ring->tqp->io_base + - HNS3_RING_TX_EN_REG))); + seq_printf(s, "%-12s", + str_on_off(readl_relaxed(base + + HNS3_RING_TX_EN_REG))); else - sprintf(result[j++], "%s", "NA"); + seq_printf(s, "%-12s", "NA"); =20 - base_add_h =3D readl_relaxed(ring->tqp->io_base + - HNS3_RING_TX_RING_BASEADDR_H_REG); - base_add_l =3D readl_relaxed(ring->tqp->io_base + - HNS3_RING_TX_RING_BASEADDR_L_REG); - sprintf(result[j++], "0x%08x%08x", base_add_h, base_add_l); + base_add_h =3D readl_relaxed(base + HNS3_RING_TX_RING_BASEADDR_H_REG); + base_add_l =3D readl_relaxed(base + HNS3_RING_TX_RING_BASEADDR_L_REG); + seq_printf(s, "0x%08x%08x\n", base_add_h, base_add_l); } =20 -static int hns3_dbg_tx_queue_info(struct hnae3_handle *h, - char *buf, int len) +static int hns3_dbg_tx_queue_info(struct seq_file *s, void *data) { - char data_str[ARRAY_SIZE(tx_queue_info_items)][HNS3_DBG_DATA_STR_LEN]; - struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(h); - char *result[ARRAY_SIZE(tx_queue_info_items)]; + struct hnae3_handle *h =3D hnae3_seq_file_to_handle(s); struct hns3_nic_priv *priv =3D h->priv; - char content[HNS3_DBG_INFO_LEN]; struct hns3_enet_ring *ring; - int pos =3D 0; u32 i; =20 if (!priv->ring) { @@ -752,12 +722,8 @@ static int hns3_dbg_tx_queue_info(struct hnae3_handle = *h, return -EFAULT; } =20 - for (i =3D 0; i < ARRAY_SIZE(tx_queue_info_items); i++) - result[i] =3D &data_str[i][0]; - - hns3_dbg_fill_content(content, sizeof(content), tx_queue_info_items, - NULL, ARRAY_SIZE(tx_queue_info_items)); - pos +=3D scnprintf(buf + pos, len - pos, "%s", content); + seq_puts(s, "QUEUE_ID BD_NUM TC TAIL HEAD FBDNUM OFFSET "); + seq_puts(s, "PKTNUM RING_EN TX_RING_EN BASE_ADDR\n"); =20 for (i =3D 0; i < h->kinfo.num_tqps; i++) { /* Each cycle needs to determine whether the instance is reset, @@ -769,12 +735,7 @@ static int hns3_dbg_tx_queue_info(struct hnae3_handle = *h, return -EPERM; =20 ring =3D &priv->ring[i]; - hns3_dump_tx_queue_info(ring, ae_dev, result, i); - hns3_dbg_fill_content(content, sizeof(content), - tx_queue_info_items, - (const char **)result, - ARRAY_SIZE(tx_queue_info_items)); - pos +=3D scnprintf(buf + pos, len - pos, "%s", content); + hns3_dump_tx_queue_info(ring, s, i); } =20 return 0; @@ -1170,10 +1131,6 @@ static const struct hns3_dbg_func hns3_dbg_cmd_func[= ] =3D { .cmd =3D HNAE3_DBG_CMD_RX_QUEUE_INFO, .dbg_dump =3D hns3_dbg_rx_queue_info, }, - { - .cmd =3D HNAE3_DBG_CMD_TX_QUEUE_INFO, - .dbg_dump =3D hns3_dbg_tx_queue_info, - }, { .cmd =3D HNAE3_DBG_CMD_PAGE_POOL_INFO, .dbg_dump =3D hns3_dbg_page_pool_info, @@ -1310,6 +1267,27 @@ hns3_dbg_common_file_init(struct hnae3_handle *handl= e, u32 cmd) return 0; } =20 +static int hns3_dbg_common_init_t1(struct hnae3_handle *handle, u32 cmd) +{ + struct device *dev =3D &handle->pdev->dev; + struct dentry *entry_dir; + read_func func =3D NULL; + + switch (hns3_dbg_cmd[cmd].cmd) { + case HNAE3_DBG_CMD_TX_QUEUE_INFO: + func =3D hns3_dbg_tx_queue_info; + break; + default: + return -EINVAL; + } + + entry_dir =3D hns3_dbg_dentry[hns3_dbg_cmd[cmd].dentry].dentry; + debugfs_create_devm_seqfile(dev, hns3_dbg_cmd[cmd].name, entry_dir, + func); + + return 0; +} + int hns3_dbg_init(struct hnae3_handle *handle) { struct hnae3_ae_dev *ae_dev =3D hns3_get_ae_dev(handle); diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/= ethernet/hisilicon/hns3/hns3_enet.c index 49fcee7a6d0f..52f42fe1d56f 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -5299,6 +5299,8 @@ static int hns3_client_init(struct hnae3_handle *hand= le) struct net_device *netdev; int ret; =20 + ae_dev->handle =3D handle; + handle->ae_algo->ops->get_tqps_and_rss_info(handle, &alloc_tqps, &max_rss_size); netdev =3D alloc_etherdev_mq(sizeof(struct hns3_nic_priv), alloc_tqps); --=20 2.33.0