Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp12660561rwd; Fri, 23 Jun 2023 08:58:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5LQ8ergNs0wckdYlyYvyIX/3kMG5CMwOV0e9zQ0aN7oNyr7TVlpuMHJXQm+X3iYAU/BG2Z X-Received: by 2002:a05:6a00:15d6:b0:66a:6310:ac1a with SMTP id o22-20020a056a0015d600b0066a6310ac1amr4770274pfu.13.1687535927620; Fri, 23 Jun 2023 08:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687535927; cv=none; d=google.com; s=arc-20160816; b=xZZhADQtfrp0ZEyu29ESSpFoDWJ05EfllIke9Kbl0dhuM4kAAr+dw485H335L4ZRMB asBP7mzhCrdpH/QexKGCmNgBrpYOzTQ2THeNKQBCHCJ0xcgbcefnZQz3YEHu2EJejbHR rfaQnZjYssTUZ2ya7Khl4Eiaa+z15eFr9PQxrZNLlMoRmws7Atfi1Mz3ut6ieKx5oDQl 16o9eIGEZd8AudvWgzIT+hnlu9GnzWa/K3AwxipRBBehL9ygGmvLrfHvqz02FcApRUxx 1TB2lRZAgnNd9T1yqt5rP2oecwK7b/+r1o50Q05ZN1CP2v2HidLVgNjeCPQuvEZIP+Oy 9WFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1mTZQB6E8gpW9xyv3IdX7kwRMApo1npl8Ta69cylcgI=; b=vqvJqVwV+ihKLuCKRyhnOokgKL7VuB6uVOGFdfrSTC1Q5cZ8sR/zrJw7ZqlyN+8NcE 3NHcf/rVP+KjLELLhnjGe+/UmnNvF8a51yrGMC5+zl++qRgPMis3V0Wh54I59tR/7yzv Ext4p/iRd0NeuW+2ruR8zURR6RWlSj2PqROQ2Yqh12WFyhNwWm4u78oY6EA+AkLuoL9s LT0yw77wyXwS6zL7E0aJoRRsOWzxQjnNq6TVBDUk3kTYxUpIcVurYunPWPtqsksVIqvd 6aBCVwaj+9r1y7PrJL6TTJuT0HEZ81lj6r736q/GHDIQK2A45WMFD8U5tdsmBiwItG22 e1sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=cw+6g9R2; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u20-20020a056a00099400b00653c0edfd34si6204131pfg.139.2023.06.23.08.58.35; Fri, 23 Jun 2023 08:58:47 -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=@suse.com header.s=susede1 header.b=cw+6g9R2; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232224AbjFWPUv (ORCPT + 99 others); Fri, 23 Jun 2023 11:20:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232747AbjFWPUb (ORCPT ); Fri, 23 Jun 2023 11:20:31 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 238FC10C1; Fri, 23 Jun 2023 08:20:29 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id D24151F45F; Fri, 23 Jun 2023 15:20:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1687533627; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1mTZQB6E8gpW9xyv3IdX7kwRMApo1npl8Ta69cylcgI=; b=cw+6g9R2o/Umv74/BGjs0HZFU73NXkDTjRhAwElwD9yLjkG2loVWkX98zsq+Jw9f7GWEbv 1LhcZAdPyuPlH6OaETf856CLkRN01mJSpFOO8X/jovaGWHnPkt2fDQYbq4M0K8/oavd3Ir XsYDO2FS6i0HJDFn6EWyGK6+OhLducU= Received: from suse.cz (pmladek.udp.ovpn2.prg.suse.de [10.100.201.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 1AE602C141; Fri, 23 Jun 2023 15:20:22 +0000 (UTC) Date: Fri, 23 Jun 2023 17:20:17 +0200 From: Petr Mladek To: Joel Granados Cc: Jiri Slaby , Greg Kroah-Hartman , mcgrof@kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Theodore Ts'o , "Jason A. Donenfeld" , Juergen Gross , Stefano Stabellini , Benjamin LaHaise , Alexander Viro , Christian Brauner , Jeff Layton , Chuck Lever , Jan Kara , Kees Cook , Iurii Zaikin , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Balbir Singh , Eric Biederman , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Peter Zijlstra , Will Deacon , Sergey Senozhatsky , Juri Lelli , Vincent Guittot , Steven Rostedt , Andrew Morton , Mike Kravetz , Muchun Song , Naoya Horiguchi , "Matthew Wilcox (Oracle)" , David Howells , Jarkko Sakkinen , Paul Moore , James Morris , "Serge E. Hallyn" , "H. Peter Anvin" , Oleksandr Tyshchenko , Amir Goldstein , John Fastabend , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Waiman Long , Boqun Feng , John Ogness , Dietmar Eggemann , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Andy Lutomirski , Will Drewry , Mark Rutland , Miaohe Lin , linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, kexec@lists.infradead.org, linux-trace-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [PATCH 08/11] sysctl: Add size to register_sysctl_init Message-ID: References: <20230621091000.424843-1-j.granados@samsung.com> <20230621091000.424843-9-j.granados@samsung.com> <2023062150-outbound-quiet-2609@gregkh> <20230621131552.pqsordxcjmiopciq@localhost> <20230622140021.g3odhui75ybwuai5@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230622140021.g3odhui75ybwuai5@localhost> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Thu 2023-06-22 16:00:21, Joel Granados wrote: > On Thu, Jun 22, 2023 at 06:21:48AM +0200, Jiri Slaby wrote: > > On 21. 06. 23, 15:15, Joel Granados wrote: > > > On Wed, Jun 21, 2023 at 12:47:58PM +0200, Greg Kroah-Hartman wrote: > > > > On Wed, Jun 21, 2023 at 11:09:57AM +0200, Joel Granados wrote: > > > > > static int __init random_sysctls_init(void) > > > > > { > > > > > - register_sysctl_init("kernel/random", random_table); > > > > > + register_sysctl_init("kernel/random", random_table, > > > > > + ARRAY_SIZE(random_table)); > > > > > > > > As mentioned before, why not just do: > > > > > > > > #define register_sysctl_init(string, table) \ > > > > __register_sysctl_init(string, table, ARRAY_SIZE(table); > > > Answered you in the original mail where you suggested it. > > > > I am curious what that was, do you have a link? > of course. I think you will find it here https://lore.kernel.org/all/20230621123816.ufqbob6qthz4hujx@localhost/ Let me to copy the answer here: I considered this at the outset, but it will not work with callers that use a pointer instead of the actual array. Additionally, we would not avoid big commits as we would have to go looking in all the files where register is called directly or indirectly and make sure the logic is sound. For the callers using a pointer. A solution would be to create another wrapper which would take the array size, e.g. #define register_sysctl_init_limited(string, table, size) \ __register_sysctl_init(string, table, size); And ARRAY_SIZE() is defined in include/linux/kernel.h as: #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) It will create a compiler error when either an array[] or *array is passed. When using this: 1. The compiler will tell us where the other wrapper is needed. 2. Some locations might need the @size parameter even when a static array is passed. For example, neigh_sysctl_register() terminates the array early. But this will work when __register_sysctl_init() supports both ways.I mean that it will stop either on @size or empty element, as discussed in the other subthread. This should be caught when the final "empty" is removed from the particular caller. Best Regards, Petr