qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] hw/ide/ahci: silence a compiler warning


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH] hw/ide/ahci: silence a compiler warning
Date: Tue, 6 Oct 2020 18:11:40 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0

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]);
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]