From: Thomas Huth <thuth@redhat.com>
To: "Yoshinori Sato" <ysato@users.sourceforge.jp>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Magnus Damm" <magnus.damm@gmail.com>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Richard Henderson" <rth@twiddle.net>
Subject: Re: [PULL 07/15] hw/timer: RX62N 8-Bit timer (TMR)
Date: Tue, 7 Jul 2020 17:06:07 +0200 [thread overview]
Message-ID: <6e36f1f3-06e2-9635-960d-e2f7f75b2040@redhat.com> (raw)
In-Reply-To: <878sfv9xmi.wl-ysato@users.sourceforge.jp>
On 07/07/2020 17.02, Yoshinori Sato wrote:
> On Mon, 29 Jun 2020 18:58:56 +0900,
> Philippe Mathieu-Daudé wrote:
>>
>> Hi Yoshinori,
>>
>> On 6/25/20 11:25 AM, Peter Maydell wrote:
>>> On Sun, 21 Jun 2020 at 13:54, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>>>>
>>>> From: Yoshinori Sato <ysato@users.sourceforge.jp>
>>>>
>>>> renesas_tmr: 8bit timer modules.
>>>
>>> Hi; the recent Coverity run reports a potential bug in this
>>> code: (CID 1429976)
>>>
>>>
>>>> +static uint16_t read_tcnt(RTMRState *tmr, unsigned size, int ch)
>>>> +{
>>>> + int64_t delta, now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>>>> + int elapsed, ovf = 0;
>>>> + uint16_t tcnt[2];
>>>
>>> Here we declare tcnt[] but do not initialize its contents...
>>>
>>>> + uint32_t ret;
>>>> +
>>>> + delta = (now - tmr->tick) * NANOSECONDS_PER_SECOND / tmr->input_freq;
>>>> + if (delta > 0) {
>>>> + tmr->tick = now;
>>>> +
>>>> + if (FIELD_EX8(tmr->tccr[1], TCCR, CSS) == INTERNAL) {
>>>> + /* timer1 count update */
>>>> + elapsed = elapsed_time(tmr, 1, delta);
>>>> + if (elapsed >= 0x100) {
>>>> + ovf = elapsed >> 8;
>>>> + }
>>>> + tcnt[1] = tmr->tcnt[1] + (elapsed & 0xff);
>>>> + }
>>>> + switch (FIELD_EX8(tmr->tccr[0], TCCR, CSS)) {
>>>> + case INTERNAL:
>>>> + elapsed = elapsed_time(tmr, 0, delta);
>>>> + tcnt[0] = tmr->tcnt[0] + elapsed;
>>>> + break;
>>>> + case CASCADING:
>>>> + if (ovf > 0) {
>>>> + tcnt[0] = tmr->tcnt[0] + ovf;
>>>> + }
>>>> + break;
>>>> + }
>>>
>>> ...but not all cases here set both tcnt[0] and tcnt[1]
>>> (for instance in the "case CASCADING:" if ovf <=0 we
>>> won't set either of them)...
>>>
>>>> + } else {
>>>> + tcnt[0] = tmr->tcnt[0];
>>>> + tcnt[1] = tmr->tcnt[1];
>>>> + }
>>>> + if (size == 1) {
>>>> + return tcnt[ch];
>>>> + } else {
>>>> + ret = 0;
>>>> + ret = deposit32(ret, 0, 8, tcnt[1]);
>>>> + ret = deposit32(ret, 8, 8, tcnt[0]);
>>>> + return ret;
>>>
>>> ...and so here we will end up returning uninitialized
>>> data. Presumably the spec says what value is actually
>>> supposed to be returned in these cases?
>>>
>>> PS: the "else" branch with the deposit32() calls could be
>>> rewritten more simply as
>>> return lduw_be_p(tcnt);
>>>
>>>> +static uint64_t tmr_read(void *opaque, hwaddr addr, unsigned size)
>>>> +{
>>>
>>> In this function Coverity reports a missing "break" (CID 1429977):
>>>
>>>> + case A_TCORA:
>>>> + if (size == 1) {
>>>> + return tmr->tcora[ch];
>>>> + } else if (ch == 0) {
>>>> + return concat_reg(tmr->tcora);
>>>> + }
>>>
>>> Here execution can fall through but there is no 'break' or '/* fallthrough */'.
>>>
>>>> + case A_TCORB:
>>>> + if (size == 1) {
>>>> + return tmr->tcorb[ch];
>>>> + } else {
>>>> + return concat_reg(tmr->tcorb);
>>>> + }
>>>
>>> Is it correct that the A_TCORA and A_TCORB code is different?
>>> It looks odd, so if this is intentional then a comment describing
>>> why it is so might be helpful to readers.
>>
>> Can you address Peter's comments please?
>
> This register can 8bit and 16bit access.
> 8bit case return separate single TCORA or TCORB.
> 16bit case return merged two channel's TCORA or TCORB.
> high byte: channel 0 register.
> low byte: channel 1 register
So could you please provide a patch that either adds the missing
"break;" statement between the cases here, or adds a "/* fallthrough */"
comment between the cases?
Thanks,
Thomas
next prev parent reply other threads:[~2020-07-07 15:07 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-21 12:47 [PULL 00/15] Renesas hardware patches for 2020-06-21 Philippe Mathieu-Daudé
2020-06-21 12:47 ` [PULL 01/15] MAINTAINERS: Cover sh_intc files in the R2D/Shix machine sections Philippe Mathieu-Daudé
2020-06-21 12:47 ` [PULL 02/15] MAINTAINERS: Add an entry for common Renesas peripherals Philippe Mathieu-Daudé
2020-06-21 12:47 ` [PULL 03/15] hw/sh4: Use MemoryRegion typedef Philippe Mathieu-Daudé
2020-06-21 12:47 ` [PULL 04/15] hw/sh4: Extract timer definitions to 'hw/timer/tmu012.h' Philippe Mathieu-Daudé
2020-06-21 12:47 ` [PULL 05/15] hw/timer/sh_timer: Remove unused 'qemu/timer.h' include Philippe Mathieu-Daudé
2020-06-21 12:47 ` [PULL 06/15] hw/intc: RX62N interrupt controller (ICUa) Philippe Mathieu-Daudé
2020-06-21 12:47 ` [PULL 07/15] hw/timer: RX62N 8-Bit timer (TMR) Philippe Mathieu-Daudé
2020-06-25 9:25 ` Peter Maydell
2020-06-25 10:06 ` Thomas Huth
2020-06-25 12:19 ` Peter Maydell
2020-06-29 9:58 ` Philippe Mathieu-Daudé
2020-07-07 4:22 ` Philippe Mathieu-Daudé
2020-07-07 15:02 ` Yoshinori Sato
2020-07-07 15:04 ` Philippe Mathieu-Daudé
2020-07-07 15:06 ` Thomas Huth [this message]
2020-07-08 15:37 ` Yoshinori Sato
2020-06-21 12:48 ` [PULL 08/15] hw/timer: RX62N compare match timer (CMT) Philippe Mathieu-Daudé
2020-06-21 12:48 ` [PULL 09/15] hw/char: RX62N serial communication interface (SCI) Philippe Mathieu-Daudé
2020-06-21 12:48 ` [PULL 10/15] hw/rx: RX62N microcontroller (MCU) Philippe Mathieu-Daudé
2020-06-21 12:48 ` [PULL 11/15] hw/rx: Honor -accel qtest Philippe Mathieu-Daudé
2020-06-21 12:48 ` [PULL 12/15] hw/rx: Register R5F562N7 and R5F562N8 MCUs Philippe Mathieu-Daudé
2020-06-21 12:48 ` [PULL 13/15] hw/rx: Add RX GDB simulator Philippe Mathieu-Daudé
2020-06-21 12:48 ` [PULL 14/15] BootLinuxConsoleTest: Test the " Philippe Mathieu-Daudé
2020-06-21 12:48 ` [PULL 15/15] docs: Document the RX target Philippe Mathieu-Daudé
2020-06-22 16:01 ` [PULL 00/15] Renesas hardware patches for 2020-06-21 Peter Maydell
2020-06-22 16:19 ` Peter Maydell
2020-06-22 16:45 ` Philippe Mathieu-Daudé
2020-06-22 17:22 ` Aleksandar Markovic
2020-06-22 17:30 ` Aleksandar Markovic
2020-06-22 19:17 ` Philippe Mathieu-Daudé
2020-06-22 19:41 ` Aleksandar Markovic
2020-06-22 16:25 ` Philippe Mathieu-Daudé
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=6e36f1f3-06e2-9635-960d-e2f7f75b2040@redhat.com \
--to=thuth@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=f4bug@amsat.org \
--cc=magnus.damm@gmail.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=rth@twiddle.net \
--cc=ysato@users.sourceforge.jp \
/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).