mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2025-08-22 00:42:01 +02:00

Although it seems unlikely in practice - there would need to be rx ring indexes greater than 10^10 - it is theoretically possible for the filename of per rx ring debugfs files to be truncated. This is because although a 16 byte buffer is provided, the length of the filename is restricted to 10 bytes. Remove this restriction and allow the entire buffer to be used. Also reduce the buffer to 12 bytes, which is sufficient. Given that the range of rx ring indexes likely much smaller than the maximum range of a 32-bit signed integer, a smaller buffer could be used, with some further changes. But this change seems simple, robust, and has minimal stack overhead. Flagged by gcc-14: .../bnxt_debugfs.c: In function 'bnxt_debug_dev_init': drivers/net/ethernet/broadcom/bnxt/bnxt_debugfs.c:69:30: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size 10 [-Wformat-truncation=] 69 | snprintf(qname, 10, "%d", ring_idx); | ^~ In function 'debugfs_dim_ring_init', inlined from 'bnxt_debug_dev_init' at .../bnxt_debugfs.c:87:4: .../bnxt_debugfs.c:69:29: note: directive argument in the range [-2147483643, 2147483646] 69 | snprintf(qname, 10, "%d", ring_idx); | ^~~~ .../bnxt_debugfs.c:69:9: note: 'snprintf' output between 2 and 12 bytes into a destination of size 10 69 | snprintf(qname, 10, "%d", ring_idx); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Compile tested only Signed-off-by: Simon Horman <horms@kernel.org> Reviewed-by: Michael Chan <michael.chan@broadcom.com> Link: https://patch.msgid.link/20240813-bnxt-str-v2-2-872050a157e7@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
108 lines
2.3 KiB
C
108 lines
2.3 KiB
C
/* Broadcom NetXtreme-C/E network driver.
|
|
*
|
|
* Copyright (c) 2017-2018 Broadcom Limited
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/debugfs.h>
|
|
#include <linux/module.h>
|
|
#include <linux/pci.h>
|
|
#include "bnxt_hsi.h"
|
|
#include <linux/dim.h>
|
|
#include "bnxt.h"
|
|
#include "bnxt_debugfs.h"
|
|
|
|
static struct dentry *bnxt_debug_mnt;
|
|
|
|
static ssize_t debugfs_dim_read(struct file *filep,
|
|
char __user *buffer,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct dim *dim = filep->private_data;
|
|
int len;
|
|
char *buf;
|
|
|
|
if (*ppos)
|
|
return 0;
|
|
if (!dim)
|
|
return -ENODEV;
|
|
buf = kasprintf(GFP_KERNEL,
|
|
"state = %d\n" \
|
|
"profile_ix = %d\n" \
|
|
"mode = %d\n" \
|
|
"tune_state = %d\n" \
|
|
"steps_right = %d\n" \
|
|
"steps_left = %d\n" \
|
|
"tired = %d\n",
|
|
dim->state,
|
|
dim->profile_ix,
|
|
dim->mode,
|
|
dim->tune_state,
|
|
dim->steps_right,
|
|
dim->steps_left,
|
|
dim->tired);
|
|
if (!buf)
|
|
return -ENOMEM;
|
|
if (count < strlen(buf)) {
|
|
kfree(buf);
|
|
return -ENOSPC;
|
|
}
|
|
len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
|
|
kfree(buf);
|
|
return len;
|
|
}
|
|
|
|
static const struct file_operations debugfs_dim_fops = {
|
|
.owner = THIS_MODULE,
|
|
.open = simple_open,
|
|
.read = debugfs_dim_read,
|
|
};
|
|
|
|
static void debugfs_dim_ring_init(struct dim *dim, int ring_idx,
|
|
struct dentry *dd)
|
|
{
|
|
static char qname[12];
|
|
|
|
snprintf(qname, sizeof(qname), "%d", ring_idx);
|
|
debugfs_create_file(qname, 0600, dd, dim, &debugfs_dim_fops);
|
|
}
|
|
|
|
void bnxt_debug_dev_init(struct bnxt *bp)
|
|
{
|
|
const char *pname = pci_name(bp->pdev);
|
|
struct dentry *dir;
|
|
int i;
|
|
|
|
bp->debugfs_pdev = debugfs_create_dir(pname, bnxt_debug_mnt);
|
|
dir = debugfs_create_dir("dim", bp->debugfs_pdev);
|
|
|
|
/* create files for each rx ring */
|
|
for (i = 0; i < bp->cp_nr_rings; i++) {
|
|
struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
|
|
|
|
if (cpr && bp->bnapi[i]->rx_ring)
|
|
debugfs_dim_ring_init(&cpr->dim, i, dir);
|
|
}
|
|
}
|
|
|
|
void bnxt_debug_dev_exit(struct bnxt *bp)
|
|
{
|
|
if (bp) {
|
|
debugfs_remove_recursive(bp->debugfs_pdev);
|
|
bp->debugfs_pdev = NULL;
|
|
}
|
|
}
|
|
|
|
void bnxt_debug_init(void)
|
|
{
|
|
bnxt_debug_mnt = debugfs_create_dir("bnxt_en", NULL);
|
|
}
|
|
|
|
void bnxt_debug_exit(void)
|
|
{
|
|
debugfs_remove_recursive(bnxt_debug_mnt);
|
|
}
|