* [PATCH] hw/ide/ahci: silence a compiler warning
@ 2020-10-06 15:42 Alex Bennée
2020-10-06 16:11 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 2+ messages in thread
From: Alex Bennée @ 2020-10-06 15:42 UTC (permalink / raw)
To: qemu-devel; +Cc: John Snow, Alex Bennée, open list:IDE
When built with -Og -ggdb with gcc 8.3 the compiler gets confused
reporting:
../../hw/ide/ahci.c: In function ‘ahci_populate_sglist’:
../../hw/ide/ahci.c:965:58: error: ‘tbl_entry_size’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
As prdtl being > 0 is a prerequisite for running the code which
guarantees we execute the loop at least once although not necessarily
resetting off_pos/off_idx which should short-circuit the test anyway.
To save grey hair initialise the value to zero and move the variable
to the local block so future changes can't accidentally use it.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
hw/ide/ahci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 680304a24c..f5c20c7d55 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -925,7 +925,6 @@ static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList *sglist,
uint64_t sum = 0;
int off_idx = -1;
int64_t off_pos = -1;
- int tbl_entry_size;
IDEBus *bus = &ad->port;
BusState *qbus = BUS(bus);
@@ -952,6 +951,7 @@ static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList *sglist,
/* Get entries in the PRDT, init a qemu sglist accordingly */
if (prdtl > 0) {
AHCI_SG *tbl = (AHCI_SG *)prdt;
+ int tbl_entry_size = 0;
sum = 0;
for (i = 0; i < prdtl; i++) {
tbl_entry_size = prdt_tbl_entry_size(&tbl[i]);
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] hw/ide/ahci: silence a compiler warning
2020-10-06 15:42 [PATCH] hw/ide/ahci: silence a compiler warning Alex Bennée
@ 2020-10-06 16:11 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-06 16:11 UTC (permalink / raw)
To: Alex Bennée, qemu-devel; +Cc: Paolo Bonzini, John Snow, open list:IDE
On 10/6/20 5:42 PM, Alex Bennée wrote:
> When built with -Og -ggdb with gcc 8.3 the compiler gets confused
> reporting:
>
> ../../hw/ide/ahci.c: In function ‘ahci_populate_sglist’:
> ../../hw/ide/ahci.c:965:58: error: ‘tbl_entry_size’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
> As prdtl being > 0 is a prerequisite for running the code which
> guarantees we execute the loop at least once although not necessarily
> resetting off_pos/off_idx which should short-circuit the test anyway.
>
> To save grey hair initialise the value to zero and move the variable
> to the local block so future changes can't accidentally use it.
Paolo fixed it yesterday but forgot to Cc you:
https://www.mail-archive.com/qemu-block@nongnu.org/msg75131.html
As your patch is also valid (and simpler):
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> hw/ide/ahci.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
> index 680304a24c..f5c20c7d55 100644
> --- a/hw/ide/ahci.c
> +++ b/hw/ide/ahci.c
> @@ -925,7 +925,6 @@ static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList *sglist,
> uint64_t sum = 0;
> int off_idx = -1;
> int64_t off_pos = -1;
> - int tbl_entry_size;
> IDEBus *bus = &ad->port;
> BusState *qbus = BUS(bus);
>
> @@ -952,6 +951,7 @@ static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList *sglist,
> /* Get entries in the PRDT, init a qemu sglist accordingly */
> if (prdtl > 0) {
> AHCI_SG *tbl = (AHCI_SG *)prdt;
> + int tbl_entry_size = 0;
> sum = 0;
> for (i = 0; i < prdtl; i++) {
> tbl_entry_size = prdt_tbl_entry_size(&tbl[i]);
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-06 16:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-06 15:42 [PATCH] hw/ide/ahci: silence a compiler warning Alex Bennée
2020-10-06 16:11 ` Philippe Mathieu-Daudé
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).