Skip to content

Commit

Permalink
Merge tag 'v6.5-rc1-sysctl-next' of git://git.kernel.org/pub/scm/linu…
Browse files Browse the repository at this point in the history
…x/kernel/git/mcgrof/linux

Pull sysctl updates from Luis Chamberlain:
 "The changes for sysctl are in line with prior efforts to stop usage of
  deprecated routines which incur recursion and also make it hard to
  remove the empty array element in each sysctl array declaration.

  The most difficult user to modify was parport which required a bit of
  re-thinking of how to declare shared sysctls there, Joel Granados has
  stepped up to the plate to do most of this work and eventual removal
  of register_sysctl_table(). That work ended up saving us about 1465
  bytes according to bloat-o-meter. Since we gained a few bloat-o-meter
  karma points I moved two rather small sysctl arrays from
  kernel/sysctl.c leaving us only two more sysctl arrays to move left.

  Most changes have been tested on linux-next for about a month. The
  last straggler patches are a minor parport fix, changes to the sysctl
  kernel selftest so to verify correctness and prevent regressions for
  the future change he made to provide an alternative solution for the
  special sysctl mount point target which was using the now deprecated
  sysctl child element.

  This is all prep work to now finally be able to remove the empty array
  element in all sysctl declarations / registrations which is expected
  to save us a bit of bytes all over the kernel. That work will be
  tested early after v6.5-rc1 is out"

* tag 'v6.5-rc1-sysctl-next' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux:
  sysctl: replace child with an enumeration
  sysctl: Remove debugging dump_stack
  test_sysclt: Test for registering a mount point
  test_sysctl: Add an option to prevent test skip
  test_sysctl: Add an unregister sysctl test
  test_sysctl: Group node sysctl test under one func
  test_sysctl: Fix test metadata getters
  parport: plug a sysctl register leak
  sysctl: move security keys sysctl registration to its own file
  sysctl: move umh sysctl registration to its own file
  signal: move show_unhandled_signals sysctl to its own file
  sysctl: remove empty dev table
  sysctl: Remove register_sysctl_table
  sysctl: Refactor base paths registrations
  sysctl: stop exporting register_sysctl_table
  parport: Removed sysctl related defines
  parport: Remove register_sysctl_table from parport_default_proc_register
  parport: Remove register_sysctl_table from parport_device_proc_register
  parport: Remove register_sysctl_table from parport_proc_register
  parport: Move magic number "15" to a define
  • Loading branch information
torvalds committed Jun 28, 2023
2 parents 4e3c09e + 2f2665c commit 6a8cbd9
Show file tree
Hide file tree
Showing 15 changed files with 351 additions and 434 deletions.
185 changes: 100 additions & 85 deletions drivers/parport/procfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
#define PARPORT_MAX_TIMESLICE_VALUE ((unsigned long) HZ)
#define PARPORT_MIN_SPINTIME_VALUE 1
#define PARPORT_MAX_SPINTIME_VALUE 1000
/*
* PARPORT_BASE_* is the size of the known parts of the sysctl path
* in dev/partport/%s/devices/%s. "dev/parport/"(12), "/devices/"(9
* and null char(1).
*/
#define PARPORT_BASE_PATH_SIZE 13
#define PARPORT_BASE_DEVICES_PATH_SIZE 22

static int do_active_device(struct ctl_table *table, int write,
void *result, size_t *lenp, loff_t *ppos)
Expand Down Expand Up @@ -236,13 +243,6 @@ do { \
return 0;
}

#define PARPORT_PORT_DIR(CHILD) { .procname = NULL, .mode = 0555, .child = CHILD }
#define PARPORT_PARPORT_DIR(CHILD) { .procname = "parport", \
.mode = 0555, .child = CHILD }
#define PARPORT_DEV_DIR(CHILD) { .procname = "dev", .mode = 0555, .child = CHILD }
#define PARPORT_DEVICES_ROOT_DIR { .procname = "devices", \
.mode = 0555, .child = NULL }

static const unsigned long parport_min_timeslice_value =
PARPORT_MIN_TIMESLICE_VALUE;

Expand All @@ -257,17 +257,16 @@ PARPORT_MAX_SPINTIME_VALUE;


struct parport_sysctl_table {
struct ctl_table_header *sysctl_header;
struct ctl_table_header *port_header;
struct ctl_table_header *devices_header;
struct ctl_table vars[12];
struct ctl_table device_dir[2];
struct ctl_table port_dir[2];
struct ctl_table parport_dir[2];
struct ctl_table dev_dir[2];
};

static const struct parport_sysctl_table parport_sysctl_template = {
.sysctl_header = NULL,
{
.port_header = NULL,
.devices_header = NULL,
{
{
.procname = "spintime",
.data = NULL,
Expand Down Expand Up @@ -305,7 +304,6 @@ static const struct parport_sysctl_table parport_sysctl_template = {
.mode = 0444,
.proc_handler = do_hardware_modes
},
PARPORT_DEVICES_ROOT_DIR,
#ifdef CONFIG_PARPORT_1284
{
.procname = "autoprobe",
Expand Down Expand Up @@ -355,18 +353,6 @@ static const struct parport_sysctl_table parport_sysctl_template = {
},
{}
},
{
PARPORT_PORT_DIR(NULL),
{}
},
{
PARPORT_PARPORT_DIR(NULL),
{}
},
{
PARPORT_DEV_DIR(NULL),
{}
}
};

struct parport_device_sysctl_table
Expand All @@ -393,32 +379,16 @@ parport_device_sysctl_template = {
.extra1 = (void*) &parport_min_timeslice_value,
.extra2 = (void*) &parport_max_timeslice_value
},
{}
},
{
{
.procname = NULL,
.data = NULL,
.maxlen = 0,
.mode = 0555,
.child = NULL
},
{}
},
{
PARPORT_DEVICES_ROOT_DIR,
{}
},
{
PARPORT_PORT_DIR(NULL),
{}
},
{
PARPORT_PARPORT_DIR(NULL),
{}
},
{
PARPORT_DEV_DIR(NULL),
{}
}
};

Expand Down Expand Up @@ -454,98 +424,143 @@ parport_default_sysctl_table = {
.extra2 = (void*) &parport_max_spintime_value
},
{}
},
{
{
.procname = "default",
.mode = 0555,
.child = parport_default_sysctl_table.vars
},
{}
},
{
PARPORT_PARPORT_DIR(parport_default_sysctl_table.default_dir),
{}
},
{
PARPORT_DEV_DIR(parport_default_sysctl_table.parport_dir),
{}
}
};


int parport_proc_register(struct parport *port)
{
struct parport_sysctl_table *t;
int i;
char *tmp_dir_path;
size_t tmp_path_len, port_name_len;
int bytes_written, i, err = 0;

t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL);
if (t == NULL)
return -ENOMEM;

t->device_dir[0].extra1 = port;

for (i = 0; i < 5; i++)
t->vars[0].data = &port->spintime;
for (i = 0; i < 5; i++) {
t->vars[i].extra1 = port;
t->vars[5 + i].extra2 = &port->probe_info[i];
}

t->vars[0].data = &port->spintime;
t->vars[5].child = t->device_dir;

for (i = 0; i < 5; i++)
t->vars[6 + i].extra2 = &port->probe_info[i];
port_name_len = strnlen(port->name, PARPORT_NAME_MAX_LEN);
/*
* Allocate a buffer for two paths: dev/parport/PORT and dev/parport/PORT/devices.
* We calculate for the second as that will give us enough for the first.
*/
tmp_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len;
tmp_dir_path = kzalloc(tmp_path_len, GFP_KERNEL);
if (!tmp_dir_path) {
err = -ENOMEM;
goto exit_free_t;
}

t->port_dir[0].procname = port->name;
bytes_written = snprintf(tmp_dir_path, tmp_path_len,
"dev/parport/%s/devices", port->name);
if (tmp_path_len <= bytes_written) {
err = -ENOENT;
goto exit_free_tmp_dir_path;
}
t->devices_header = register_sysctl(tmp_dir_path, t->device_dir);
if (t->devices_header == NULL) {
err = -ENOENT;
goto exit_free_tmp_dir_path;
}

t->port_dir[0].child = t->vars;
t->parport_dir[0].child = t->port_dir;
t->dev_dir[0].child = t->parport_dir;
tmp_path_len = PARPORT_BASE_PATH_SIZE + port_name_len;
bytes_written = snprintf(tmp_dir_path, tmp_path_len,
"dev/parport/%s", port->name);
if (tmp_path_len <= bytes_written) {
err = -ENOENT;
goto unregister_devices_h;
}

t->sysctl_header = register_sysctl_table(t->dev_dir);
if (t->sysctl_header == NULL) {
kfree(t);
t = NULL;
t->port_header = register_sysctl(tmp_dir_path, t->vars);
if (t->port_header == NULL) {
err = -ENOENT;
goto unregister_devices_h;
}

port->sysctl_table = t;

kfree(tmp_dir_path);
return 0;

unregister_devices_h:
unregister_sysctl_table(t->devices_header);

exit_free_tmp_dir_path:
kfree(tmp_dir_path);

exit_free_t:
kfree(t);
return err;
}

int parport_proc_unregister(struct parport *port)
{
if (port->sysctl_table) {
struct parport_sysctl_table *t = port->sysctl_table;
port->sysctl_table = NULL;
unregister_sysctl_table(t->sysctl_header);
unregister_sysctl_table(t->devices_header);
unregister_sysctl_table(t->port_header);
kfree(t);
}
return 0;
}

int parport_device_proc_register(struct pardevice *device)
{
int bytes_written, err = 0;
struct parport_device_sysctl_table *t;
struct parport * port = device->port;
size_t port_name_len, device_name_len, tmp_dir_path_len;
char *tmp_dir_path;

t = kmemdup(&parport_device_sysctl_template, sizeof(*t), GFP_KERNEL);
if (t == NULL)
return -ENOMEM;

t->dev_dir[0].child = t->parport_dir;
t->parport_dir[0].child = t->port_dir;
t->port_dir[0].procname = port->name;
t->port_dir[0].child = t->devices_root_dir;
t->devices_root_dir[0].child = t->device_dir;
port_name_len = strnlen(port->name, PARPORT_NAME_MAX_LEN);
device_name_len = strnlen(device->name, PATH_MAX);

/* Allocate a buffer for two paths: dev/parport/PORT/devices/DEVICE. */
tmp_dir_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len + device_name_len;
tmp_dir_path = kzalloc(tmp_dir_path_len, GFP_KERNEL);
if (!tmp_dir_path) {
err = -ENOMEM;
goto exit_free_t;
}

bytes_written = snprintf(tmp_dir_path, tmp_dir_path_len, "dev/parport/%s/devices/%s",
port->name, device->name);
if (tmp_dir_path_len <= bytes_written) {
err = -ENOENT;
goto exit_free_path;
}

t->device_dir[0].procname = device->name;
t->device_dir[0].child = t->vars;
t->vars[0].data = &device->timeslice;

t->sysctl_header = register_sysctl_table(t->dev_dir);
t->sysctl_header = register_sysctl(tmp_dir_path, t->vars);
if (t->sysctl_header == NULL) {
kfree(t);
t = NULL;
}
device->sysctl_table = t;

kfree(tmp_dir_path);
return 0;

exit_free_path:
kfree(tmp_dir_path);

exit_free_t:
kfree(t);

return err;
}

int parport_device_proc_unregister(struct pardevice *device)
Expand All @@ -564,7 +579,7 @@ static int __init parport_default_proc_register(void)
int ret;

parport_default_sysctl_table.sysctl_header =
register_sysctl_table(parport_default_sysctl_table.dev_dir);
register_sysctl("dev/parport/default", parport_default_sysctl_table.vars);
if (!parport_default_sysctl_table.sysctl_header)
return -ENOMEM;
ret = parport_bus_init();
Expand Down
2 changes: 1 addition & 1 deletion drivers/parport/share.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,
atomic_set(&tmp->ref_count, 1);
INIT_LIST_HEAD(&tmp->full_list);

name = kmalloc(15, GFP_KERNEL);
name = kmalloc(PARPORT_NAME_MAX_LEN, GFP_KERNEL);
if (!name) {
kfree(tmp);
return NULL;
Expand Down
Loading

0 comments on commit 6a8cbd9

Please sign in to comment.