Skip to content

Commit 6a8cbd9

Browse files
committed
Merge tag 'v6.5-rc1-sysctl-next' of git://git.kernel.org/pub/scm/linux/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
2 parents 4e3c09e + 2f2665c commit 6a8cbd9

File tree

15 files changed

+351
-434
lines changed

15 files changed

+351
-434
lines changed

Diff for: drivers/parport/procfs.c

+100-85
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
#define PARPORT_MAX_TIMESLICE_VALUE ((unsigned long) HZ)
3333
#define PARPORT_MIN_SPINTIME_VALUE 1
3434
#define PARPORT_MAX_SPINTIME_VALUE 1000
35+
/*
36+
* PARPORT_BASE_* is the size of the known parts of the sysctl path
37+
* in dev/partport/%s/devices/%s. "dev/parport/"(12), "/devices/"(9
38+
* and null char(1).
39+
*/
40+
#define PARPORT_BASE_PATH_SIZE 13
41+
#define PARPORT_BASE_DEVICES_PATH_SIZE 22
3542

3643
static int do_active_device(struct ctl_table *table, int write,
3744
void *result, size_t *lenp, loff_t *ppos)
@@ -236,13 +243,6 @@ do { \
236243
return 0;
237244
}
238245

239-
#define PARPORT_PORT_DIR(CHILD) { .procname = NULL, .mode = 0555, .child = CHILD }
240-
#define PARPORT_PARPORT_DIR(CHILD) { .procname = "parport", \
241-
.mode = 0555, .child = CHILD }
242-
#define PARPORT_DEV_DIR(CHILD) { .procname = "dev", .mode = 0555, .child = CHILD }
243-
#define PARPORT_DEVICES_ROOT_DIR { .procname = "devices", \
244-
.mode = 0555, .child = NULL }
245-
246246
static const unsigned long parport_min_timeslice_value =
247247
PARPORT_MIN_TIMESLICE_VALUE;
248248

@@ -257,17 +257,16 @@ PARPORT_MAX_SPINTIME_VALUE;
257257

258258

259259
struct parport_sysctl_table {
260-
struct ctl_table_header *sysctl_header;
260+
struct ctl_table_header *port_header;
261+
struct ctl_table_header *devices_header;
261262
struct ctl_table vars[12];
262263
struct ctl_table device_dir[2];
263-
struct ctl_table port_dir[2];
264-
struct ctl_table parport_dir[2];
265-
struct ctl_table dev_dir[2];
266264
};
267265

268266
static const struct parport_sysctl_table parport_sysctl_template = {
269-
.sysctl_header = NULL,
270-
{
267+
.port_header = NULL,
268+
.devices_header = NULL,
269+
{
271270
{
272271
.procname = "spintime",
273272
.data = NULL,
@@ -305,7 +304,6 @@ static const struct parport_sysctl_table parport_sysctl_template = {
305304
.mode = 0444,
306305
.proc_handler = do_hardware_modes
307306
},
308-
PARPORT_DEVICES_ROOT_DIR,
309307
#ifdef CONFIG_PARPORT_1284
310308
{
311309
.procname = "autoprobe",
@@ -355,18 +353,6 @@ static const struct parport_sysctl_table parport_sysctl_template = {
355353
},
356354
{}
357355
},
358-
{
359-
PARPORT_PORT_DIR(NULL),
360-
{}
361-
},
362-
{
363-
PARPORT_PARPORT_DIR(NULL),
364-
{}
365-
},
366-
{
367-
PARPORT_DEV_DIR(NULL),
368-
{}
369-
}
370356
};
371357

372358
struct parport_device_sysctl_table
@@ -393,32 +379,16 @@ parport_device_sysctl_template = {
393379
.extra1 = (void*) &parport_min_timeslice_value,
394380
.extra2 = (void*) &parport_max_timeslice_value
395381
},
382+
{}
396383
},
397384
{
398385
{
399386
.procname = NULL,
400387
.data = NULL,
401388
.maxlen = 0,
402389
.mode = 0555,
403-
.child = NULL
404390
},
405391
{}
406-
},
407-
{
408-
PARPORT_DEVICES_ROOT_DIR,
409-
{}
410-
},
411-
{
412-
PARPORT_PORT_DIR(NULL),
413-
{}
414-
},
415-
{
416-
PARPORT_PARPORT_DIR(NULL),
417-
{}
418-
},
419-
{
420-
PARPORT_DEV_DIR(NULL),
421-
{}
422392
}
423393
};
424394

@@ -454,98 +424,143 @@ parport_default_sysctl_table = {
454424
.extra2 = (void*) &parport_max_spintime_value
455425
},
456426
{}
457-
},
458-
{
459-
{
460-
.procname = "default",
461-
.mode = 0555,
462-
.child = parport_default_sysctl_table.vars
463-
},
464-
{}
465-
},
466-
{
467-
PARPORT_PARPORT_DIR(parport_default_sysctl_table.default_dir),
468-
{}
469-
},
470-
{
471-
PARPORT_DEV_DIR(parport_default_sysctl_table.parport_dir),
472-
{}
473427
}
474428
};
475429

476-
477430
int parport_proc_register(struct parport *port)
478431
{
479432
struct parport_sysctl_table *t;
480-
int i;
433+
char *tmp_dir_path;
434+
size_t tmp_path_len, port_name_len;
435+
int bytes_written, i, err = 0;
481436

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

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

488-
for (i = 0; i < 5; i++)
443+
t->vars[0].data = &port->spintime;
444+
for (i = 0; i < 5; i++) {
489445
t->vars[i].extra1 = port;
446+
t->vars[5 + i].extra2 = &port->probe_info[i];
447+
}
490448

491-
t->vars[0].data = &port->spintime;
492-
t->vars[5].child = t->device_dir;
493-
494-
for (i = 0; i < 5; i++)
495-
t->vars[6 + i].extra2 = &port->probe_info[i];
449+
port_name_len = strnlen(port->name, PARPORT_NAME_MAX_LEN);
450+
/*
451+
* Allocate a buffer for two paths: dev/parport/PORT and dev/parport/PORT/devices.
452+
* We calculate for the second as that will give us enough for the first.
453+
*/
454+
tmp_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len;
455+
tmp_dir_path = kzalloc(tmp_path_len, GFP_KERNEL);
456+
if (!tmp_dir_path) {
457+
err = -ENOMEM;
458+
goto exit_free_t;
459+
}
496460

497-
t->port_dir[0].procname = port->name;
461+
bytes_written = snprintf(tmp_dir_path, tmp_path_len,
462+
"dev/parport/%s/devices", port->name);
463+
if (tmp_path_len <= bytes_written) {
464+
err = -ENOENT;
465+
goto exit_free_tmp_dir_path;
466+
}
467+
t->devices_header = register_sysctl(tmp_dir_path, t->device_dir);
468+
if (t->devices_header == NULL) {
469+
err = -ENOENT;
470+
goto exit_free_tmp_dir_path;
471+
}
498472

499-
t->port_dir[0].child = t->vars;
500-
t->parport_dir[0].child = t->port_dir;
501-
t->dev_dir[0].child = t->parport_dir;
473+
tmp_path_len = PARPORT_BASE_PATH_SIZE + port_name_len;
474+
bytes_written = snprintf(tmp_dir_path, tmp_path_len,
475+
"dev/parport/%s", port->name);
476+
if (tmp_path_len <= bytes_written) {
477+
err = -ENOENT;
478+
goto unregister_devices_h;
479+
}
502480

503-
t->sysctl_header = register_sysctl_table(t->dev_dir);
504-
if (t->sysctl_header == NULL) {
505-
kfree(t);
506-
t = NULL;
481+
t->port_header = register_sysctl(tmp_dir_path, t->vars);
482+
if (t->port_header == NULL) {
483+
err = -ENOENT;
484+
goto unregister_devices_h;
507485
}
486+
508487
port->sysctl_table = t;
488+
489+
kfree(tmp_dir_path);
509490
return 0;
491+
492+
unregister_devices_h:
493+
unregister_sysctl_table(t->devices_header);
494+
495+
exit_free_tmp_dir_path:
496+
kfree(tmp_dir_path);
497+
498+
exit_free_t:
499+
kfree(t);
500+
return err;
510501
}
511502

512503
int parport_proc_unregister(struct parport *port)
513504
{
514505
if (port->sysctl_table) {
515506
struct parport_sysctl_table *t = port->sysctl_table;
516507
port->sysctl_table = NULL;
517-
unregister_sysctl_table(t->sysctl_header);
508+
unregister_sysctl_table(t->devices_header);
509+
unregister_sysctl_table(t->port_header);
518510
kfree(t);
519511
}
520512
return 0;
521513
}
522514

523515
int parport_device_proc_register(struct pardevice *device)
524516
{
517+
int bytes_written, err = 0;
525518
struct parport_device_sysctl_table *t;
526519
struct parport * port = device->port;
520+
size_t port_name_len, device_name_len, tmp_dir_path_len;
521+
char *tmp_dir_path;
527522

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

532-
t->dev_dir[0].child = t->parport_dir;
533-
t->parport_dir[0].child = t->port_dir;
534-
t->port_dir[0].procname = port->name;
535-
t->port_dir[0].child = t->devices_root_dir;
536-
t->devices_root_dir[0].child = t->device_dir;
527+
port_name_len = strnlen(port->name, PARPORT_NAME_MAX_LEN);
528+
device_name_len = strnlen(device->name, PATH_MAX);
529+
530+
/* Allocate a buffer for two paths: dev/parport/PORT/devices/DEVICE. */
531+
tmp_dir_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len + device_name_len;
532+
tmp_dir_path = kzalloc(tmp_dir_path_len, GFP_KERNEL);
533+
if (!tmp_dir_path) {
534+
err = -ENOMEM;
535+
goto exit_free_t;
536+
}
537+
538+
bytes_written = snprintf(tmp_dir_path, tmp_dir_path_len, "dev/parport/%s/devices/%s",
539+
port->name, device->name);
540+
if (tmp_dir_path_len <= bytes_written) {
541+
err = -ENOENT;
542+
goto exit_free_path;
543+
}
537544

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

542-
t->sysctl_header = register_sysctl_table(t->dev_dir);
547+
t->sysctl_header = register_sysctl(tmp_dir_path, t->vars);
543548
if (t->sysctl_header == NULL) {
544549
kfree(t);
545550
t = NULL;
546551
}
547552
device->sysctl_table = t;
553+
554+
kfree(tmp_dir_path);
548555
return 0;
556+
557+
exit_free_path:
558+
kfree(tmp_dir_path);
559+
560+
exit_free_t:
561+
kfree(t);
562+
563+
return err;
549564
}
550565

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

566581
parport_default_sysctl_table.sysctl_header =
567-
register_sysctl_table(parport_default_sysctl_table.dev_dir);
582+
register_sysctl("dev/parport/default", parport_default_sysctl_table.vars);
568583
if (!parport_default_sysctl_table.sysctl_header)
569584
return -ENOMEM;
570585
ret = parport_bus_init();

Diff for: drivers/parport/share.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,
467467
atomic_set(&tmp->ref_count, 1);
468468
INIT_LIST_HEAD(&tmp->full_list);
469469

470-
name = kmalloc(15, GFP_KERNEL);
470+
name = kmalloc(PARPORT_NAME_MAX_LEN, GFP_KERNEL);
471471
if (!name) {
472472
kfree(tmp);
473473
return NULL;

0 commit comments

Comments
 (0)