From nobody Wed Mar 12 12:58:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1741690158158120.45388664025529; Tue, 11 Mar 2025 03:49:18 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1162E1C05; Tue, 11 Mar 2025 06:49:17 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B76B61BE1; Tue, 11 Mar 2025 06:48:56 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A264A1B9D; Tue, 11 Mar 2025 06:48:53 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0BE501BAA for ; Tue, 11 Mar 2025 06:48:53 -0400 (EDT) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-y8usETRxMcKcqdfBcyS-6Q-1; Tue, 11 Mar 2025 06:48:51 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 72DCC19560B7 for ; Tue, 11 Mar 2025 10:48:50 +0000 (UTC) Received: from orkuz (unknown [10.43.3.115]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 035F23001D0E for ; Tue, 11 Mar 2025 10:48:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741690132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=T2kw5lsJIH2Efz1BtuO9/AG+Sdu1sT7x0aNOeYAhdpo=; b=AZumd4ZE9C0RuvjdnpYeZZ/vqN+/f4ZDRLiIidzhxtwRrkUzSANFEmM8GukiNuqmMocbYS OMdnEQitX9dD2+lQwmb+M7eBBY7iSTS8qlN1OEabczgtYuGSc/xrAKJM9v2r1ho62fFdj9 2Qch6y0QDAfWh6L3lfMINX5PenR0SD0= X-MC-Unique: y8usETRxMcKcqdfBcyS-6Q-1 X-Mimecast-MFC-AGG-ID: y8usETRxMcKcqdfBcyS-6Q_1741690130 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH] esx: Refactor esxVI_LookupHostScsiTopologyLunListByTargetName Date: Tue, 11 Mar 2025 11:48:41 +0100 Message-ID: <6a6382363cd2f411fdba0ed7e6c383839e5ef384.1741690121.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: qNkE874-906WEAyM2bc4qzTzC-w30QSMJvt1ytbf1Fg_1741690130 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3UZPLFSSVJYUW5PAKYNN3YLC7RNVNJNK X-Message-ID-Hash: 3UZPLFSSVJYUW5PAKYNN3YLC7RNVNJNK X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1741690161521019100 Content-Type: text/plain; charset="utf-8" With a specific combination of compiler options gcc reported the following bogus warning (I added a context to it to make the issue visible): ../src/esx/esx_vi.c: In function =E2=80=98esxVI_LookupHostScsiTopologyLunLi= stByTargetName=E2=80=99: ../src/esx/esx_vi.c:4674:32: error: potential null pointer dereference [-We= rror=3Dnull-dereference] 4671 | if (!found || !hostScsiTopologyTarget) 4672 | goto cleanup; 4673 | 4674 | if (!hostScsiTopologyTarget->lun) { | ~~~~~~~~~~~~~~~~~~~~~~^~~~~ Most likely this is caused by found and hostScsiTopologyTarget doing essentially the same thing as found is true if and only if hostScsiTopologyTarget is non-NULL. The found variable is completely redundant. Removing it would be enough, but I decided to make the code a little bit easier to read by not using the iterator variable directly. Signed-off-by: Jiri Denemark Reviewed-by: Peter Krempa --- src/esx/esx_vi.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index e2589aa69a..aee649b86e 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -4616,7 +4616,6 @@ esxVI_LookupHostScsiTopologyLunListByTargetName esxVI_HostScsiTopologyInterface *hostScsiInterfaceList =3D NULL; esxVI_HostScsiTopologyInterface *hostScsiInterface =3D NULL; esxVI_HostScsiTopologyTarget *hostScsiTopologyTarget =3D NULL; - bool found =3D false; esxVI_HostInternetScsiTargetTransport *candidate =3D NULL; =20 ESX_VI_CHECK_ARG_LIST(hostScsiTopologyLunList); @@ -4653,22 +4652,21 @@ esxVI_LookupHostScsiTopologyLunListByTargetName =20 /* See vSphere API documentation about HostScsiTopologyInterface */ for (hostScsiInterface =3D hostScsiInterfaceList; - hostScsiInterface && !found; + hostScsiInterface && !hostScsiTopologyTarget; hostScsiInterface =3D hostScsiInterface->_next) { - for (hostScsiTopologyTarget =3D hostScsiInterface->target; - hostScsiTopologyTarget; - hostScsiTopologyTarget =3D hostScsiTopologyTarget->_next) { + esxVI_HostScsiTopologyTarget *target; + for (target =3D hostScsiInterface->target; target; target =3D targ= et->_next) { candidate =3D esxVI_HostInternetScsiTargetTransport_DynamicCast - (hostScsiTopologyTarget->transport); + (target->transport); =20 if (candidate && STREQ(candidate->iScsiName, name)) { - found =3D true; + hostScsiTopologyTarget =3D target; break; } } } =20 - if (!found || !hostScsiTopologyTarget) + if (!hostScsiTopologyTarget) goto cleanup; =20 if (!hostScsiTopologyTarget->lun) { --=20 2.48.1