Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1641847rwd; Mon, 15 May 2023 00:27:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7h3FzL3i0v9VW5mXf7Q6VvkZ7gLWuwgYShbfFtN+zbJLf9ZklgTv2hJgVTNEfrGP9weRmw X-Received: by 2002:a17:90b:3904:b0:247:8029:fb30 with SMTP id ob4-20020a17090b390400b002478029fb30mr35791156pjb.42.1684135675536; Mon, 15 May 2023 00:27:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684135675; cv=none; d=google.com; s=arc-20160816; b=wJYwYYsIhrevmgMLxgWpg1o4R0x8voKbgKSyvcV/TFto/KjYZfXKkt84GNrSQ//+iZ pnzjrXyQIZYPLcOPJ6Ot77vNDTCSz43+77vrNCDmf/pH5VxI9s6Z/vGEMtaOFEcwuFBL WxcZsRUVPnfoxvbueN98cS5wm5kxSVltm9xBv2BQyhCVs/zVtgBKY7yo+gKNdcqFakqG 3wNpvB2SDGAvgxH/XWqKhsSUmjgD5p2Wi5mE6clZ9BBVZTsdRWeVz9vNN/LVdv+rwDcc bW6LHT+3gxULRnySZMm+eW6Wt92rS/yxrkFArflqI9Bo/uqdmOmOUHp2+XrKLs+/e8Or K05Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :mime-version:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=PDU9jqEs8417s9sxrU7lh3cS+FBJYDs7iRwM4PSqxjk=; b=ao+9AElBrktGuwnr3szc12rp/hC0WmoENvtaPBY9/Hu0KkJtMeAPCwsNj3JFrveTnH xUVb5m7Cbz6pB0CRCaRPlTuWYFI465uU7mKK4kd9ltZzdXPIML7HpgY2jelDZzvYy3ur P/OMqAaNam6bxbYPaEwJmuBaOfoipc7mgSWpvIQWT4L5r7cvMT6IIlKrCJxOIbBhYYyY k7FaU60aSsM6FLk2AXNYpZuspHDBaFunJKYFZmL3DzPQvUDo55hw7WBhEOoEnrazh41R 805IHP8ZagyCjw5uM5r0DhiIW+0IE32sD8KnoouGT8ZczWoHK1zRlEOQcz0ixH+SKyaE uv7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=NZvcG6tx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d187-20020a6336c4000000b005181ce23024si16561515pga.896.2023.05.15.00.27.43; Mon, 15 May 2023 00:27:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=NZvcG6tx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240654AbjEOHO7 (ORCPT + 99 others); Mon, 15 May 2023 03:14:59 -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: 8bit Content-Type: text/plain 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 N3fAlogIiEucOL2ZEaSIWeApo8Tcf71MIAlhgXCJ0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HOtiw2i6COj RMvaT8wQzhZGiZ1797KAVLEJ6Eicf3MHrFtEQFzixOnNjCBFzAJPGSVmHnrKBJIQFgiVeN6z BKiIg4NFQFXi+EEPkDCvgK1EQ8d9qG3yEm3XpzOC2JwCdhLr9h8FaxUCqjm9axsrRL2gxMmZ T8D2MgPVN2+dzQxhS0gcfPEC6gMlia9veqFm1kp8/vuMcQKjyCwk7bOQtM9C0r6AkXkVo0hq aXFuem6xkV5xYm5xaV66XnJ+7iZGYPxtO/Zzyw7Gla8+6h1iZOJgPMQowcGsJMLbPjM+RYg3 JbGyKrUoP76oNCe1+BCjKdCbE5mlRJPzgQkgryTe0MzA1NDEzNLA1NLMWEmc17OgI1FIID2x JDU7NbUgtQimj4mDU6qBSdFPlLlMpmt1xdy4d/YTHY7V2asL7f474+P+yHOrfzj6sXD+snkU /03kScI0k4U3BSty11cZaJZO+pLBcWV93g3Go4duznlUw1SZJ7uz/tDnZxkdRqf3+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> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 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]; }; static const struct parport_sysctl_table parport_sysctl_template = { @@ -305,7 +309,6 @@ static const struct parport_sysctl_table parport_sysctl_template = { .mode = 0444, .proc_handler = do_hardware_modes }, - PARPORT_DEVICES_ROOT_DIR, #ifdef CONFIG_PARPORT_1284 { .procname = "autoprobe", @@ -355,18 +358,6 @@ static const struct parport_sysctl_table parport_sysctl_template = { }, {} }, - { - PARPORT_PORT_DIR(NULL), - {} - }, - { - PARPORT_PARPORT_DIR(NULL), - {} - }, - { - PARPORT_DEV_DIR(NULL), - {} - } }; struct parport_device_sysctl_table @@ -477,7 +468,9 @@ parport_default_sysctl_table = { 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 = 0; t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL); if (t == NULL) @@ -485,28 +478,60 @@ int parport_proc_register(struct parport *port) t->device_dir[0].extra1 = port; - for (i = 0; i < 5; i++) - t->vars[i].extra1 = port; - t->vars[0].data = &port->spintime; - t->vars[5].child = t->device_dir; - - for (i = 0; i < 5; i++) - t->vars[6 + i].extra2 = &port->probe_info[i]; + for (i = 0; i < 5; i++) { + t->vars[i].extra1 = port; + t->vars[5 + i].extra2 = &port->probe_info[i]; + } + + port_name_len = 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 = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len; + tmp_dir_path = kmalloc(tmp_path_len, GFP_KERNEL); + if (!tmp_dir_path) { + err = -ENOMEM; + goto exit_free_t; + } - t->port_dir[0].procname = port->name; + if (tmp_path_len + <= snprintf(tmp_dir_path, tmp_path_len, "dev/parport/%s/devices", port->name)) { + kfree(tmp_dir_path); + return -ENOENT; + } + if (register_sysctl(tmp_dir_path, t->device_dir) == NULL) + /* + * We keep the original behavior of parport where failure to register + * does not return error. + */ + goto exit_free_tmp_dir_path; - t->port_dir[0].child = t->vars; - t->parport_dir[0].child = t->port_dir; - t->dev_dir[0].child = t->parport_dir; - t->sysctl_header = register_sysctl_table(t->dev_dir); - if (t->sysctl_header == NULL) { - kfree(t); - t = NULL; + tmp_path_len = PARPORT_BASE_PATH_SIZE + port_name_len; + if (tmp_path_len + <= snprintf(tmp_dir_path, tmp_path_len, "dev/parport/%s", port->name)) { + err = -ENOENT; + goto exit_free_tmp_dir_path; } + + t->sysctl_header = register_sysctl(tmp_dir_path, t->vars); + if (t->sysctl_header == NULL) + goto exit_free_tmp_dir_path; + port->sysctl_table = t; + + kfree(tmp_dir_path); return 0; + +exit_free_tmp_dir_path: + kfree(tmp_dir_path); +exit_free_t: + kfree(t); + t = NULL; + return err; + } int parport_proc_unregister(struct parport *port) -- 2.30.2