From mboxrd@z Thu Jan 1 00:00:00 1970 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 shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D04C9C433FE for ; Tue, 29 Nov 2022 18:31:15 +0000 (UTC) Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.96) (envelope-from ) id 1p05Nh-0002zh-1L; Tue, 29 Nov 2022 13:30:57 -0500 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1p05Nb-0002ij-3B for kernelnewbies@kernelnewbies.org; Tue, 29 Nov 2022 13:30:52 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id B6778320099A; Tue, 29 Nov 2022 13:30:47 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 29 Nov 2022 13:30:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h=cc :cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1669746647; x=1669833047; bh=WjTxJpAwwF VK+6deheS/g0XdHn366edWuEj10jfa8Bg=; b=KmRqnSdER5UmIik/f2VZOn8A39 j/meqYiqds7FeXntEPsx9EirM2rdZDR5TJbB3gkbxND4RZHpTYRHBlp9nmEc9UEO 3B7eeL1VDJW44w2TroQnwdChc8+u/OAXjR4R8GuBUPmWMkcEXNV/Fsf493/tuoKS Jl2jN34sSFcaDe2Te/gv+kKEglCYuXn/rnsHVm4F5cjmXA+0XY/Bz0asbcMd9Cmk IJiVjIzdkvC4khuBmGCxv0UoFZp97JGYIQWcD8/vnwI6LYtHjZnRO61ZFgpBhBZR 6JcFhmJiVBIfOYEgBtI7BoAxcD8oK6PxIxderJLo4WVrjDQ0dmIrT8q55USQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1669746647; x=1669833047; bh=WjTxJpAwwFVK+6deheS/g0XdHn36 6edWuEj10jfa8Bg=; b=advHMG/MwveawNXkIxGmoyws98Dr5+hcLHTK6jy4IQ4+ QN+Bo+1wbElk2tW9VOrqQYeLAHd+L2YVYMh2/QMawT7PEzgOKb5aF5bzVLq6SilL vAZe9qfwIvyH/JZXnBOgmQudtWAM5cVFOM21xRRYvfvM05pKSSLCVfTmZelp7ms+ 0YQOhTXanTF+XLtiqvkLZVAV23T1fTd9G0RN78g9C0WuKpal5Ex5g8zuvim4NOWT BMvxpE9aw1w5lCfhsSj0htXq60K3IUGVxFx5WboP6xMZxbAEY5fYenpRInbp59lo +TvYZxAEfYRS2Wv9DAl3vd4n5h2BnL7AgKNocWXunQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrtddtgdekfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuffkfhggtggujgesthdtre dttddtvdenucfhrhhomhepifhrvghgucfmjfcuoehgrhgvgheskhhrohgrhhdrtghomheq necuggftrfgrthhtvghrnhepheegvdevvdeljeeugfdtudduhfekledtiefhveejkeejue fhtdeufefhgfehkeetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghi lhhfrhhomhepghhrvghgsehkrhhorghhrdgtohhm X-ME-Proxy: Feedback-ID: i787e41f1:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 29 Nov 2022 13:30:46 -0500 (EST) Date: Tue, 29 Nov 2022 19:30:42 +0100 From: Greg KH To: Anuz Pratap Singh Tomar Subject: Re: struct definition inside a function Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Cc: kernelnewbies X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org On Tue, Nov 29, 2022 at 03:06:30PM +0000, Anuz Pratap Singh Tomar wrote: > Hi all, > I have not seen a struct define inside a function in kernel code and > couldn't find any guidelines if it's permitted or frowned upon? > > int fn(int i) > { > struct my_struct { > int var1; > int var2 > }; /* is this allowed? */ > struct my_struct struct_local; Yes, it is allowed, but usually you never want to do that in a kernel function as structures are normally used across functions, not just only in a single one. Do you have a real-world example where you feel this pattern is the best? thanks, greg k-h _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies