Skip to content

Commit 4199a64

Browse files
Joelgranadosmcgrof
authored andcommitted
parport: Remove register_sysctl_table from parport_device_proc_register
This is part of the general push to deprecate register_sysctl_paths and register_sysctl_table. We use a temp allocation to include both port and device name in proc. Allocated mem is freed at the end. The unused parport_device_sysctl_template struct elements that are not used are removed. 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 9381093 commit 4199a64

1 file changed

Lines changed: 32 additions & 24 deletions

File tree

drivers/parport/procfs.c

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ parport_device_sysctl_template = {
384384
.extra1 = (void*) &parport_min_timeslice_value,
385385
.extra2 = (void*) &parport_max_timeslice_value
386386
},
387+
{}
387388
},
388389
{
389390
{
@@ -394,22 +395,6 @@ parport_device_sysctl_template = {
394395
.child = NULL
395396
},
396397
{}
397-
},
398-
{
399-
PARPORT_DEVICES_ROOT_DIR,
400-
{}
401-
},
402-
{
403-
PARPORT_PORT_DIR(NULL),
404-
{}
405-
},
406-
{
407-
PARPORT_PARPORT_DIR(NULL),
408-
{}
409-
},
410-
{
411-
PARPORT_DEV_DIR(NULL),
412-
{}
413398
}
414399
};
415400

@@ -551,30 +536,53 @@ int parport_proc_unregister(struct parport *port)
551536

552537
int parport_device_proc_register(struct pardevice *device)
553538
{
539+
int bytes_written, err = 0;
554540
struct parport_device_sysctl_table *t;
555541
struct parport * port = device->port;
542+
size_t port_name_len, device_name_len, tmp_dir_path_len;
543+
char *tmp_dir_path;
556544

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

561-
t->dev_dir[0].child = t->parport_dir;
562-
t->parport_dir[0].child = t->port_dir;
563-
t->port_dir[0].procname = port->name;
564-
t->port_dir[0].child = t->devices_root_dir;
565-
t->devices_root_dir[0].child = t->device_dir;
549+
port_name_len = strnlen(port->name, PARPORT_NAME_MAX_LEN);
550+
device_name_len = strnlen(device->name, PATH_MAX);
551+
552+
/* Allocate a buffer for two paths: dev/parport/PORT/devices/DEVICE. */
553+
tmp_dir_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len + device_name_len;
554+
tmp_dir_path = kzalloc(tmp_dir_path_len, GFP_KERNEL);
555+
if (!tmp_dir_path) {
556+
err = -ENOMEM;
557+
goto exit_free_t;
558+
}
559+
560+
bytes_written = snprintf(tmp_dir_path, tmp_dir_path_len, "dev/parport/%s/devices/%s",
561+
port->name, device->name);
562+
if (tmp_dir_path_len <= bytes_written) {
563+
err = -ENOENT;
564+
goto exit_free_path;
565+
}
566566

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

571-
t->sysctl_header = register_sysctl_table(t->dev_dir);
569+
t->sysctl_header = register_sysctl(tmp_dir_path, t->vars);
572570
if (t->sysctl_header == NULL) {
573571
kfree(t);
574572
t = NULL;
575573
}
576574
device->sysctl_table = t;
575+
576+
kfree(tmp_dir_path);
577577
return 0;
578+
579+
exit_free_path:
580+
kfree(tmp_dir_path);
581+
582+
exit_free_t:
583+
kfree(t);
584+
585+
return err;
578586
}
579587

580588
int parport_device_proc_unregister(struct pardevice *device)

0 commit comments

Comments
 (0)