Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1349079 > unrolled thread

[PATCH 0/2] lguest: Minor cleanups of boot code

Started byPaul Bolle <pebolle@tiscali.nl>
First post2016-03-03 13:10 +0100
Last post2016-03-03 13:10 +0100
Articles 2 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/2] lguest: Minor cleanups of boot code Paul Bolle <pebolle@tiscali.nl> - 2016-03-03 13:10 +0100
    [PATCH 1/2] lguest: read length of device_cap later Paul Bolle <pebolle@tiscali.nl> - 2016-03-03 13:10 +0100

#1349079 — [PATCH 0/2] lguest: Minor cleanups of boot code

FromPaul Bolle <pebolle@tiscali.nl>
Date2016-03-03 13:10 +0100
Subject[PATCH 0/2] lguest: Minor cleanups of boot code
Message-ID<r8AeS-6Vw-23@gated-at.bofh.it>
Building arch/x86/lguest/boot.o triggers two warnings:
    arch/x86/lguest/boot.c: In function 'early_put_chars':
    arch/x86/lguest/boot.c:1300:5: warning: 'device_len' may be used uninitialized in this function [-Wmaybe-uninitialized]
      if (device_len < (offsetof(struct virtio_console_config, emerg_wr)
         ^
    arch/x86/lguest/boot.c:1238:6: note: 'device_len' was declared here
      u32 device_len;
          ^
    arch/x86/lguest/boot.c:1306:21: warning: 'device_offset' may be used uninitialized in this function [-Wmaybe-uninitialized]
      console_cfg_offset = device_offset;
                         ^
    arch/x86/lguest/boot.c:1237:6: note: 'device_offset' was declared here
      u32 device_offset;
          ^

These annoy me for some time now. So I investigated whether
probe_pci_console(), which actually triggers these warnings, could be
reorganized to make these warnings go away. (Because I really dislike to
initialize variables to some default value just to shut up the compiler.)

I came up with this short series. It makes, I think, the code clearer for the
people reading it. And as a bonus the compiler is silent now.

Paul Bolle (2):
  lguest: read length of device_cap later
  lguest: read offset of device_cap later

 arch/x86/lguest/boot.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

-- 
2.4.3

[toc] | [next] | [standalone]


#1349082 — [PATCH 1/2] lguest: read length of device_cap later

FromPaul Bolle <pebolle@tiscali.nl>
Date2016-03-03 13:10 +0100
Subject[PATCH 1/2] lguest: read length of device_cap later
Message-ID<r8AeU-6Vw-57@gated-at.bofh.it>
In reply to#1349079
Read the length of the capability with type VIRTIO_PCI_CAP_DEVICE_CFG
only when we're sure we're going to need it. Which is just before the
check whether the virtio console actually has an emerg_wr field.

Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
---
 arch/x86/lguest/boot.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index 4ba229ac3f4f..535e3197d0c7 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -1258,7 +1258,7 @@ static void probe_pci_console(void)
 		u8 vndr = read_pci_config_byte(0, 1, 0, cap);
 		if (vndr == PCI_CAP_ID_VNDR) {
 			u8 type, bar;
-			u32 offset, length;
+			u32 offset;
 
 			type = read_pci_config_byte(0, 1, 0,
 			    cap + offsetof(struct virtio_pci_cap, cfg_type));
@@ -1266,15 +1266,12 @@ static void probe_pci_console(void)
 			    cap + offsetof(struct virtio_pci_cap, bar));
 			offset = read_pci_config(0, 1, 0,
 			    cap + offsetof(struct virtio_pci_cap, offset));
-			length = read_pci_config(0, 1, 0,
-			    cap + offsetof(struct virtio_pci_cap, length));
 
 			switch (type) {
 			case VIRTIO_PCI_CAP_DEVICE_CFG:
 				if (bar == 0) {
 					device_cap = cap;
 					device_offset = offset;
-					device_len = length;
 				}
 				break;
 			case VIRTIO_PCI_CAP_PCI_CFG:
@@ -1297,6 +1294,8 @@ static void probe_pci_console(void)
 	 * emerg_wr.  If it doesn't support VIRTIO_CONSOLE_F_EMERG_WRITE
 	 * it should ignore the access.
 	 */
+	device_len = read_pci_config(0, 1, 0,
+			device_cap + offsetof(struct virtio_pci_cap, length));
 	if (device_len < (offsetof(struct virtio_console_config, emerg_wr)
 			  + sizeof(u32))) {
 		printk(KERN_ERR "lguest: console missing emerg_wr field\n");
-- 
2.4.3

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web