From: Joel Granados <j.granados@samsung.com>
To: <mcgrof@kernel.org>
Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>,
Iurii Zaikin <yzaikin@google.com>,
Kees Cook <keescook@chromium.org>, <linux-kernel@vger.kernel.org>,
<linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH 3/6] parport: Remove register_sysctl_table from parport_device_proc_register
Date: Mon, 15 May 2023 21:10:19 +0200 [thread overview]
Message-ID: <20230515191019.cggga6c7yhnjzj4a@localhost> (raw)
In-Reply-To: <20230515071446.2277292-4-j.granados@samsung.com>
[-- Attachment #1: Type: text/plain, Size: 3692 bytes --]
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@samsung.com>
> ---
> 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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
next prev parent reply other threads:[~2023-05-15 19:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20230515071448eucas1p111c55b7078f1541f487c9dfb1a9f9c15@eucas1p1.samsung.com>
2023-05-15 7:14 ` [PATCH 0/6] sysctl: Remove register_sysctl_table from parport Joel Granados
[not found] ` <CGME20230515071449eucas1p172217753f35fed55c4d2f0a419e258dd@eucas1p1.samsung.com>
2023-05-15 7:14 ` [PATCH 1/6] parport: Move magic number "15" to a define Joel Granados
[not found] ` <CGME20230515071450eucas1p1625a8639e2b0edf47e41126801d4cbb8@eucas1p1.samsung.com>
2023-05-15 7:14 ` [PATCH 2/6] parport: Remove register_sysctl_table from parport_proc_register Joel Granados
2023-05-16 4:17 ` Luis Chamberlain
2023-05-16 14:31 ` Joel Granados
2023-05-16 16:12 ` Joel Granados
2023-05-16 21:49 ` Luis Chamberlain
[not found] ` <CGME20230515071452eucas1p1d535f6636b45c193b6b24fa59ff100a6@eucas1p1.samsung.com>
2023-05-15 7:14 ` [PATCH 3/6] parport: Remove register_sysctl_table from parport_device_proc_register Joel Granados
[not found] ` <CGME20230515192630eucas1p2c9bf0ffa8ddc2d0bcf9a9818c6ecd6a8@eucas1p2.samsung.com>
2023-05-15 19:10 ` Joel Granados [this message]
[not found] ` <CGME20230515071454eucas1p2ae422c4bad233cd6170dce9e7f8304d9@eucas1p2.samsung.com>
2023-05-15 7:14 ` [PATCH 4/6] parport: Remove register_sysctl_table from parport_default_proc_register Joel Granados
[not found] ` <CGME20230515071456eucas1p1e92a011498b7f3ca2e02cdc8f0d39415@eucas1p1.samsung.com>
2023-05-15 7:14 ` [PATCH 5/6] parport: Removed sysctl related defines Joel Granados
[not found] ` <CGME20230515071457eucas1p105a2dba9f4741cd6fe495bcf527d664d@eucas1p1.samsung.com>
2023-05-15 7:14 ` [PATCH 6/6] sysctl: stop exporting register_sysctl_table Joel Granados
2023-05-15 20:24 ` [PATCH 0/6] sysctl: Remove register_sysctl_table from parport Luis Chamberlain
2023-05-16 14:06 ` Joel Granados
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230515191019.cggga6c7yhnjzj4a@localhost \
--to=j.granados@samsung.com \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=sudipm.mukherjee@gmail.com \
--cc=yzaikin@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).