diff options
author | Breno Leitao <leitao@debian.org> | 2025-02-06 03:05:54 -0800 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2025-02-10 15:04:18 +0000 |
commit | 563fe939a81ab08198b78dc8451ef3090969f30b (patch) | |
tree | d45c4d99f1a3370738db64c0f81f5117acac2f00 /drivers/net/netconsole.c | |
parent | 4205f6495eea62c7f4042346e045e4ac706e1830 (diff) |
netconsole: Helper to count number of used entries
Add a helper function nr_extradata_entries() to count the number of used
extradata entries in a netconsole target. This refactors the duplicate
code for counting entries into a single function, which will be reused
by upcoming CPU sysdata changes.
The helper uses list_count_nodes() to count the number of children in
the userdata group configfs hierarchy.
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/netconsole.c')
-rw-r--r-- | drivers/net/netconsole.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 7f05c7f74c31..15daaba65c88 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -662,6 +662,16 @@ out_unlock: return ret; } +/* Count number of entries we have in extradata. + * This is important because the extradata_complete only supports + * MAX_EXTRADATA_ITEMS entries. Before enabling any new {user,sys}data + * feature, number of entries needs to checked for available space. + */ +static size_t count_extradata_entries(struct netconsole_target *nt) +{ + return list_count_nodes(&nt->userdata_group.cg_children); +} + static ssize_t remote_mac_store(struct config_item *item, const char *buf, size_t count) { @@ -811,15 +821,13 @@ static struct config_item *userdatum_make_item(struct config_group *group, struct netconsole_target *nt; struct userdatum *udm; struct userdata *ud; - size_t child_count; if (strlen(name) > MAX_EXTRADATA_NAME_LEN) return ERR_PTR(-ENAMETOOLONG); ud = to_userdata(&group->cg_item); nt = userdata_to_target(ud); - child_count = list_count_nodes(&nt->userdata_group.cg_children); - if (child_count >= MAX_EXTRADATA_ITEMS) + if (count_extradata_entries(nt) >= MAX_EXTRADATA_ITEMS) return ERR_PTR(-ENOSPC); udm = kzalloc(sizeof(*udm), GFP_KERNEL); |