[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 0/2] code style exercise: Drivers folder samples


  • To: Oleksandr Andrushchenko <andr2000@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
  • Date: Tue, 18 Feb 2025 11:56:48 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xGl0/G8/+JX2BeKYGS+AkICE1Sk02TVZJHXQ++DT0zc=; b=B7s2+mo9ritiRlllQN7IJTEp5/CRttVGMoP9sAAHWZ31RboX15ijUrr8vGmpiGUeSBVBtqfE+2nTEkIjtcFYizuZ/1+3HQxVvxbqZozCz7kWMYI737quMlGBvtA6U3mpkvBG4d+k0f/xCpA90gVnbn5/dB1f9USi4mKE0vj3gUI6UYvEeWkw9C2fMvyYCkK7UmQKvHEZgEfXOZ8ykfO13tDKlMJyO1RPP9inzSktjJBexMuOEfbNvittYyIZ2//grKHUC0Pxz+mwCFetSjQC6r+m+jOR4njHNqlarW/uCesSkKDssA9LHhvlWY1dMdVQldVu5qzULyLUbDC6xWRD7A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ExKBfVHFyAKNXaVCpqA9M63cVUOK96U5xUEOim76X1zkhV3m5Y0CXFQvbvTpA/UUdpy4xWlky1vGVjl+w4jxtYZUX0kRVoFJfQHhSLuL99qHVHlJD6dbuGiSmxeo4nebTjDGaBoBmY2XVWfZDUXUlKUSWOYl3bQV3Nh3XusK6NIREGYsxuHqKUVvCMYbh+mzJwiMWr+kxFzTysORvl7jpVCdl9pC1iN1GLk45sJO03FfrZWPsPuqgWxZF1LLl3EpwwRPIj6v7KZLSfhJIMULNq6ehfvd3gwMfi3/N+VONSxEHcwUBy16bj7P3ZS/ZjbaXABuOoCfHNFD7Wgtdr+Njw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: sstabellini@xxxxxxxxxx, Artem_Mygaiev@xxxxxxxx, jbeulich@xxxxxxxx, Luca.Fancellu@xxxxxxx, roger.pau@xxxxxxxxxx, marmarek@xxxxxxxxxxxxxxxxxxxxxx, andrew.cooper3@xxxxxxxxxx, anthony.perard@xxxxxxxxxx
  • Delivery-date: Tue, 18 Feb 2025 09:57:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>



On 16.02.25 12:21, Oleksandr Andrushchenko wrote:
Hello, everybody!

As agreed before [1] I am sending a series to show two samples of the
formatting done with clang-format. The clang-format configuration can be
found at [2]. It already has some notes on previous discussions when
Luca presented his version of that configuration and which I used to
start from.

There are two diff files which show what happens in case the same is
applied to the whole xen/drivers directory:
- first one is the result of the "git diff" command, 1.2M [3]
- the second one is for "git diff --ignire-all-space", 600K [4]

This is not to limit the reviewers from seeing a bigger picture and not
only the files in this series.
N.B. xen/drivers uses tabs a lot, so this is no surprise the size
difference is big enough: roughly space conversion is half of the changes.

While reviewing the changes I have collected some of the unexpected things
done by clang-format and some interesting pieces. You can find those
below. For some of those I have filed an issue on clang-format and hope the
community will lead me in resolving those. Of course what I collected is
not the complete list of such changes, so I hope we can discuss missed
ones here.

 From this exercise I can definitely tell that clang-format does help a
lot and has potential to be employed as a code formatting tool for Xen.
Of course it cannot be used as is now and will require discussions on the
Xen coding style and possibly submitting patches to clang-format to
satisfy those which cannot be handled by the tool now.

Stay safe,
Oleksandr Andrushchenko

1. Const string arrays reformatting
In case the length of items change we might need to introduce a bigger
change wrt new formatting of unaffected lines
==============================================================================

--- a/xen/drivers/acpi/tables.c
+++ b/xen/drivers/acpi/tables.c
@@ -38,10 +38,10 @@
-static const char *__initdata
-mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" };
-static const char *__initdata
-mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" };
+static const char *__initdata mps_inti_flags_polarity[] = { "dfl", "high",
+                                                            "res", "low" };
+static const char *__initdata mps_inti_flags_trigger[] = { "dfl", "edge", 
"res",

--- a/xen/drivers/acpi/utilities/utglobal.c
+++ b/xen/drivers/acpi/utilities/utglobal.c
  static const char *const acpi_gbl_region_types[ACPI_NUM_PREDEFINED_REGIONS] = 
{
-       "SystemMemory",
-       "SystemIO",
-       "PCI_Config",
-       "EmbeddedControl",
-       "SMBus",
-       "CMOS",
-       "PCIBARTarget",
-       "DataTable"
+    "SystemMemory", "SystemIO", "PCI_Config",   "EmbeddedControl",
+    "SMBus",        "CMOS",     "PCIBARTarget", "DataTable"
  };

2. Long strings in ptintk violations
I filed an issue on printk format strings [5]
==============================================================================
@@ -225,9 +231,9 @@ void __init acpi_table_print_madt_entry(struct 
acpi_subtable_header *header)
          printk(KERN_DEBUG PREFIX
-                              "GIC Distributor (gic_id[0x%04x] address[0x%"PRIx64"] 
gsi_base[%d])\n",
-                              p->gic_id, p->base_address,
-                              p->global_irq_base);
+               "GIC Distributor (gic_id[0x%04x] address[0x%" PRIx64
+               "] gsi_base[%d])\n",
+               p->gic_id, p->base_address, p->global_irq_base);

@@ -629,12 +628,14 @@ acpi_parse_one_rmrr(struct acpi_dmar_header *header)
-           printk(XENLOG_ERR VTDPREFIX
-                  "Overlapping RMRRs [%"PRIx64",%"PRIx64"] and 
[%"PRIx64",%"PRIx64"]\n",
-                  rmrru->base_address, rmrru->end_address,
-                  base_addr, end_addr);
+            printk(XENLOG_ERR VTDPREFIX "Overlapping RMRRs [%" PRIx64
+                                        ",%" PRIx64 "] and [%" PRIx64
+                                        ",%" PRIx64 "]\n",
+                   rmrru->base_address, rmrru->end_address, base_addr,
+                   end_addr);

It doesn't understand properly things like "PRIx64" :(

Most of other items, I've mentioned already,
Unhappy: it's probably "known" things - identification of complex defines and
static struct/arrays declarations.

And for them, probably, no magic automation tools exist which will satisfy 
everybody as,
at least static definitions are usually formatted to achieve better readability
which is always subjective.

The tags /* clang-format off/clang-format on */ might be useful.

[..]

Honestly, It looks a bit strange that Xen community is considering batch 
automated code formatting,
For example Linux kernel cleanly rejected such approach.
Linux kernel docs "4.1.1. Coding style" section [1].

Another thing, checking the new code and accepting code style violations (if 
any) on per-patch basis.

[1] https://docs.kernel.org/process/4.Coding.html

BR,
-grygorii



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.