Skip to content

Commit b8cbc08

Browse files
Joelgranadosmcgrof
authored andcommitted
sysctl: Remove register_sysctl_table
This is part of the general push to deprecate register_sysctl_paths and register_sysctl_table. After removing all the calling functions, we remove both the register_sysctl_table function and the documentation check that appeared in check-sysctl-docs awk script. We save 595 bytes with this change: ./scripts/bloat-o-meter vmlinux.1.refactor-base-paths vmlinux.2.remove-sysctl-table add/remove: 2/8 grow/shrink: 1/0 up/down: 1154/-1749 (-595) Function old new delta count_subheaders - 983 +983 unregister_sysctl_table 29 184 +155 __pfx_count_subheaders - 16 +16 __pfx_unregister_sysctl_table.part 16 - -16 __pfx_register_leaf_sysctl_tables.constprop 16 - -16 __pfx_count_subheaders.part 16 - -16 __pfx___register_sysctl_base 16 - -16 unregister_sysctl_table.part 136 - -136 __register_sysctl_base 478 - -478 register_leaf_sysctl_tables.constprop 524 - -524 count_subheaders.part 547 - -547 Total: Before=21257652, After=21257057, chg -0.00% [mcgrof: remove register_leaf_sysctl_tables and append_path too and add bloat-o-meter stats] Signed-off-by: Joel Granados <j.granados@samsung.com> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> Acked-by: Christian Brauner <brauner@kernel.org>
1 parent 2f5edd0 commit b8cbc08

2 files changed

Lines changed: 0 additions & 169 deletions

File tree

fs/proc/proc_sysctl.c

Lines changed: 0 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,19 +1466,6 @@ void __init __register_sysctl_init(const char *path, struct ctl_table *table,
14661466
kmemleak_not_leak(hdr);
14671467
}
14681468

1469-
static char *append_path(const char *path, char *pos, const char *name)
1470-
{
1471-
int namelen;
1472-
namelen = strlen(name);
1473-
if (((pos - path) + namelen + 2) >= PATH_MAX)
1474-
return NULL;
1475-
memcpy(pos, name, namelen);
1476-
pos[namelen] = '/';
1477-
pos[namelen + 1] = '\0';
1478-
pos += namelen + 1;
1479-
return pos;
1480-
}
1481-
14821469
static int count_subheaders(struct ctl_table *table)
14831470
{
14841471
int has_files = 0;
@@ -1498,152 +1485,6 @@ static int count_subheaders(struct ctl_table *table)
14981485
return nr_subheaders + has_files;
14991486
}
15001487

1501-
static int register_leaf_sysctl_tables(const char *path, char *pos,
1502-
struct ctl_table_header ***subheader, struct ctl_table_set *set,
1503-
struct ctl_table *table)
1504-
{
1505-
struct ctl_table *ctl_table_arg = NULL;
1506-
struct ctl_table *entry, *files;
1507-
int nr_files = 0;
1508-
int nr_dirs = 0;
1509-
int err = -ENOMEM;
1510-
1511-
list_for_each_table_entry(entry, table) {
1512-
if (entry->child)
1513-
nr_dirs++;
1514-
else
1515-
nr_files++;
1516-
}
1517-
1518-
files = table;
1519-
/* If there are mixed files and directories we need a new table */
1520-
if (nr_dirs && nr_files) {
1521-
struct ctl_table *new;
1522-
files = kcalloc(nr_files + 1, sizeof(struct ctl_table),
1523-
GFP_KERNEL);
1524-
if (!files)
1525-
goto out;
1526-
1527-
ctl_table_arg = files;
1528-
new = files;
1529-
1530-
list_for_each_table_entry(entry, table) {
1531-
if (entry->child)
1532-
continue;
1533-
*new = *entry;
1534-
new++;
1535-
}
1536-
}
1537-
1538-
/* Register everything except a directory full of subdirectories */
1539-
if (nr_files || !nr_dirs) {
1540-
struct ctl_table_header *header;
1541-
header = __register_sysctl_table(set, path, files);
1542-
if (!header) {
1543-
kfree(ctl_table_arg);
1544-
goto out;
1545-
}
1546-
1547-
/* Remember if we need to free the file table */
1548-
header->ctl_table_arg = ctl_table_arg;
1549-
**subheader = header;
1550-
(*subheader)++;
1551-
}
1552-
1553-
/* Recurse into the subdirectories. */
1554-
list_for_each_table_entry(entry, table) {
1555-
char *child_pos;
1556-
1557-
if (!entry->child)
1558-
continue;
1559-
1560-
err = -ENAMETOOLONG;
1561-
child_pos = append_path(path, pos, entry->procname);
1562-
if (!child_pos)
1563-
goto out;
1564-
1565-
err = register_leaf_sysctl_tables(path, child_pos, subheader,
1566-
set, entry->child);
1567-
pos[0] = '\0';
1568-
if (err)
1569-
goto out;
1570-
}
1571-
err = 0;
1572-
out:
1573-
/* On failure our caller will unregister all registered subheaders */
1574-
return err;
1575-
}
1576-
1577-
/**
1578-
* register_sysctl_table - register a sysctl table hierarchy
1579-
* @table: the top-level table structure
1580-
*
1581-
* Register a sysctl table hierarchy. @table should be a filled in ctl_table
1582-
* array. A completely 0 filled entry terminates the table.
1583-
* We are slowly deprecating this call so avoid its use.
1584-
*/
1585-
static struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1586-
{
1587-
struct ctl_table *ctl_table_arg = table;
1588-
int nr_subheaders = count_subheaders(table);
1589-
struct ctl_table_header *header = NULL, **subheaders, **subheader;
1590-
char *new_path, *pos;
1591-
1592-
pos = new_path = kmalloc(PATH_MAX, GFP_KERNEL);
1593-
if (!new_path)
1594-
return NULL;
1595-
1596-
pos[0] = '\0';
1597-
while (table->procname && table->child && !table[1].procname) {
1598-
pos = append_path(new_path, pos, table->procname);
1599-
if (!pos)
1600-
goto out;
1601-
table = table->child;
1602-
}
1603-
if (nr_subheaders == 1) {
1604-
header = __register_sysctl_table(&sysctl_table_root.default_set, new_path, table);
1605-
if (header)
1606-
header->ctl_table_arg = ctl_table_arg;
1607-
} else {
1608-
header = kzalloc(sizeof(*header) +
1609-
sizeof(*subheaders)*nr_subheaders, GFP_KERNEL);
1610-
if (!header)
1611-
goto out;
1612-
1613-
subheaders = (struct ctl_table_header **) (header + 1);
1614-
subheader = subheaders;
1615-
header->ctl_table_arg = ctl_table_arg;
1616-
1617-
if (register_leaf_sysctl_tables(new_path, pos, &subheader,
1618-
&sysctl_table_root.default_set, table))
1619-
goto err_register_leaves;
1620-
}
1621-
1622-
out:
1623-
kfree(new_path);
1624-
return header;
1625-
1626-
err_register_leaves:
1627-
while (subheader > subheaders) {
1628-
struct ctl_table_header *subh = *(--subheader);
1629-
struct ctl_table *table = subh->ctl_table_arg;
1630-
unregister_sysctl_table(subh);
1631-
kfree(table);
1632-
}
1633-
kfree(header);
1634-
header = NULL;
1635-
goto out;
1636-
}
1637-
1638-
int __register_sysctl_base(struct ctl_table *base_table)
1639-
{
1640-
struct ctl_table_header *hdr;
1641-
1642-
hdr = register_sysctl_table(base_table);
1643-
kmemleak_not_leak(hdr);
1644-
return 0;
1645-
}
1646-
16471488
static void put_links(struct ctl_table_header *header)
16481489
{
16491490
struct ctl_table_set *root_set = &sysctl_table_root.default_set;

scripts/check-sysctl-docs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,6 @@ curtable && /\.procname[\t ]*=[\t ]*".+"/ {
146146
children[curtable][curentry] = child
147147
}
148148

149-
/register_sysctl_table\(.*\)/ {
150-
match($0, /register_sysctl_table\(([^)]+)\)/, tables)
151-
if (debug) print "Registering table " tables[1]
152-
if (children[tables[1]][table]) {
153-
for (entry in entries[children[tables[1]][table]]) {
154-
printentry(entry)
155-
}
156-
}
157-
}
158-
159149
END {
160150
for (entry in documented) {
161151
if (!seen[entry]) {

0 commit comments

Comments
 (0)