Re: [PATCH V6 net-next 1/7] net: hibmcge: Add debugfs supported in this module

Jijie Shao
2024-12-12T01:35:06Z

on 2024/12/11 22:00, Jakub Kicinski wrote:
> On Tue, 10 Dec 2024 21:48:49 +0800 Jijie Shao wrote:
>> + debugfs_create_devm_seqfile(dev, hbg_dbg_infos[i].name,
>> + root, hbg_dbg_infos[i].read);
> Like I said last time, if you devm_ the entire folder you don't have to
> devm_ each individual file. debugfs_remove_recursive() removes all files
> under specified directory.

Sorry, there's something wrong with the format of the last reply.

I think debugfs_create_devm_seqfile() is a better choice,
if not use it, I might need to code like so：

static const struct file_operations hbg_dbg_fops = {
.owner = THIS_MODULE,
...
};

static int hbg_dbg_file_init(struct hbg_priv *priv, u32 cmd, const char *name)
{
struct hbg_dbg_pri_data *data;

data = devm_kzalloc(&priv->pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;

data->priv = priv;
data->cmd = cmd;
debugfs_create_file(name, HBG_DBG_FILE_MODE,
priv->debugfs.root, data, &hbg_dbg_fops);

return 0;
}

int hbg_debugfs_init(struct hbg_priv *priv)
{
...
for (i = 0; i < ARRAY_SIZE(hbg_dbg_infos); i++) {
ret = hbg_dbg_file_init(priv, i, hbg_dbg_infos[i].name);
...
}

But use debugfs_create_devm_seqfile(), I only need:

void hbg_debugfs_init(struct hbg_priv *priv)
{
...
for (i = 0; i < ARRAY_SIZE(hbg_dbg_infos); i++)
debugfs_create_devm_seqfile(dev, hbg_dbg_infos[i].name,
root, hbg_dbg_infos[i].read);

Actually I think debugfs_create_devm_seqfile() is actually similar to hbg_dbg_file_init().
And in debugfs_create_devm_seqfile(), debugfs_create_file() is also called, and the code is simplified.

Thanks,
Jijie Shao