Skip to content

Commit 9381093

Browse files
Joelgranadosmcgrof
authored andcommitted
parport: Remove register_sysctl_table from parport_proc_register
This is part of the general push to deprecate register_sysctl_paths and register_sysctl_table. Register dev/parport/PORTNAME and dev/parport/PORTNAME/devices. Temporary allocation for name is freed at the end of the function. Remove all the struct elements that are no longer used in the parport_device_sysctl_template struct. Add parport specific defines that hide the base path sizes. To make sure the resulting directory structure did not change we made sure that `find /proc/sys/dev/ | sha1sum` was the same before and after the change. Signed-off-by: Joel Granados <j.granados@samsung.com> Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/r/202305150948.pHgIh7Ql-lkp@intel.com/ Reported-by: Dan Carpenter <error27@gmail.com> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
1 parent 7c0bf4d commit 9381093

1 file changed

Lines changed: 60 additions & 31 deletions

File tree

drivers/parport/procfs.c

Lines changed: 60 additions & 31 deletions
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)
@@ -260,9 +267,6 @@ struct parport_sysctl_table {
260267
struct ctl_table_header *sysctl_header;
261268
struct ctl_table vars[12];
262269
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];
266270
};
267271

268272
static const struct parport_sysctl_table parport_sysctl_template = {
@@ -305,7 +309,6 @@ static const struct parport_sysctl_table parport_sysctl_template = {
305309
.mode = 0444,
306310
.proc_handler = do_hardware_modes
307311
},
308-
PARPORT_DEVICES_ROOT_DIR,
309312
#ifdef CONFIG_PARPORT_1284
310313
{
311314
.procname = "autoprobe",
@@ -355,18 +358,6 @@ static const struct parport_sysctl_table parport_sysctl_template = {
355358
},
356359
{}
357360
},
358-
{
359-
PARPORT_PORT_DIR(NULL),
360-
{}
361-
},
362-
{
363-
PARPORT_PARPORT_DIR(NULL),
364-
{}
365-
},
366-
{
367-
PARPORT_DEV_DIR(NULL),
368-
{}
369-
}
370361
};
371362

372363
struct parport_device_sysctl_table
@@ -473,40 +464,78 @@ parport_default_sysctl_table = {
473464
}
474465
};
475466

476-
477467
int parport_proc_register(struct parport *port)
478468
{
479469
struct parport_sysctl_table *t;
480-
int i;
470+
struct ctl_table_header *devices_h;
471+
char *tmp_dir_path;
472+
size_t tmp_path_len, port_name_len;
473+
int bytes_written, i, err = 0;
481474

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

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

488-
for (i = 0; i < 5; i++)
481+
t->vars[0].data = &port->spintime;
482+
for (i = 0; i < 5; i++) {
489483
t->vars[i].extra1 = port;
484+
t->vars[5 + i].extra2 = &port->probe_info[i];
485+
}
490486

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];
487+
port_name_len = strnlen(port->name, PARPORT_NAME_MAX_LEN);
488+
/*
489+
* Allocate a buffer for two paths: dev/parport/PORT and dev/parport/PORT/devices.
490+
* We calculate for the second as that will give us enough for the first.
491+
*/
492+
tmp_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len;
493+
tmp_dir_path = kzalloc(tmp_path_len, GFP_KERNEL);
494+
if (!tmp_dir_path) {
495+
err = -ENOMEM;
496+
goto exit_free_t;
497+
}
496498

497-
t->port_dir[0].procname = port->name;
499+
bytes_written = snprintf(tmp_dir_path, tmp_path_len,
500+
"dev/parport/%s/devices", port->name);
501+
if (tmp_path_len <= bytes_written) {
502+
err = -ENOENT;
503+
goto exit_free_tmp_dir_path;
504+
}
505+
devices_h = register_sysctl(tmp_dir_path, t->device_dir);
506+
if (devices_h == NULL) {
507+
err = -ENOENT;
508+
goto exit_free_tmp_dir_path;
509+
}
498510

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;
511+
tmp_path_len = PARPORT_BASE_PATH_SIZE + port_name_len;
512+
bytes_written = snprintf(tmp_dir_path, tmp_path_len,
513+
"dev/parport/%s", port->name);
514+
if (tmp_path_len <= bytes_written) {
515+
err = -ENOENT;
516+
goto unregister_devices_h;
517+
}
502518

503-
t->sysctl_header = register_sysctl_table(t->dev_dir);
519+
t->sysctl_header = register_sysctl(tmp_dir_path, t->vars);
504520
if (t->sysctl_header == NULL) {
505-
kfree(t);
506-
t = NULL;
521+
err = -ENOENT;
522+
goto unregister_devices_h;
507523
}
524+
508525
port->sysctl_table = t;
526+
527+
kfree(tmp_dir_path);
509528
return 0;
529+
530+
unregister_devices_h:
531+
unregister_sysctl_table(devices_h);
532+
533+
exit_free_tmp_dir_path:
534+
kfree(tmp_dir_path);
535+
536+
exit_free_t:
537+
kfree(t);
538+
return err;
510539
}
511540

512541
int parport_proc_unregister(struct parport *port)

0 commit comments

Comments
 (0)