Skip to contentSkip to conversation

vfio-pci/nvlink2: Fix ancient gcc warnings

PATCH Applied Alexey Kardashevskiy 4 participants 5 messages Jan 23, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio-pci/nvlink2: Fix ancient gcc warnings

Using the {0} construct as a generic initializer is perfectly fine in C, however due to a bug in old gcc there is a warning:

+ /kisskb/src/drivers/vfio/pci/vfio_pci_nvlink2.c: warning: (near
initialization for 'cap.header') [-Wmissing-braces]: => 181:9

Since for whatever reason we still want to compile the modern kernel with such an old gcc without warnings, this changes the capabilities initialization.

The gcc bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119

---
 drivers/vfio/pci/vfio_pci_nvlink2.c | 30 ++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/vfio/pci/vfio_pci_nvlink2.c +15 -15
index 054a2cf..91d945b 100644
@@ -178,11 +178,11 @@ static int vfio_pci_nvgpu_add_capability(struct vfio_pci_device *vdev,
 		struct vfio_pci_region *region, struct vfio_info_cap *caps)
 {
 	struct vfio_pci_nvgpu_data *data = region->data;
-	struct vfio_region_info_cap_nvlink2_ssatgt cap = { 0 };
-
-	cap.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT;
-	cap.header.version = 1;
-	cap.tgt = data->gpu_tgt;
+	struct vfio_region_info_cap_nvlink2_ssatgt cap = {
+		.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT,
+		.header.version = 1,
+		.tgt = data->gpu_tgt
+	};
 
 	return vfio_info_add_capability(caps, &cap.header, sizeof(cap));
 }
@@ -365,18 +365,18 @@ static int vfio_pci_npu2_add_capability(struct vfio_pci_device *vdev,
 		struct vfio_pci_region *region, struct vfio_info_cap *caps)
 {
 	struct vfio_pci_npu2_data *data = region->data;
-	struct vfio_region_info_cap_nvlink2_ssatgt captgt = { 0 };
-	struct vfio_region_info_cap_nvlink2_lnkspd capspd = { 0 };
+	struct vfio_region_info_cap_nvlink2_ssatgt captgt = {
+		.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT,
+		.header.version = 1,
+		.tgt = data->gpu_tgt
+	};
+	struct vfio_region_info_cap_nvlink2_lnkspd capspd = {
+		.header.id = VFIO_REGION_INFO_CAP_NVLINK2_LNKSPD,
+		.header.version = 1,
+		.link_speed = data->link_speed
+	};
 	int ret;
 
-	captgt.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT;
-	captgt.header.version = 1;
-	captgt.tgt = data->gpu_tgt;
-
-	capspd.header.id = VFIO_REGION_INFO_CAP_NVLINK2_LNKSPD;
-	capspd.header.version = 1;
-	capspd.link_speed = data->link_speed;
-
 	ret = vfio_info_add_capability(caps, &captgt.header, sizeof(captgt));
 	if (ret)
 		return ret;
Signature · 1 line
2.17.1
#1 lore raw

Hi Geert,

The below patch comes about from the build regressions and improvements list you've sent out, but something doesn't add up that we'd be testing with an old compiler where initialization with { 0 } generates a "missing braces around initialization" warning. Is this really the case or are we missing something here? There's no harm that I can see with Alexey's fix, but are these really just false positives from a compiler bug that we should selectively ignore if the "fix" is less clean? Thanks,

Alex

Quoted 67 lines · On Wed, 23 Jan 2019 15:07:11 +1100 Alexey Kardashevskiy <[email protected]> wrote:

Using the {0} construct as a generic initializer is perfectly fine in C, however due to a bug in old gcc there is a warning:

+ /kisskb/src/drivers/vfio/pci/vfio_pci_nvlink2.c: warning: (near
initialization for 'cap.header') [-Wmissing-braces]: => 181:9

Since for whatever reason we still want to compile the modern kernel with such an old gcc without warnings, this changes the capabilities initialization.

The gcc bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119

---
 drivers/vfio/pci/vfio_pci_nvlink2.c | 30 ++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/vfio/pci/vfio_pci_nvlink2.c +15 -15
index 054a2cf..91d945b 100644
@@ -178,11 +178,11 @@ static int vfio_pci_nvgpu_add_capability(struct vfio_pci_device *vdev,
 		struct vfio_pci_region *region, struct vfio_info_cap *caps)
 {
 	struct vfio_pci_nvgpu_data *data = region->data;
-	struct vfio_region_info_cap_nvlink2_ssatgt cap = { 0 };
-
-	cap.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT;
-	cap.header.version = 1;
-	cap.tgt = data->gpu_tgt;
+	struct vfio_region_info_cap_nvlink2_ssatgt cap = {
+		.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT,
+		.header.version = 1,
+		.tgt = data->gpu_tgt
+	};
 
 	return vfio_info_add_capability(caps, &cap.header, sizeof(cap));
 }
@@ -365,18 +365,18 @@ static int vfio_pci_npu2_add_capability(struct vfio_pci_device *vdev,
 		struct vfio_pci_region *region, struct vfio_info_cap *caps)
 {
 	struct vfio_pci_npu2_data *data = region->data;
-	struct vfio_region_info_cap_nvlink2_ssatgt captgt = { 0 };
-	struct vfio_region_info_cap_nvlink2_lnkspd capspd = { 0 };
+	struct vfio_region_info_cap_nvlink2_ssatgt captgt = {
+		.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT,
+		.header.version = 1,
+		.tgt = data->gpu_tgt
+	};
+	struct vfio_region_info_cap_nvlink2_lnkspd capspd = {
+		.header.id = VFIO_REGION_INFO_CAP_NVLINK2_LNKSPD,
+		.header.version = 1,
+		.link_speed = data->link_speed
+	};
 	int ret;
 
-	captgt.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT;
-	captgt.header.version = 1;
-	captgt.tgt = data->gpu_tgt;
-
-	capspd.header.id = VFIO_REGION_INFO_CAP_NVLINK2_LNKSPD;
-	capspd.header.version = 1;
-	capspd.link_speed = data->link_speed;
-
 	ret = vfio_info_add_capability(caps, &captgt.header, sizeof(captgt));
 	if (ret)
 		return ret;
#2 lore raw

Hi Alex,

Quoted 8 lines · Alex Williamson

The below patch comes about from the build regressions and improvements list you've sent out, but something doesn't add up that we'd be testing with an old compiler where initialization with { 0 } generates a "missing braces around initialization" warning. Is this really the case or are we missing something here? There's no harm that I can see with Alexey's fix, but are these really just false positives from a compiler bug that we should selectively ignore if the "fix" is less clean? Thanks,

Yes, they are false positives, AFAIK.

Quoted 8 lines
Quoted 5 lines · On Wed, 23 Jan 2019 15:07:11 +1100 Alexey Kardashevskiy <[email protected]> wrote:

Using the {0} construct as a generic initializer is perfectly fine in C, however due to a bug in old gcc there is a warning:

+ /kisskb/src/drivers/vfio/pci/vfio_pci_nvlink2.c: warning: (near
initialization for 'cap.header') [-Wmissing-braces]: => 181:9

These all seem to come from an old gcc 4.6, which is the oldest still supported version for compiling Linux
http://kisskb.ellerman.id.au/kisskb/buildresult/13663641/

Note that kisskb is also using gcc 4.6.3 for s390x and mips, which are the only other builds showing missing braces warnings.

Quoted 21 lines
Quoted 21 lines

Since for whatever reason we still want to compile the modern kernel with such an old gcc without warnings, this changes the capabilities initialization.

The gcc bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119

---
 drivers/vfio/pci/vfio_pci_nvlink2.c | 30 ++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/vfio/pci/vfio_pci_nvlink2.c +0 -2
index 054a2cf..91d945b 100644
@@ -178,11 +178,11 @@ static int vfio_pci_nvgpu_add_capability(struct vfio_pci_device *vdev,
              struct vfio_pci_region *region, struct vfio_info_cap *caps)
 {
      struct vfio_pci_nvgpu_data *data = region->data;
-     struct vfio_region_info_cap_nvlink2_ssatgt cap = { 0 };
-
Quoted 8 lines

drivers/vfio/pci/vfio_pci_nvlink2.c static int vfio_pci_nvgpu_add_capability(struct vfio_pci_device *vdev, · line 185

Quoted 8 lines
drivers/vfio/pci/vfio_pci_nvlink2.c +5 -3
-     cap.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT;
-     cap.header.version = 1;
-     cap.tgt = data->gpu_tgt;
+     struct vfio_region_info_cap_nvlink2_ssatgt cap = {
+             .header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT,
+             .header.version = 1,
+             .tgt = data->gpu_tgt
+     };

I think the simpler change

- struct vfio_region_info_cap_nvlink2_ssatgt cap = { 0 };
+ struct vfio_region_info_cap_nvlink2_ssatgt cap = { { 0 } };

should also work (tested with gcc 4.1).
That's how most of these were fixed in the past.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#3 lore raw
Quoted 24 lines · Geert Uytterhoeven

Hi Alex,

Quoted 8 lines · Alex Williamson

The below patch comes about from the build regressions and improvements list you've sent out, but something doesn't add up that we'd be testing with an old compiler where initialization with { 0 } generates a "missing braces around initialization" warning. Is this really the case or are we missing something here? There's no harm that I can see with Alexey's fix, but are these really just false positives from a compiler bug that we should selectively ignore if the "fix" is less clean? Thanks,

Yes, they are false positives, AFAIK.

Quoted 8 lines
Quoted 5 lines · On Wed, 23 Jan 2019 15:07:11 +1100 Alexey Kardashevskiy <[email protected]> wrote:

Using the {0} construct as a generic initializer is perfectly fine in C, however due to a bug in old gcc there is a warning:

+ /kisskb/src/drivers/vfio/pci/vfio_pci_nvlink2.c: warning: (near
initialization for 'cap.header') [-Wmissing-braces]: => 181:9

Quoted 6 lines

These all seem to come from an old gcc 4.6, which is the oldest still supported version for compiling Linux
http://kisskb.ellerman.id.au/kisskb/buildresult/13663641/

Note that kisskb is also using gcc 4.6.3 for s390x and mips, which are the only other builds showing missing braces warnings.

As documented here:

https://www.kernel.org/doc/html/latest/process/changes.html#current-minimal-requirements

x86 has effectively dropped support for 4.6 because it doesn't support retpoline and CONFIG_RETPOLINE is default y.

So it might be time to stop supporting 4.6, but I'd rather that happened by someone sending a patch to change the requirements doc above, and then kisskb can stop doing the builds with 4.6.

cheers

#4 lore raw
In reply to Alexey Kardashevskiy
Quoted 6 lines · On Wed, 23 Jan 2019 15:07:11 +1100 Alexey Kardashevskiy <[email protected]> wrote:

Using the {0} construct as a generic initializer is perfectly fine in C, however due to a bug in old gcc there is a warning:

+ /kisskb/src/drivers/vfio/pci/vfio_pci_nvlink2.c: warning: (near
initialization for 'cap.header') [-Wmissing-braces]: => 181:9

Quoted 7 lines

Since for whatever reason we still want to compile the modern kernel with such an old gcc without warnings, this changes the capabilities initialization.

The gcc bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119

Added Fixes: and Reported-by: tags.

Applied to for-linus branch for v5.0. Thanks,

Alex

Quoted 54 lines
---
 drivers/vfio/pci/vfio_pci_nvlink2.c | 30 ++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/vfio/pci/vfio_pci_nvlink2.c +15 -15
index 054a2cf..91d945b 100644
@@ -178,11 +178,11 @@ static int vfio_pci_nvgpu_add_capability(struct vfio_pci_device *vdev,
 		struct vfio_pci_region *region, struct vfio_info_cap *caps)
 {
 	struct vfio_pci_nvgpu_data *data = region->data;
-	struct vfio_region_info_cap_nvlink2_ssatgt cap = { 0 };
-
-	cap.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT;
-	cap.header.version = 1;
-	cap.tgt = data->gpu_tgt;
+	struct vfio_region_info_cap_nvlink2_ssatgt cap = {
+		.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT,
+		.header.version = 1,
+		.tgt = data->gpu_tgt
+	};
 
 	return vfio_info_add_capability(caps, &cap.header, sizeof(cap));
 }
@@ -365,18 +365,18 @@ static int vfio_pci_npu2_add_capability(struct vfio_pci_device *vdev,
 		struct vfio_pci_region *region, struct vfio_info_cap *caps)
 {
 	struct vfio_pci_npu2_data *data = region->data;
-	struct vfio_region_info_cap_nvlink2_ssatgt captgt = { 0 };
-	struct vfio_region_info_cap_nvlink2_lnkspd capspd = { 0 };
+	struct vfio_region_info_cap_nvlink2_ssatgt captgt = {
+		.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT,
+		.header.version = 1,
+		.tgt = data->gpu_tgt
+	};
+	struct vfio_region_info_cap_nvlink2_lnkspd capspd = {
+		.header.id = VFIO_REGION_INFO_CAP_NVLINK2_LNKSPD,
+		.header.version = 1,
+		.link_speed = data->link_speed
+	};
 	int ret;
 
-	captgt.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT;
-	captgt.header.version = 1;
-	captgt.tgt = data->gpu_tgt;
-
-	capspd.header.id = VFIO_REGION_INFO_CAP_NVLINK2_LNKSPD;
-	capspd.header.version = 1;
-	capspd.link_speed = data->link_speed;
-
 	ret = vfio_info_add_capability(caps, &captgt.header, sizeof(captgt));
 	if (ret)
 		return ret;