linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: "Benjamin Stürz" <benni@stuerz.xyz>, andrew@lunn.ch
Cc: sebastian.hesselbarth@gmail.com, gregory.clement@bootlin.com,
	linux@armlinux.org.uk, linux@simtec.co.uk, krzk@kernel.org,
	alim.akhtar@samsung.com, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, hpa@zytor.com,
	robert.moore@intel.com, rafael.j.wysocki@intel.com,
	lenb@kernel.org, 3chas3@gmail.com, laforge@gnumonks.org,
	arnd@arndb.de, gregkh@linuxfoundation.org, mchehab@kernel.org,
	tony.luck@intel.com, james.morse@arm.com, rric@kernel.org,
	linus.walleij@linaro.org, brgl@bgdev.pl,
	mike.marciniszyn@cornelisnetworks.com,
	dennis.dalessandro@cornelisnetworks.com, jgg@ziepe.ca,
	pali@kernel.org, dmitry.torokhov@gmail.com, isdn@linux-pingi.de,
	benh@kernel.crashing.org, fbarrat@linux.ibm.com,
	ajd@linux.ibm.com, davem@davemloft.net, kuba@kernel.org,
	pabeni@redhat.com, nico@fluxnic.net, loic.poulain@linaro.org,
	kvalo@kernel.org, pkshih@realtek.com, bhelgaas@google.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
	linux-ia64@vger.kernel.org, linux-acpi@vger.kernel.org,
	devel@acpica.org, linux-atm-general@lists.sourceforge.net,
	netdev@vger.kernel.org, linux-edac@vger.kernel.org,
	linux-gpio@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-input@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	linux-media@vger.kernel.org, wcn36xx@lists.infradead.org,
	linux-wireless@vger.kernel.org, linux-pci@vger.kernel.org,
	"Benjamin Stürz" <benni@stuerz.xyz>
Subject: Re: [PATCH 04/22] x86: Replace comments with C99 initializers
Date: Tue, 29 Mar 2022 01:08:16 +0200	[thread overview]
Message-ID: <87lewtfzfj.ffs@tglx> (raw)
In-Reply-To: <20220326165909.506926-4-benni@stuerz.xyz>

Benjamin,

On Sat, Mar 26 2022 at 17:58, Benjamin Stürz wrote:

> This replaces comments with C99's designated
> initializers because the kernel supports them now.

the kernel has used designated array initializers for a very long time
simply because the kernel did not use pure C89 but C89 with GNU
extensions, i.e. -std=gnu89, which include designated array
initializers. GCC supports this since 1998 with =gnu89, so 'now' is
more than slightly off.

Explicit value assignment to enum constants are a different story. They
are neither designated initializers nor new in C99. The following
paragraph from the standard has not been changed since C89:

   "The identifiers in an enumerator list are declared as constants that
    have type int and may appear wherever such are permitted. An
    enumerator with = defines its enumeration constant as the value of
    the constant expression. If the first enumerator has no =, the value
    of its enumeration constant is 0. Each subsequent enumerator with no
    = defines its enumeration constant as the value of the constant
    expression obtained by adding 1 to the value of the previous
    enumeration constant. (The use of enumerators with = may produce
    enumeration constants with values that duplicate other values in the
    same enumeration.)"

Please make sure that your changelogs are factual. Making uninformed
claims is not helping your cause.

The most important part is the WHY:

    Why is the current code suboptimal?

    Why is the proposed change making it better, more correct, less
    error prone?

If you can't come up with proper technical answers for these questions
then why should it be changed?

>  enum regnames {
> -	GDB_AX,			/* 0 */
> +	GDB_AX = 0,

Linear enums without value assignment like here are not a problem at
all. Simply because they are well defined and well understood. See the
above quote of the standard.

Whether the explicit assignment is an improvement over the trailing
comment or not is a matter of taste and preference. There is absolutely
_zero_ technical advantage in using explicit value assignments in _this_
case and neither in many other cases of your series.

Also completely removing the comments here loses information:

> -	GDB_PC,			/* 8 also known as eip */
> -	GDB_PS,			/* 9 also known as eflags */

Can you map _PC to EIP and _PS to EFLAGS? I can't without digging
deep...

>  static const char *const mtrr_strings[MTRR_NUM_TYPES] =
>  {
> -	"uncachable",		/* 0 */
> -	"write-combining",	/* 1 */
> -	"?",			/* 2 */
> -	"?",			/* 3 */
> -	"write-through",	/* 4 */
> -	"write-protect",	/* 5 */
> -	"write-back",		/* 6 */
> +	[0] = "uncachable",
> +	[1] = "write-combining",
> +	[2] = "?",
> +	[3] = "?",
> +	[4] = "write-through",
> +	[5] = "write-protect",
> +	[6] = "write-back",

Again, while not supported in C89, the kernel uses designators in array
initializers for a very long time...

Linear array initializers like the mtrr strings are not a real problem
simply because there is no correlation and the code using the array
still has to make sure that the index into the array is what it expects
to be the content. Changing it from C89 automatic to explicit C99
designators does not help there at all.

It becomes a different story if you combine [enum] constants and arrays
and use the constants in code because then the change to the constants
will immediately be reflected in the array initializer. I.e. for this
case:

enum foo {
     BAR,
     BAZ,
     RAB,
     ZAR,
};

char foobar[] = {
     "bar",
     "baz",
     "rab",
     "zar",
};

it makes a difference if someone does:

  enum foo {
     BAR,
     BAZ,
+    MOO,
     RAB,
     ZAR,
  };

because then the related array initializer is obviously out of
order. With:

char *foobar[] = {
     [BAR] = "bar",
     [BAZ] = "baz",
     [RAB] = "rab",
     [ZAR] = "zar",
};

the existing values are still in the same place, just the newly added
value is a NULL pointer. It also does not matter when the fixup for the
missing array entry becomes:

  char *foobar[] = {
     [BAR] = "bar",
     [BAZ] = "baz",
     [RAB] = "rab",
     [ZAR] = "zar",
+    [MOO] = "moo",     
  };

because the compiled result is still in enum order. While doing

  char foobar[] = {
     "bar",
     "baz",
     "rab",
     "zar",
+    "moo",
  };

would be blantantly wrong. See?

But that does not apply to any of your proposed changes.

So you really need to look at things and not just throw a mechanical
change scheme at it, which results even in failures like reported by
the 0-day robot against patch 10/22.

That said, I'm not completely opposed to those changes, but you really
have to come up with good reasons why they make sense aside of
cosmetical reasons.

Btw, the really important change regarding initializers between C89 and
C99 was the ability to initialize struct members explicitly.

In C89 the only way to initialize a struct was

   = { a, b, c, d }

which was way more error prone than the enum/array initializers. The
dangerous part or C89 struct initializers are changes to the struct
unless the change of the struct is actually triggering a type
mismatch.

But even that needs some serious inspection whether there is confusion
potential or not. The harmless example is a file local:

struct foo {
       unsigned int      id;
       unsigned int      flags;
};

and the C89 style initializer:

static struct foo[] {
       { ID_A, 0x01 },
       { ID_B, 0x02 },
       { ID_C, 0x01 },
};

which has a very low confusion potential simply because it's scope is
file local and well defined and unlikely to change.

A globally used structure is a different problem especially when it
becomes necessary to insert a new struct member in the middle instead of
appending it, changing the order, removing a member... That ends up in a
hard to diagnose disaster with C89 style unnamed initializers pretty
fast.

Ideally C89 style unnamed struct initializers should not be used at all,
but again it's a matter of common sense and justification whether it's
worth to change it just because.

Thanks,

        tglx

  reply	other threads:[~2022-03-28 23:08 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-26 16:58 [PATCH 01/22] orion5x: Replace comments with C99 initializers Benjamin Stürz
2022-03-26 16:58 ` [PATCH 02/22] s3c: " Benjamin Stürz
2022-03-26 19:44   ` Joe Perches
2022-03-28 13:37   ` Daniel Thompson
2022-03-26 16:58 ` [PATCH 03/22] ia64: " Benjamin Stürz
2022-03-26 16:58 ` [PATCH 04/22] x86: " Benjamin Stürz
2022-03-28 23:08   ` Thomas Gleixner [this message]
2022-03-26 16:58 ` [PATCH 05/22] acpica: " Benjamin Stürz
2022-03-27 19:59   ` Andy Shevchenko
2022-03-31 19:27     ` Moore, Robert
2022-04-01  5:09       ` Christoph Hellwig
2022-04-01  5:10     ` Christoph Hellwig
2022-03-28 12:33   ` Rafael J. Wysocki
2022-03-26 16:58 ` [PATCH 06/22] idt77252: " Benjamin Stürz
2022-03-26 16:58 ` [PATCH 07/22] cm4000: " Benjamin Stürz
2022-03-26 16:58 ` [PATCH 08/22] i5100: " Benjamin Stürz
2022-03-26 16:58 ` [PATCH 09/22] gpio-winbond: Use " Benjamin Stürz
2022-03-27 12:03   ` Linus Walleij
2022-03-29 12:30   ` Bartosz Golaszewski
2022-03-26 16:58 ` [PATCH 10/22] hfi1: Replace comments with " Benjamin Stürz
2022-03-26 16:58 ` [PATCH 11/22] rdmavt: " Benjamin Stürz
2022-03-27  7:04   ` Leon Romanovsky
2022-03-31 17:41     ` Dennis Dalessandro
2022-03-26 16:58 ` [PATCH 12/22] alps: " Benjamin Stürz
2022-03-26 16:59 ` [PATCH 13/22] capi: " Benjamin Stürz
2022-03-26 16:59 ` [PATCH 14/22] mISDN: " Benjamin Stürz
2022-03-26 16:59 ` [PATCH 15/22] macintosh: " Benjamin Stürz
2022-03-26 16:59 ` [PATCH 16/22] dvb-usb: " Benjamin Stürz
2022-03-26 18:24   ` Mauro Carvalho Chehab
2022-03-26 18:27     ` Mauro Carvalho Chehab
2022-03-26 19:51       ` Joe Perches
2022-03-26 20:11         ` Larry Finger
2022-03-26 21:08           ` Mauro Carvalho Chehab
2022-03-28 18:08             ` [PATCH 16/22 v3] " Benjamin Stürz
2022-03-28 20:52               ` Mauro Carvalho Chehab
2022-03-27 13:33   ` [PATCH 16/22 v2] " Benjamin Stürz
2022-03-26 16:59 ` [PATCH 17/22] cxl: " Benjamin Stürz
2022-03-26 16:59 ` [PATCH 18/22] smsc: " Benjamin Stürz
2022-03-26 16:59 ` [PATCH 19/22] wnc36xx: " Benjamin Stürz
2022-03-28 16:17   ` Jeff Johnson
2022-03-28 18:38     ` [PATCH 19/22 v2] wcn36xx: Improve readability of wcn36xx_caps_name Benjamin Stürz
2022-03-28 20:23       ` Jeff Johnson
2022-03-30  7:05         ` Kalle Valo
2022-03-30  8:19           ` Kalle Valo
2022-03-26 16:59 ` [PATCH 20/22] wireless: Replace comments with C99 initializers Benjamin Stürz
2022-03-28 12:06   ` Kalle Valo
2022-03-28 18:21     ` [PATCH 20/22 v2] ray_cs: " Benjamin Stürz
2022-03-28 19:23       ` Joe Perches
2022-03-28 19:54         ` [PATCH 20/22 v3] ray_cs: Improve card_status[] Benjamin Stürz
2022-04-06 11:31           ` Kalle Valo
2022-03-26 16:59 ` [PATCH 21/22] rtw89: Replace comments with C99 initializers Benjamin Stürz
2022-03-26 18:55   ` Larry Finger
2022-03-28  9:28     ` Kalle Valo
2022-03-28 12:21       ` David Laight
2022-03-26 16:59 ` [PATCH 22/22] pci: " Benjamin Stürz
2022-03-26 18:20 ` [PATCH 01/22] orion5x: " Mauro Carvalho Chehab
2022-03-26 19:23 ` Arnd Bergmann
2022-03-28 13:19   ` Segher Boessenkool
2022-03-27 12:46 ` [PATCH 00/22] " Benjamin Stürz
2022-03-28  9:33   ` Kalle Valo
2022-03-28 11:51     ` Benjamin Stürz
2022-03-28 12:31       ` Kalle Valo
2022-03-28 20:20       ` Jakub Kicinski
2022-03-28 13:47   ` Daniel Thompson
2022-03-28 13:17 ` [PATCH 01/22] orion5x: " Daniel Thompson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lewtfzfj.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=3chas3@gmail.com \
    --cc=ajd@linux.ibm.com \
    --cc=alim.akhtar@samsung.com \
    --cc=andrew@lunn.ch \
    --cc=arnd@arndb.de \
    --cc=benh@kernel.crashing.org \
    --cc=benni@stuerz.xyz \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=brgl@bgdev.pl \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=devel@acpica.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=fbarrat@linux.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gregory.clement@bootlin.com \
    --cc=hpa@zytor.com \
    --cc=isdn@linux-pingi.de \
    --cc=james.morse@arm.com \
    --cc=jgg@ziepe.ca \
    --cc=krzk@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=laforge@gnumonks.org \
    --cc=lenb@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-atm-general@lists.sourceforge.net \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-ia64@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linux@simtec.co.uk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=loic.poulain@linaro.org \
    --cc=mchehab@kernel.org \
    --cc=mike.marciniszyn@cornelisnetworks.com \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=nico@fluxnic.net \
    --cc=pabeni@redhat.com \
    --cc=pali@kernel.org \
    --cc=pkshih@realtek.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=robert.moore@intel.com \
    --cc=rric@kernel.org \
    --cc=sebastian.hesselbarth@gmail.com \
    --cc=tony.luck@intel.com \
    --cc=wcn36xx@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).