* [PATCH 0/2] lguest: Minor cleanups of boot code
@ 2016-03-03 12:01 Paul Bolle
2016-03-03 12:01 ` [PATCH 1/2] lguest: read length of device_cap later Paul Bolle
2016-03-03 12:01 ` [PATCH 2/2] lguest: read offset " Paul Bolle
0 siblings, 2 replies; 5+ messages in thread
From: Paul Bolle @ 2016-03-03 12:01 UTC (permalink / raw)
To: Rusty Russell, Thomas Gleixner, Ingo Molnar, H. Peter Anvin
Cc: x86, lguest, linux-kernel
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] lguest: read length of device_cap later
2016-03-03 12:01 [PATCH 0/2] lguest: Minor cleanups of boot code Paul Bolle
@ 2016-03-03 12:01 ` Paul Bolle
2016-06-10 9:42 ` [tip:x86/cleanups] lguest: Read " tip-bot for Paul Bolle
2016-03-03 12:01 ` [PATCH 2/2] lguest: read offset " Paul Bolle
1 sibling, 1 reply; 5+ messages in thread
From: Paul Bolle @ 2016-03-03 12:01 UTC (permalink / raw)
To: Rusty Russell, Thomas Gleixner, Ingo Molnar, H. Peter Anvin
Cc: x86, lguest, linux-kernel
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] lguest: read offset of device_cap later
2016-03-03 12:01 [PATCH 0/2] lguest: Minor cleanups of boot code Paul Bolle
2016-03-03 12:01 ` [PATCH 1/2] lguest: read length of device_cap later Paul Bolle
@ 2016-03-03 12:01 ` Paul Bolle
2016-06-10 9:43 ` [tip:x86/cleanups] lguest: Read " tip-bot for Paul Bolle
1 sibling, 1 reply; 5+ messages in thread
From: Paul Bolle @ 2016-03-03 12:01 UTC (permalink / raw)
To: Rusty Russell, Thomas Gleixner, Ingo Molnar, H. Peter Anvin
Cc: x86, lguest, linux-kernel
Read the offset of the capability with type VIRTIO_PCI_CAP_DEVICE_CFG
only when we're sure we're going to need it. Which is when all checks
have passed and we know we have a virtio console with an emerg_wr field.
Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
---
arch/x86/lguest/boot.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index 535e3197d0c7..3b0c0eb4abf8 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -1233,8 +1233,6 @@ static void write_bar_via_cfg(u32 cfg_offset, u32 off, u32 val)
static void probe_pci_console(void)
{
u8 cap, common_cap = 0, device_cap = 0;
- /* Offset within BAR0 */
- u32 device_offset;
u32 device_len;
/* Avoid recursive printk into here. */
@@ -1258,21 +1256,16 @@ 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;
type = read_pci_config_byte(0, 1, 0,
cap + offsetof(struct virtio_pci_cap, cfg_type));
bar = read_pci_config_byte(0, 1, 0,
cap + offsetof(struct virtio_pci_cap, bar));
- offset = read_pci_config(0, 1, 0,
- cap + offsetof(struct virtio_pci_cap, offset));
switch (type) {
case VIRTIO_PCI_CAP_DEVICE_CFG:
- if (bar == 0) {
+ if (bar == 0)
device_cap = cap;
- device_offset = offset;
- }
break;
case VIRTIO_PCI_CAP_PCI_CFG:
console_access_cap = cap;
@@ -1302,7 +1295,8 @@ static void probe_pci_console(void)
return;
}
- console_cfg_offset = device_offset;
+ console_cfg_offset = read_pci_config(0, 1, 0,
+ device_cap + offsetof(struct virtio_pci_cap, offset));
printk(KERN_INFO "lguest: Console via virtio-pci emerg_wr\n");
}
--
2.4.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip:x86/cleanups] lguest: Read length of device_cap later
2016-03-03 12:01 ` [PATCH 1/2] lguest: read length of device_cap later Paul Bolle
@ 2016-06-10 9:42 ` tip-bot for Paul Bolle
0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Paul Bolle @ 2016-06-10 9:42 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, hpa, pebolle, rusty, tglx, mingo
Commit-ID: 7faf90ef995ea470f32f43810266ece8ac8ba6c7
Gitweb: http://git.kernel.org/tip/7faf90ef995ea470f32f43810266ece8ac8ba6c7
Author: Paul Bolle <pebolle@tiscali.nl>
AuthorDate: Thu, 3 Mar 2016 13:01:40 +0100
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Fri, 10 Jun 2016 11:39:09 +0200
lguest: Read length of device_cap later
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>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: lguest@lists.ozlabs.org
Link: http://lkml.kernel.org/r/1457006501-5377-2-git-send-email-pebolle@tiscali.nl
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
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 3847e73..146d11c 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");
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip:x86/cleanups] lguest: Read offset of device_cap later
2016-03-03 12:01 ` [PATCH 2/2] lguest: read offset " Paul Bolle
@ 2016-06-10 9:43 ` tip-bot for Paul Bolle
0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Paul Bolle @ 2016-06-10 9:43 UTC (permalink / raw)
To: linux-tip-commits; +Cc: hpa, mingo, rusty, linux-kernel, pebolle, tglx
Commit-ID: cf2cf0f50c14e86e04cda2c684357eed77922666
Gitweb: http://git.kernel.org/tip/cf2cf0f50c14e86e04cda2c684357eed77922666
Author: Paul Bolle <pebolle@tiscali.nl>
AuthorDate: Thu, 3 Mar 2016 13:01:41 +0100
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Fri, 10 Jun 2016 11:39:09 +0200
lguest: Read offset of device_cap later
Read the offset of the capability with type VIRTIO_PCI_CAP_DEVICE_CFG
only when we're sure we're going to need it. Which is when all checks
have passed and we know we have a virtio console with an emerg_wr field.
Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: lguest@lists.ozlabs.org
Link: http://lkml.kernel.org/r/1457006501-5377-3-git-send-email-pebolle@tiscali.nl
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/lguest/boot.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index 146d11c..25da5bc8 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -1233,8 +1233,6 @@ static void write_bar_via_cfg(u32 cfg_offset, u32 off, u32 val)
static void probe_pci_console(void)
{
u8 cap, common_cap = 0, device_cap = 0;
- /* Offset within BAR0 */
- u32 device_offset;
u32 device_len;
/* Avoid recursive printk into here. */
@@ -1258,21 +1256,16 @@ 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;
type = read_pci_config_byte(0, 1, 0,
cap + offsetof(struct virtio_pci_cap, cfg_type));
bar = read_pci_config_byte(0, 1, 0,
cap + offsetof(struct virtio_pci_cap, bar));
- offset = read_pci_config(0, 1, 0,
- cap + offsetof(struct virtio_pci_cap, offset));
switch (type) {
case VIRTIO_PCI_CAP_DEVICE_CFG:
- if (bar == 0) {
+ if (bar == 0)
device_cap = cap;
- device_offset = offset;
- }
break;
case VIRTIO_PCI_CAP_PCI_CFG:
console_access_cap = cap;
@@ -1302,7 +1295,8 @@ static void probe_pci_console(void)
return;
}
- console_cfg_offset = device_offset;
+ console_cfg_offset = read_pci_config(0, 1, 0,
+ device_cap + offsetof(struct virtio_pci_cap, offset));
printk(KERN_INFO "lguest: Console via virtio-pci emerg_wr\n");
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-06-10 9:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-03 12:01 [PATCH 0/2] lguest: Minor cleanups of boot code Paul Bolle
2016-03-03 12:01 ` [PATCH 1/2] lguest: read length of device_cap later Paul Bolle
2016-06-10 9:42 ` [tip:x86/cleanups] lguest: Read " tip-bot for Paul Bolle
2016-03-03 12:01 ` [PATCH 2/2] lguest: read offset " Paul Bolle
2016-06-10 9:43 ` [tip:x86/cleanups] lguest: Read " tip-bot for Paul Bolle
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).