On Mon, May 15, 2023 at 09:14:43AM +0200, Joel Granados wrote: > 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@xxxxxxxxxxx> > --- > drivers/parport/procfs.c | 57 +++++++++++++++++++++++----------------- > 1 file changed, 33 insertions(+), 24 deletions(-) > > diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c > index 53ae5cb98190..902547eb045c 100644 > --- a/drivers/parport/procfs.c > +++ b/drivers/parport/procfs.c > @@ -384,6 +384,7 @@ parport_device_sysctl_template = { > .extra1 = (void*) &parport_min_timeslice_value, > .extra2 = (void*) &parport_max_timeslice_value > }, > + {} > }, > { > { > @@ -394,22 +395,6 @@ parport_device_sysctl_template = { > .child = NULL > }, > {} > - }, > - { > - PARPORT_DEVICES_ROOT_DIR, > - {} > - }, > - { > - PARPORT_PORT_DIR(NULL), > - {} > - }, > - { > - PARPORT_PARPORT_DIR(NULL), > - {} > - }, > - { > - PARPORT_DEV_DIR(NULL), > - {} > } > }; > > @@ -547,30 +532,54 @@ int parport_proc_unregister(struct parport *port) > > int parport_device_proc_register(struct pardevice *device) > { > + int 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 = kmalloc(tmp_dir_path_len, GFP_KERNEL); > + if (!tmp_dir_path) { > + err = -ENOMEM; > + goto exit_free_t; > + } > + > + if (tmp_dir_path_len > + <= snprintf(tmp_dir_path, tmp_dir_path_len, "dev/parport/%s/devices/%s", > + port->name, device->name)) { > + 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; In the paprport_proc_register there is the same logic where we do not return error code on error. Additionally, noone checks the return values of parport_proc_register nor parport_device_proc_register. Should we just change these to void and be done with it? Or is it better to change parport/share.c to take care of the error codes? I realized this after some comments from 0-day. Best > } > device->sysctl_table = t; > + > + kfree(tmp_dir_path); > return 0; > + > +exit_free_path: > + kfree(tmp_dir_path); > + > +exit_free_t: > + kfree(t); > + t = NULL; > + > + return err; > } > > int parport_device_proc_unregister(struct pardevice *device) > -- > 2.30.2 > -- Joel Granados
Attachment:
signature.asc
Description: PGP signature