From nobody Tue Feb 10 01:15:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CEFCC77B75 for ; Mon, 15 May 2023 07:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240661AbjEOHPE (ORCPT ); Mon, 15 May 2023 03:15:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239050AbjEOHOy (ORCPT ); Mon, 15 May 2023 03:14:54 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D00C5E74 for ; Mon, 15 May 2023 00:14:52 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230515071451euoutp015328c38d42b6fe82322f185dc77f7da4~fP8LJaqfV1779217792euoutp018 for ; Mon, 15 May 2023 07:14:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230515071451euoutp015328c38d42b6fe82322f185dc77f7da4~fP8LJaqfV1779217792euoutp018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1684134891; bh=PDU9jqEs8417s9sxrU7lh3cS+FBJYDs7iRwM4PSqxjk=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=NZvcG6txfKlALnmoGaVSt9TgWjC4sNfXlVEjymrJmfLZjYd3mSP3OWsWHv3JX7adV Cy5aHSw67LOmXoIdjOfmJkyQFT0SKMfNLImZMI1VeKgRX85LPFjvPZltVgV2YkOVUu IbaIoRFeAPtfnuzKSSz8hCgRSj5wEBCkTKVrFvxQ= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20230515071451eucas1p132717dca0137ef15506aa989d1fe48cc~fP8K1UiQL1417814178eucas1p1q; Mon, 15 May 2023 07:14:51 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id BC.71.42423.AEBD1646; Mon, 15 May 2023 08:14:51 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230515071450eucas1p1625a8639e2b0edf47e41126801d4cbb8~fP8Kf7ZEv0313203132eucas1p1j; Mon, 15 May 2023 07:14:50 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230515071450eusmtrp2d0828b702e0a9f3c6141673ac46d8aa5~fP8KfIRdp2610526105eusmtrp2H; Mon, 15 May 2023 07:14:50 +0000 (GMT) X-AuditID: cbfec7f2-a51ff7000002a5b7-8e-6461dbea09a9 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id CC.D9.14344.AEBD1646; Mon, 15 May 2023 08:14:50 +0100 (BST) Received: from CAMSVWEXC02.scsc.local (unknown [106.1.227.72]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230515071450eusmtip19478c10b8a19fdd7ccc945b06d0b0a33~fP8KQPBLz3240832408eusmtip1E; Mon, 15 May 2023 07:14:50 +0000 (GMT) Received: from localhost (106.110.32.133) by CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 May 2023 08:14:49 +0100 From: Joel Granados To: CC: Sudip Mukherjee , Iurii Zaikin , Kees Cook , , , Joel Granados Subject: [PATCH 2/6] parport: Remove register_sysctl_table from parport_proc_register Date: Mon, 15 May 2023 09:14:42 +0200 Message-ID: <20230515071446.2277292-3-j.granados@samsung.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230515071446.2277292-1-j.granados@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [106.110.32.133] X-ClientProxiedBy: CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) To CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplleLIzCtJLcpLzFFi42LZduzned3XtxNTDGZ9ZbQ4051rsWfvSRaL y7vmsFncmPCU0eLA6SnMFst2+jmwecxuuMjisXPWXXaPBZtKPTat6mTz+LxJLoA1issmJTUn syy1SN8ugSvjxru7bAWTVSo65u5nb2DcIdvFyMkhIWAiceXiR2YQW0hgBaPE5zsCXYxcQPYX Rol1U9exQDifGSV+/n7ACtPx4ctidojEckaJBxPOscNVbX4wmxXC2cIo8XJhPyNIC5uAjsT5 N3fAlogIiEucOL2ZEaSIWeApo8Tcf71MIAlhgXCJ0x/uAXVzcLAIqEocP+gBEuYVsJVo6LgP tVpeou36dLCZnAJ2Euv2H2WCqBGUODnzCQuIzQxU07x1NjOELSFx8MULZoheJYmvb3qh5tRK nNpyiwnkBgmBBxwSp98sZYNIuEjsu7SYEcIWlnh1fAs7hC0j8X/nfKiGyYwS+/99YIdwVjNK LGv8ygRRZS3RcuUJVIejxOr1d9lBvpEQ4JO48VYQ4iI+iUnbpjNDhHklOtqEJjCqzELywywk P8xC8sMCRuZVjOKppcW56anFhnmp5XrFibnFpXnpesn5uZsYgSnm9L/jn3Ywzn31Ue8QIxMH 4yFGCQ5mJRHe9pnxKUK8KYmVValF+fFFpTmpxYcYpTlYlMR5tW1PJgsJpCeWpGanphakFsFk mTg4pRqYnFdqdJ70XW8/14i9aA/PY6dZ91ZEfZErfnC8geNmRv5h4yLNVTPzq1bmS3l+u9LS dubEMlZ93krWqzLLr+il6PBee73oYkbhyr5yT6PbV8yr9eSX7F2xx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+9fF8cxR Pi0uKFLP7zTVO+22x/HZi5ueKnx6sKK+foHP+qX5wf5m57aFuDX/WSqb8SWy4PLNBYfCdkgV PDtiYL9kYiC/a2eQe8zlD2enTDhhb2VY++NoqptIe8Gysr7tlivdA2uCbZ6fmiLGNOvG49Ar Xb/EWe5oqx44eD6zw7Xtfeyb58WCb5uPhjCl9iZzli199FElflVJTn/10wscQsUfjLN/xtis 23ztDtM5S/YUn9ofhjfalFiKMxINtZiLihMBjL9PN0gDAAA= X-CMS-MailID: 20230515071450eucas1p1625a8639e2b0edf47e41126801d4cbb8 X-Msg-Generator: CA X-RootMTR: 20230515071450eucas1p1625a8639e2b0edf47e41126801d4cbb8 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230515071450eucas1p1625a8639e2b0edf47e41126801d4cbb8 References: <20230515071446.2277292-1-j.granados@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Joel Granados Reviewed-by: Luis Chamberlain --- drivers/parport/procfs.c | 89 +++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c index d740eba3c099..53ae5cb98190 100644 --- a/drivers/parport/procfs.c +++ b/drivers/parport/procfs.c @@ -32,6 +32,13 @@ #define PARPORT_MAX_TIMESLICE_VALUE ((unsigned long) HZ) #define PARPORT_MIN_SPINTIME_VALUE 1 #define PARPORT_MAX_SPINTIME_VALUE 1000 +/* + * PARPORT_BASE_* is the size of the known parts of the sysctl path + * in dev/partport/%s/devices/%s. "dev/parport/"(12), "/devices/"(9 + * and null char(1). + */ +#define PARPORT_BASE_PATH_SIZE 13 +#define PARPORT_BASE_DEVICES_PATH_SIZE 22 =20 static int do_active_device(struct ctl_table *table, int write, void *result, size_t *lenp, loff_t *ppos) @@ -260,9 +267,6 @@ struct parport_sysctl_table { struct ctl_table_header *sysctl_header; struct ctl_table vars[12]; struct ctl_table device_dir[2]; - struct ctl_table port_dir[2]; - struct ctl_table parport_dir[2]; - struct ctl_table dev_dir[2]; }; =20 static const struct parport_sysctl_table parport_sysctl_template =3D { @@ -305,7 +309,6 @@ static const struct parport_sysctl_table parport_sysctl= _template =3D { .mode =3D 0444, .proc_handler =3D do_hardware_modes }, - PARPORT_DEVICES_ROOT_DIR, #ifdef CONFIG_PARPORT_1284 { .procname =3D "autoprobe", @@ -355,18 +358,6 @@ static const struct parport_sysctl_table parport_sysct= l_template =3D { }, {} }, - { - PARPORT_PORT_DIR(NULL), - {} - }, - { - PARPORT_PARPORT_DIR(NULL), - {} - }, - { - PARPORT_DEV_DIR(NULL), - {} - } }; =20 struct parport_device_sysctl_table @@ -477,7 +468,9 @@ parport_default_sysctl_table =3D { int parport_proc_register(struct parport *port) { struct parport_sysctl_table *t; - int i; + char *tmp_dir_path; + size_t tmp_path_len, port_name_len; + int i, err =3D 0; =20 t =3D kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL); if (t =3D=3D NULL) @@ -485,28 +478,60 @@ int parport_proc_register(struct parport *port) =20 t->device_dir[0].extra1 =3D port; =20 - for (i =3D 0; i < 5; i++) - t->vars[i].extra1 =3D port; - t->vars[0].data =3D &port->spintime; - t->vars[5].child =3D t->device_dir; -=09 - for (i =3D 0; i < 5; i++) - t->vars[6 + i].extra2 =3D &port->probe_info[i]; + for (i =3D 0; i < 5; i++) { + t->vars[i].extra1 =3D port; + t->vars[5 + i].extra2 =3D &port->probe_info[i]; + } + + port_name_len =3D strnlen(port->name, PARPORT_NAME_MAX_LEN); + /* + * Allocate a buffer for two paths: dev/parport/PORT and dev/parport/PORT= /devices. + * We calculate for the second as that will give us enough for the first. + */ + tmp_path_len =3D PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len; + tmp_dir_path =3D kmalloc(tmp_path_len, GFP_KERNEL); + if (!tmp_dir_path) { + err =3D -ENOMEM; + goto exit_free_t; + } =20 - t->port_dir[0].procname =3D port->name; + if (tmp_path_len + <=3D snprintf(tmp_dir_path, tmp_path_len, "dev/parport/%s/devices", p= ort->name)) { + kfree(tmp_dir_path); + return -ENOENT; + } + if (register_sysctl(tmp_dir_path, t->device_dir) =3D=3D NULL) + /* + * We keep the original behavior of parport where failure to register + * does not return error. + */ + goto exit_free_tmp_dir_path; =20 - t->port_dir[0].child =3D t->vars; - t->parport_dir[0].child =3D t->port_dir; - t->dev_dir[0].child =3D t->parport_dir; =20 - t->sysctl_header =3D register_sysctl_table(t->dev_dir); - if (t->sysctl_header =3D=3D NULL) { - kfree(t); - t =3D NULL; + tmp_path_len =3D PARPORT_BASE_PATH_SIZE + port_name_len; + if (tmp_path_len + <=3D snprintf(tmp_dir_path, tmp_path_len, "dev/parport/%s", port->name= )) { + err =3D -ENOENT; + goto exit_free_tmp_dir_path; } + + t->sysctl_header =3D register_sysctl(tmp_dir_path, t->vars); + if (t->sysctl_header =3D=3D NULL) + goto exit_free_tmp_dir_path; + port->sysctl_table =3D t; + + kfree(tmp_dir_path); return 0; + +exit_free_tmp_dir_path: + kfree(tmp_dir_path); +exit_free_t: + kfree(t); + t =3D NULL; + return err; + } =20 int parport_proc_unregister(struct parport *port) --=20 2.30.2