Skip to contentSkip to conversation

net: cleanup bitmaps printing

PATCH Applied Yury Norov 3 participants 5 messages Mar 19 – Mar 24

Subsystems (3)
lore
Share & tools
lore

Yury Norov

author
#0 lore raw

v2 cover net: cleanup bitmaps printing

Bitmap API has a bitmap_print_to_pagebuf() function that is intended to print bitmap into a human readable format, making sure that the output string will not get big enough to cross the current page limit.

Some drivers use this function immediately before passing the result to scnprintf() with no modification. This is useless because scnprintf(), and helpers based on it like seq_pritf() and sysfs_emit(), take care of not overflowing the buffer by itself, and perfectly print bitmaps with "%*pb[l]".

v1: https://lore.kernel.org/all/[email protected]/
v2:
- fix copy-paste error in print_npa_qsize() (Simon);
- fix typo in #1 subject (Jakub).

Yury Norov (2):
octeontx2-af: siplify rvu_debugfs
net-sysfs: switch xps_queue_show() to sysfs_emit()

 .../marvell/octeontx2/af/rvu_debugfs.c        | 28 ++++---------------
 net/core/net-sysfs.c                          |  2 +-
 2 files changed, 6 insertions(+), 24 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v2 1/2 octeontx2-af: simplify rvu_debugfs

The driver uses bitmap_print_to_pagebuf() to store human-readable bitmaps representations in a temporary buffers; and then feed seq_printf() with it.

Switch to using seq_printf("%*pb") directly and drop intermediate buffer.

---
 .../marvell/octeontx2/af/rvu_debugfs.c        | 28 ++++---------------
 1 file changed, 5 insertions(+), 23 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +5 -23
index 15d3cb0b9da6..9e5a85998ccc 100644
@@ -960,30 +960,21 @@ static bool rvu_dbg_is_valid_lf(struct rvu *rvu, int blkaddr, int lf,
 
 static void print_npa_qsize(struct seq_file *m, struct rvu_pfvf *pfvf)
 {
-	char *buf;
-
-	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
-	if (!buf)
-		return;
-
 	if (!pfvf->aura_ctx) {
 		seq_puts(m, "Aura context is not initialized\n");
 	} else {
-		bitmap_print_to_pagebuf(false, buf, pfvf->aura_bmap,
-					pfvf->aura_ctx->qsize);
 		seq_printf(m, "Aura count : %d\n", pfvf->aura_ctx->qsize);
-		seq_printf(m, "Aura context ena/dis bitmap : %s\n", buf);
+		seq_printf(m, "Aura context ena/dis bitmap : %*pb\n",
+			   pfvf->aura_ctx->qsize, pfvf->aura_bmap);
 	}
 
 	if (!pfvf->pool_ctx) {
 		seq_puts(m, "Pool context is not initialized\n");
 	} else {
-		bitmap_print_to_pagebuf(false, buf, pfvf->pool_bmap,
-					pfvf->pool_ctx->qsize);
 		seq_printf(m, "Pool count : %d\n", pfvf->pool_ctx->qsize);
-		seq_printf(m, "Pool context ena/dis bitmap : %s\n", buf);
+		seq_printf(m, "Pool context ena/dis bitmap : %*pb\n",
+			   pfvf->pool_ctx->qsize, pfvf->pool_bmap);
 	}
-	kfree(buf);
 }
 
 /* The 'qsize' entry dumps current Aura/Pool context Qsize
@@ -2545,17 +2536,8 @@ RVU_DEBUG_SEQ_FOPS(nix_cq_ctx, nix_cq_ctx_display, nix_cq_ctx_write);
 static void print_nix_qctx_qsize(struct seq_file *filp, int qsize,
 				 unsigned long *bmap, char *qtype)
 {
-	char *buf;
-
-	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
-	if (!buf)
-		return;
-
-	bitmap_print_to_pagebuf(false, buf, bmap, qsize);
 	seq_printf(filp, "%s context count : %d\n", qtype, qsize);
-	seq_printf(filp, "%s context ena/dis bitmap : %s\n",
-		   qtype, buf);
-	kfree(buf);
+	seq_printf(filp, "%s context ena/dis bitmap : %*pb\n", qtype, qsize, bmap);
 }
 
 static void print_nix_qsize(struct seq_file *filp, struct rvu_pfvf *pfvf)
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v2 2/2 net-sysfs: switch xps_queue_show() to sysfs_emit()

In reply to Yury Norov

Switch the function to use the proper sysfs_emit("%pb").

---
 net/core/net-sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/net-sysfs.c +1 -1
index 07624b682b08..a260f8b4d5c6 100644
@@ -1754,7 +1754,7 @@ static ssize_t xps_queue_show(struct net_device *dev, unsigned int index,
 out_no_maps:
 	rcu_read_unlock();
 
-	len = bitmap_print_to_pagebuf(false, buf, mask, nr_ids);
+	len = sysfs_emit(buf, "%*pb\n", nr_ids, mask);
 	bitmap_free(mask);
 
 	return len < PAGE_SIZE ? len : -EINVAL;
Signature · 1 line
2.43.0
reviewer Reviewed-by on the v2 series
#3 lore raw
In reply to Yury Norov
Quoted 10 lines · Yury Norov

Bitmap API has a bitmap_print_to_pagebuf() function that is intended to print bitmap into a human readable format, making sure that the output string will not get big enough to cross the current page limit.

Some drivers use this function immediately before passing the result to scnprintf() with no modification. This is useless because scnprintf(), and helpers based on it like seq_pritf() and sysfs_emit(), take care of not overflowing the buffer by itself, and perfectly print bitmaps with "%*pb[l]".

Quoted 4 lines

v1: https://lore.kernel.org/all/[email protected]/
v2:
- fix copy-paste error in print_npa_qsize() (Simon);
- fix typo in #1 subject (Jakub).

Thanks for the updates.

#4 lore raw
In reply to Yury Norov
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 11 lines · On Thu, 19 Mar 2026 16:17:09 -0400 you wrote:

Bitmap API has a bitmap_print_to_pagebuf() function that is intended to print bitmap into a human readable format, making sure that the output string will not get big enough to cross the current page limit.

Some drivers use this function immediately before passing the result to scnprintf() with no modification. This is useless because scnprintf(), and helpers based on it like seq_pritf() and sysfs_emit(), take care of not overflowing the buffer by itself, and perfectly print bitmaps with "%*pb[l]".

[...]

Here is the summary with links:
- [1/2] octeontx2-af: simplify rvu_debugfs

    https://git.kernel.org/netdev/net-next/c/6e4235adfa88
  - [2/2] net-sysfs: switch xps_queue_show() to sysfs_emit()
    https://git.kernel.org/netdev/net-next/c/de69301dc2f6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html