From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lamorak.hansenpartnership.com (lamorak.hansenpartnership.com [198.37.111.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3966122A1D5 for ; Tue, 18 Nov 2025 16:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.37.111.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763483970; cv=none; b=To8l+Y+d2IFgnnIBokzEdre4GX/ORNJntrY6xGY626JnIJd4Cfl+7Sr2+7cpssRD1L1UieXAZ6gCy9RwAC7BjyP5bNecE91mPVnBqDVYCQ3LOJkLIdb/O78LTPXPGeP7qwbarEFM04kgRuf8z113V0ilnfuOOKdIa5v8UZXBmlY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763483970; c=relaxed/simple; bh=SAt5+bSAmImvyQIp3CC97sOj4VCHG8obYL4nadNudoM=; h=Message-ID:Subject:From:To:Cc:Date:Content-Type:MIME-Version; b=tSgd60BXujTH8HCqUP503OyDVUcYo2Od/s8gKBSqbuN0foMq0SQODTtRuCV5xkaTp5Mve9GFTCRDEGtkB/hpg5g4pcrPV4IHiKacV4jWVdxTF28ZauYm5oGEscy2Y90LqOzCdwjwK0BwxZ6e+J4ogAshuow4Zj3haR1dmQrtY0M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=HansenPartnership.com; spf=pass smtp.mailfrom=HansenPartnership.com; dkim=pass (1024-bit key) header.d=hansenpartnership.com header.i=@hansenpartnership.com header.b=HS10EXRo; arc=none smtp.client-ip=198.37.111.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=HansenPartnership.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=HansenPartnership.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hansenpartnership.com header.i=@hansenpartnership.com header.b="HS10EXRo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1763483967; bh=SAt5+bSAmImvyQIp3CC97sOj4VCHG8obYL4nadNudoM=; h=Message-ID:Subject:From:To:Date:From; b=HS10EXRokkJd2yIne9i4dNn9VV3lAvk97rPHyalKxzRgmTwcJhXgeItB8tNquhi7D msZdh/JzrgHvf32loYUp5JAgQq7JnaadaY/CyNJJsTDtCa3j0ym28W7QXiRpZAF1IK EG9mD2TkXLdxqbKvNMowpog3Hq9uuEHwA9p1CRDY= Received: from lingrow.int.hansenpartnership.com (unknown [IPv6:2601:5c4:4302:c21::a774]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lamorak.hansenpartnership.com (Postfix) with ESMTPSA id 02FD31C000D; Tue, 18 Nov 2025 11:39:26 -0500 (EST) Message-ID: <58fd478f408a34b578ee8d949c5c4b4da4d4f41d.camel@HansenPartnership.com> Subject: Clarifying confusion of our variable placement rules caused by cleanup.h From: James Bottomley To: ksummit@lists.linux.dev, Dan Williams Cc: linux-kernel , Dan Carpenter Date: Tue, 18 Nov 2025 11:39:26 -0500 Autocrypt: addr=James.Bottomley@HansenPartnership.com; prefer-encrypt=mutual; keydata=mQENBE58FlABCADPM714lRLxGmba4JFjkocqpj1/6/Cx+IXezcS22azZetzCXDpm2MfNElecY3qkFjfnoffQiw5rrOO0/oRSATOh8+2fmJ6el7naRbDuh+i8lVESfdlkoqX57H5R8h/UTIp6gn1mpNlxjQv6QSZbl551zQ1nmkSVRbA5TbEp4br5GZeJ58esmYDCBwxuFTsSsdzbOBNthLcudWpJZHURfMc0ew24By1nldL9F37AktNcCipKpC2U0NtGlJjYPNSVXrCd1izxKmO7te7BLP+7B4DNj1VRnaf8X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2aoXh2KOH6naGzPKDkYDJ/K7XCJAq3nJYEpYN8G+F8mL/ql0hrihAsHfjmoDOlt+INa3AcG3v0jDZIMEzmcjAlu7g5NcXS3kntcMHgw3dCgE9eYDaKGipUCubdXvBaZWU6AUlTldaB8FE6u7It7+UO+IW4/L+KpLYKs8V5POInu2rqahlm7vgxY5iv4Txz4EvCW2e4dAlG 8mT2Eh9SkH+YVOmaKsajgZgrBxA7fWmGoxXswEVxJIFj3vW7yNc0C5HaUdYa5iGOMs4kg2ht4s7yy7NRQuh7BifWjo6BQ6k4S1H+6axZucxhSV1L6zN9d+lr3Xo/vy1unzA== Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.3 Precedence: bulk X-Mailing-List: ksummit@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch, introduced by Dan Williams (cc'd): https://lore.kernel.org/all/171097196970.1011049.9726486429680041876.stgit@= dwillia2-xfh.jf.intel.com/ There was some discussion at the time (I missed it because I'm not on any of the lists it touched) and people expected to be opinionated were cc'd but none of it really touched on the problem that we now have inconsistent rules for variable and initializer placement. Before this change, we always adhered to K&R rules, subsequently codified in C89, to place variable declarations at the top of the block The problem specifically is this added comment in cleanup.h: > * That bug is fixed by changing init() to call guard() and define + > * initialize @obj in this order:: > * > * guard(mutex)(&lock); > * struct object *obj __free(remove_free) =3D alloc_add(); Which is recommending mixing declarations and code contrary to our prior rule. I note the rule against mixing variables and code was relaxed in the C99 standard (and in a lot of other languages), but we've never formally changed our coding rules. I'm not saying we have to stick with C89, just that if we change adherence to it, we should do so globally and document it because having incosistency for __free vs other variables really isn't a good idea. So which should we do? It does seem the dependency ordering problem of __free annotations means that there are situations where we can't adhere to the variables at the top of the block rule, but are we going to relax this globally or simply advise noting the dependency in a comment but keep the rule (thus discouraging the mixing of code and declarations except where absolutely necessary)? The other problem is that we've traditionally not initialized automatic variables specifically to avoid the initialization taking unnecessary space in the data/bss of the kernel. However immediately below the quote above, there's this > * > * Given that the "__free(...) =3D NULL" pattern for variables defined at > * the top of the function poses this potential interdependency problem > * the recommendation is to always define and assign variables in one > * statement and not group variable definitions at the top of the > * function when __free() is used. Which advises always initializing __free variables (in addition to mixing code and declarations). My reading of our compilers and checkers is that actually this is unnecessary: there is a danger that a return before initialization will result in a free being called on an uninitialized pointer, but that the checkers and compilers can correctly detect this (at least as correctly as they usually detect uninitialized variables) so, again, requiring __free variables always to be initiallised is an unnecessary deviation from our usual coding habits. The danger of the above is that one way of avoiding the data/bss space problem is to move the declaration into the code directly where the allocation is (as the rule relaxation above says you could). Again, I'm not saying we shouldn't do this, just that we should do it consistently and mindfully rather than allowing it to leak in like this. So, again, I think we should debate whether and how much we're changing the coding rules and do so globally in the coding-style document rather than keeping the change in the cleanup.h file. For myself I do find some value in the C89 declarations at the beginning of the block for readability, so I'm happy to relax the mixing rule to cases where it's strictly necessary and require documenting in the comment what the necessity is. However, I do think we should, absent ordering problems, keep __free variables uninitialised and at the top of the block given we can detect any problem (and thus keep this rule absolutely for non-__free variables where there's no ordering issues). But, again, I'm less attached to this position than I am to the consistency one: I really think it's a bad idea to change the rules for one class of variables but not for another, so whatever we do, we should do it for everything and if that means relaxing the rule mixing code and declarations for everthing, I can live with that. Regards, James