Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q683v-0002n4-Lq for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jun 2023 11:07:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q682v-0006m6-9w for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jun 2023 11:06:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q682u-0006lw-OH for pgsql-hackers@lists.postgresql.org; Mon, 05 Jun 2023 11:06:44 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1q682p-000KS7-Sg for pgsql-hackers@postgresql.org; Mon, 05 Jun 2023 11:06:43 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-514924b4f8cso7236047a12.3 for ; Mon, 05 Jun 2023 04:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685963198; x=1688555198; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=wCAmQZFj8F6h5+ysAaYS5W8Mg9FO9TBJFXVrMkWHeUw=; b=JkUmMDUzuCuccggUhFepquk4vMmyuooz9uW/vlRj4pzyguoCqBiATn6Qqk3n95Awi2 K/Odbu89wieB10ngth6JS8AXghUoqRTh+7hjs8/YfgRhZTFvprLZNaM3vq/A/IhpNJ+T Wv3chrwq4vjBhiJF3vu+RjFsL3iOZ1wcC6eUUd4z+5qGZcxGRAHHrff9PxyBzMJftMVw 4wSyN8nCUacTY81DeHy+6qPqL2n1IDF8mRnoHIeb4qkYQXpKX6AiXq6ZILZZCgBz/hQc mL57XIjnQ31YLTiUO8X8nMy+jeFjBTLs6/YYLXYZT84RQJAySMjsN+ek8ZSXL3yJPwEM kkwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685963198; x=1688555198; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wCAmQZFj8F6h5+ysAaYS5W8Mg9FO9TBJFXVrMkWHeUw=; b=J6HRqGO25NPsnMvdWihtWKGGAPoxMloemx0RVq9Snwlu8RRAUa9ittg19bO1/b9xLm lXD6p4VbMdBPiz3BPdDXkpf2uoTFt2Ra3D3rQWf8DrpacI5GEx3UPD1x3D1uaCILztU7 Xhb+a2wkh7YWHOD9hOPgj/t8Adba/7uDHOtaVdcziFhSL7uIK0pS8ieQTNEj02XaEFTZ 33LgZxo8IFRlNutkJcmj3G8U0lMzAgOtOKct3HELOljD2J72Vvd87Vf0Ic1AJ8u57uV1 mQBG2LFcEqrWC+qZiAVUZcvlOZ7hNJ4QV9AHU8D1sce2ro+ttHIe7gPxD62OCyIC3ezM LDPg== X-Gm-Message-State: AC+VfDwynpM+RSYEFDe2f+f2F4MSDHTXN2T+Dl/TdMtGaDBmrpDauH2P cW6i1ZZM2MKOodKg1Sh0hZHZg/LHUuulR1nFwzE= X-Google-Smtp-Source: ACHHUZ5biOcrQGYfTd9xkjlasNapUAgE+4hb8AXQXggQOC41oIRMffENPitIwm9obeTdELVYdVam/HqyZ+ZkEPueAs0= X-Received: by 2002:aa7:c1c9:0:b0:514:ae18:162e with SMTP id d9-20020aa7c1c9000000b00514ae18162emr6310604edp.35.1685963197944; Mon, 05 Jun 2023 04:06:37 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ranier Vilela Date: Mon, 5 Jun 2023 08:06:26 -0300 Message-ID: Subject: Re: Avoid unncessary always true test (src/backend/storage/buffer/bufmgr.c) To: Richard Guo Cc: Pg Hackers Content-Type: multipart/alternative; boundary="00000000000084a78a05fd5fe5e5" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000084a78a05fd5fe5e5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Em dom., 4 de jun. de 2023 =C3=A0s 23:37, Richard Guo escreveu: > > On Sun, Jun 4, 2023 at 8:42=E2=80=AFPM Ranier Vilela wrote: > >> Hi, >> >> Per Coverity. >> >> At function ExtendBufferedRelShared, has a always true test. >> eb.rel was dereferenced one line above, so in >> if (eb.rel) is always true. >> >> I think it's worth removing the test, because Coverity raises dozens of >> alerts thinking eb.rel might be NULL. >> Besides, one less test is one less branch. >> > > This also happens in ExtendBufferedRelTo, and the comment there explains > that the eb.rel 'could have been closed while waiting for lock'. > Well, RelationGetSmgr also dereferences eb.rel. If eb.rel could be closed while waiting for lock, anyone who references eb.rel below takes a risk? static inline SMgrRelation RelationGetSmgr(Relation rel) { if (unlikely(rel->rd_smgr =3D=3D NULL)) smgrsetowner(&(rel->rd_smgr), smgropen(rel->rd_locator, rel->rd_backend)); return rel->rd_smgr; } regards, Ranier Vilela --00000000000084a78a05fd5fe5e5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Em dom., 4 de jun. de 2023 =C3=A0s 23:37, Richard Guo <guofenglinux@gmail.com> escreveu:
<= div dir=3D"ltr">
On Sun, Jun 4, 2023 at 8:42=E2=80=AFPM Ranier Vilela <ranier.vf@gmail.com<= /a>> wrote:
<= div dir=3D"ltr">
Hi,

Per Coverity.
<= br>
At function ExtendBufferedRelShared, has a always true test.<= /div>
eb.rel was dereferenced one line above, so in
if (= eb.rel) is always true.

I think it's worth rem= oving the test, because Coverity raises dozens of alerts thinking eb.rel mi= ght be NULL.
Besides, one less test is one less branch.

This also happens in ExtendBufferedRelTo= , and the comment there explains
that the eb.rel 'could have been cl= osed while waiting for lock'.
Well, = RelationGetSmgr also dereferences eb.rel.
If eb.rel could be clos= ed while waiting for lock,
anyone who references eb.rel below tak= es a risk?
=C2=A0
static inline SMgrRelation
Rel= ationGetSmgr(Relation rel)
{
if (unlikely(rel->rd_smgr =3D=3D NUL= L))
smgrsetowner(&(rel->rd_smgr), smgropen(rel->rd_locator, = rel->rd_backend));
return rel->rd_smgr;
}

regards,
Ranier Vilela
--00000000000084a78a05fd5fe5e5--