Received: by 2002:a17:907:8744:b0:9bd:85f7:2662 with SMTP id qo4csp3741712ejc; Tue, 17 Oct 2023 00:49:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtdDCMddqGrKs7yivLKrGlsHw0tp3fMwtWzbdffZOKU+Nxn7PRTfKvYT3AHZO8DSPF7Tso X-Received: by 2002:a05:622a:1182:b0:417:d1e7:5e9b with SMTP id m2-20020a05622a118200b00417d1e75e9bmr1937740qtk.26.1697528946636; Tue, 17 Oct 2023 00:49:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697528946; cv=none; d=google.com; s=arc-20160816; b=Wo3h2RAqXayqVsmyFj3ancyhV1DtHEDu6+yRMc+VbzLIVGFRnuWYAENq+AIxN8nAJr VrmaGZ0Xn/xEVWP42ZY0XvLohUKMuqWw43zj3SP6XNcKEUsMUKFB3kUgdK3jxytnGQfG wwcLf3cq3T+x6W9nQ0Vnd3KCWY43K4W3vKgPCLne6/+Hb0oStF1cDcKxWFQ6ClCJ//6T +mBJVwADON0RmPaNA4+qSnHl+ROTt0XcGVpo2dUQORKK5+Cr3rJsvHq588qB87EGFw9z djfNMpfKBRvwUdNm9rFupM6uSlABNolsKnyY3zz3+BOMNfBQNNBQMygT/klTLSRxR+8T kNPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=FsWGjoiQz9o9+jcC4jZM0jnofWMwl8FabZlxz/AdIkM=; fh=FQudIxJAVafJ8SIPt9dDDiSBF16B9Tf7tHRFaMXBmqU=; b=jSMFRfTZQZ1GxdlvxgvW8frRtYGPcFjMDhiGiXReBRQ1uDvoYn6hWEWOtPwfVuRBrW eBCbZuaz/nzcDnQDjnrde+YdXcQiC3D51OCofd0Dk10vAerAuHM4Nqjx9R9PpNsYOW+t LcDKg1Ae+ddwDn8Y6TO9KXDOuoJaIe3RoRu4MUZ14CsSoCg60Augfl9OWkPiwrSswgnm KQySlXZx03xKi8JiDlRb8sq9wOpK7mDwuPVX17Z1ORpNG8sPWVXQvuuTCR0qxT4Lt6pj ZivOtn1YH+8UHkZWzr5ru7aQ7nkU8/aQYHthlKesTJ2kXkhDgYf8wyqf98K44WTEjAeg nEYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c13-20020a05622a058d00b004194d25f6a0si731000qtb.249.2023.10.17.00.49.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Oct 2023 00:49:06 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qseoz-00056y-M2; Tue, 17 Oct 2023 03:48:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qseou-00053r-6v; Tue, 17 Oct 2023 03:48:53 -0400 Received: from exchange.fintech.ru ([195.54.195.159]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1qseor-0005wZ-6k; Tue, 17 Oct 2023 03:48:51 -0400 Received: from Ex16-02.fintech.ru (10.0.10.19) by exchange.fintech.ru (195.54.195.159) with Microsoft SMTP Server (TLS) id 14.3.498.0; Tue, 17 Oct 2023 10:48:30 +0300 Received: from Ex16-02.fintech.ru (10.0.10.19) by Ex16-02.fintech.ru (10.0.10.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Tue, 17 Oct 2023 10:48:30 +0300 Received: from Ex16-02.fintech.ru ([fe80::18b6:cd4a:a259:613c]) by Ex16-02.fintech.ru ([fe80::18b6:cd4a:a259:613c%3]) with mapi id 15.01.2242.004; Tue, 17 Oct 2023 10:48:30 +0300 From: =?koi8-r?B?7cnSz87P1yDzxdLHxcog98zBxMnNydLP18ne?= To: Peter Maydell CC: "qemu-devel@nongnu.org" , "qemu-arm@nongnu.org" Subject: Re: [PATCH 1/1] target/arm: Adding a check for the result of calling the CPU information check function Thread-Topic: [PATCH 1/1] target/arm: Adding a check for the result of calling the CPU information check function Thread-Index: AQHZ/Oockw9FDKXV3E6X4qPU6uyPIrBMbjAAgAExPY8= Date: Tue, 17 Oct 2023 07:48:29 +0000 Message-ID: <9683808b184c4ab3b273ebffe6d66c6a@fintech.ru> References: <20231012085710.880440-1-mironov@fintech.ru>, In-Reply-To: Accept-Language: ru-RU, en-US Content-Language: ru-RU X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.0.1.141] Content-Type: multipart/alternative; boundary="_000_9683808b184c4ab3b273ebffe6d66c6afintechru_" MIME-Version: 1.0 Received-SPF: pass client-ip=195.54.195.159; envelope-from=mironov@fintech.ru; helo=exchange.fintech.ru X-Spam_score_int: 38 X-Spam_score: 3.8 X-Spam_bar: +++ X-Spam_report: (3.8 / 5.0 requ) BAYES_00=-1.9, CHARSET_FARAWAY_HEADER=3.2, HTML_MESSAGE=0.001, MIME_CHARSET_FARAWAY=2.45, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: 22KQ96EBR+Hk --_000_9683808b184c4ab3b273ebffe6d66c6afintechru_ Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable Yes, the warning was initially received in the static analyzer SVACE, the same type as Coverity. In this case, return value of a function 'get_arm_cp_reginfo' is referenced at helper.c without checking for ALL, but it is usually checked for this fu= nction (8/9). ________________________________ =EF=D4: Peter Maydell =EF=D4=D0=D2=C1=D7=CC=C5=CE=CF: 16 =CF=CB=D4=D1=C2=D2=D1 2023 =C7. 19:23 =EB=CF=CD=D5: =ED=C9=D2=CF=CE=CF=D7 =F3=C5=D2=C7=C5=CA =F7=CC=C1=C4=C9=CD= =C9=D2=CF=D7=C9=DE =EB=CF=D0=C9=D1: qemu-devel@nongnu.org; qemu-arm@nongnu.org =F4=C5=CD=C1: Re: [PATCH 1/1] target/arm: Adding a check for the result of = calling the CPU information check function On Thu, 12 Oct 2023 at 09:57, Sergey Mironov wrote: > > 6 out of 7 calls to get_arm_cp_reginfo() are checked This sounds like it's talking about a Coverity warning, though it doesn't say so. Is that the motivation here ? If so, it would be good to say so in the commit message. If not, the commit message should explain why we're making the change. That particular Coverity warning is quite prone to false positives, since it's only a heuristic. Sometimes it's useful to add an assert(), if it helps both Coverity and human readers, but not always. assert()s are also most useful if there's a comment that explains why we can assume the thing they're assuming, as Alex suggests. > Signed-off-by: Sergey Mironov > --- > target/arm/helper.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/target/arm/helper.c b/target/arm/helper.c > index 74fbb6e1d7..cffbbaf571 100644 > --- a/target/arm/helper.c > +++ b/target/arm/helper.c > @@ -198,6 +198,7 @@ static void add_cpreg_to_list(gpointer key, gpointer = opaque) > uint32_t regidx =3D (uintptr_t)key; > const ARMCPRegInfo *ri =3D get_arm_cp_reginfo(cpu->cp_regs, regidx); > > + assert(ri !=3D NULL); > if (!(ri->type & (ARM_CP_NO_RAW | ARM_CP_ALIAS))) { > cpu->cpreg_indexes[cpu->cpreg_array_len] =3D cpreg_to_kvm_id(reg= idx); > /* The value array need not be initialized at this point */ > -- > 2.31.1 thanks -- PMM --_000_9683808b184c4ab3b273ebffe6d66c6afintechru_ Content-Type: text/html; charset="koi8-r" Content-Transfer-Encoding: quoted-printable

Yes, the warning was initially received in the static analyzer SVA= CE, 

the same type as Coverity.


In this case, return value of a function 'get_arm_cp_reginfo' is refe= renced 
at helper.c without checking for ALL, but it is usually checked for t= his function (8/9).


=EF=D4: Peter Maydell <= ;peter.maydell@linaro.org>
=EF=D4=D0=D2=C1=D7=CC=C5=CE=CF: 16 =CF=CB=D4=D1=C2=D2=D1 2023 =C7. 1= 9:23
=EB=CF=CD=D5: =ED=C9=D2=CF=CE=CF=D7 =F3=C5=D2=C7=C5=CA =F7=CC=C1=C4= =C9=CD=C9=D2=CF=D7=C9=DE
=EB=CF=D0=C9=D1: qemu-devel@nongnu.org; qemu-arm@nongnu.org
=F4=C5=CD=C1: Re: [PATCH 1/1] target/arm: Adding a check for the res= ult of calling the CPU information check function
 
On Thu, 12 Oct 2023 at 09:57, Sergey Mironov <m= ironov@fintech.ru> wrote:
>
> 6 out of 7 calls to get_arm_cp_reginfo() are checked

This sounds like it's talking about a Coverity warning, though
it doesn't say so. Is that the motivation here ? If so,
it would be good to say so in the commit message. If not,
the commit message should explain why we're making the change.

That particular Coverity warning is quite prone to false
positives, since it's only a heuristic. Sometimes it's
useful to add an assert(), if it helps both Coverity and
human readers, but not always.

assert()s are also most useful if there's a comment that explains
why we can assume the thing they're assuming, as Alex suggests.

> Signed-off-by: Sergey Mironov <mironov@fintech.ru>
> ---
>  target/arm/helper.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/target/arm/helper.c b/target/arm/helper.c
> index 74fbb6e1d7..cffbbaf571 100644
> --- a/target/arm/helper.c
> +++ b/target/arm/helper.c
> @@ -198,6 +198,7 @@ static void add_cpreg_to_list(gpointer key, gp= ointer opaque)
>      uint32_t regidx =3D (uintptr_t)key;
>      const ARMCPRegInfo *ri =3D get_arm_cp_re= ginfo(cpu->cp_regs, regidx);
>
> +    assert(ri !=3D NULL);

>      if (!(ri->type & (ARM_CP_NO_RAW |= ARM_CP_ALIAS))) {
>          cpu->cpreg_in= dexes[cpu->cpreg_array_len] =3D cpreg_to_kvm_id(regidx);
>          /* The value arr= ay need not be initialized at this point */
> --
> 2.31.1

thanks
-- PMM
--_000_9683808b184c4ab3b273ebffe6d66c6afintechru_--