qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: "Matheus K. Ferst" <matheus.ferst@eldorado.org.br>,
	qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, clg@kaod.org, david@gibson.dropbear.id.au
Subject: Re: [PATCH 1/2] ppc/pnv: initialize 'taddr' in pnv_phb3_translate_tve()
Date: Wed, 26 Jan 2022 17:09:49 -0300	[thread overview]
Message-ID: <7a5857b0-f0dc-5dce-d7d5-80ca5fade3d0@gmail.com> (raw)
In-Reply-To: <582d8d5f-d46f-daba-5911-96b0a8f78bf4@eldorado.org.br>



On 1/26/22 14:28, Matheus K. Ferst wrote:
> On 26/01/2022 10:41, Daniel Henrique Barboza wrote:
>> The 'taddr' variable is left unintialized, being set only inside the
>> "while ((lev--) >= 0)" loop where we get the TCE address. The 'lev' var
>> is an int32_t that is being initiliazed by the GETFIELD() macro, which
>> returns an uint64_t.
>>
>> For a human reader this means that 'lev' will always be positive or zero.
>> But some compilers may beg to differ. 'lev' being an int32_t can in theory
>> be set as negative, and the "while ((lev--) >= 0)" loop might never be
>> reached, and 'taddr' will be left unitialized.
> 
> If we expect this code to execute at least once, wouldn't it be better to use a do-while? E.g.:
> 
> do {
>      lev--;
> 
>      /* Grab the TCE address */
>      taddr = base | (((addr >> sh) & ((1ul << tbl_shift) - 1)) << 3);
>      if (dma_memory_read(&address_space_memory, taddr, &tce,
>      /* ... */
>      }
>      sh -= tbl_shift;
>      base = tce & ~0xfffull;
> } while (lev >= 0);
> 
> Otherwise, I think we'll need to initialize tce too.

Initializing tce isn't necessary, at least as far as compiler warning goes,
because tce will be defaulted to zero and its current use (tce & 3, tce & 2,
tce & 1 operations) isn't offending the compiler. For now at least.

That said, I think using a do/while() loop is an idea that fixes the issue while
keeping the code flow, without having to add extra initializations, so I ended
up changing it as you suggested.


Thanks,


Daniel

> 
> Thanks,
> Matheus K. Ferst
> Instituto de Pesquisas ELDORADO <http://www.eldorado.org.br/>
> Analista de Software
> Aviso Legal - Disclaimer <https://www.eldorado.org.br/disclaimer.html>


  reply	other threads:[~2022-01-26 20:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-26 13:41 [PATCH 0/2] initialize 'taddr' in pnv_phbX_translate_tve() Daniel Henrique Barboza
2022-01-26 13:41 ` [PATCH 1/2] ppc/pnv: initialize 'taddr' in pnv_phb3_translate_tve() Daniel Henrique Barboza
2022-01-26 17:28   ` Matheus K. Ferst
2022-01-26 20:09     ` Daniel Henrique Barboza [this message]
2022-01-26 13:41 ` [PATCH 2/2] ppc/pnv: initialize 'taddr' in pnv_phb4_translate_tve() Daniel Henrique Barboza

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7a5857b0-f0dc-5dce-d7d5-80ca5fade3d0@gmail.com \
    --to=danielhb413@gmail.com \
    --cc=clg@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=matheus.ferst@eldorado.org.br \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).