From nobody Sun Feb 8 05:07:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1637768695; cv=none; d=zohomail.com; s=zohoarc; b=JwLqpUKYroWHmYGkxWbTRTGXWX82qt82hQTf6yMOXhgTO/8LjutleooC2oJM2+hEYQIRRgzFqdYTxa5xirA4c4NcmBejz6gJjcmYm9mkvO1kH3k3DXjh0OpRuczS5qIKYdA022SQDbryvelCK0Gu3suFiO6tkIh1ip3D0dZiOC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637768695; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Us2cR0riIBn9nv1MrpOwKDupdQu+s3VT6dsVqPudIos=; b=kenZ9XgMEo7rBy2iXfofC+d8lDpnzNrohPC+FvKIGAiW7xh8hIyFmzVlg/i5yMnrIwqVLjGctiZ0W1FDdNxCV3aff1F8Hw4hF73lcA1a0T+fx3Gi88dtohL42DmmOu526bkEhoTzhlov/cX3fw3EkzE4qnrYBQPjl5wENAt0QUw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1637768695685339.68878662565373; Wed, 24 Nov 2021 07:44:55 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-272-lg1NPKu-OdGqdC8LNjexNg-1; Wed, 24 Nov 2021 10:44:52 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CFD3110144F6; Wed, 24 Nov 2021 15:44:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B207A5D9C0; Wed, 24 Nov 2021 15:44:45 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 84F4D1809CB8; Wed, 24 Nov 2021 15:44:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1AOFiT5S027891 for ; Wed, 24 Nov 2021 10:44:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id D393F79455; Wed, 24 Nov 2021 15:44:29 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4097B79458; Wed, 24 Nov 2021 15:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637768694; h=from:from:sender:sender: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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Us2cR0riIBn9nv1MrpOwKDupdQu+s3VT6dsVqPudIos=; b=XAQhGvasJqa/3rIbNQjrTfXjqfUagYEuOiHIZM2V9kdfwK1YgC/gIl309i/UAiZZvAo5qK CYkjR40bNGQYcUswlmbL53YDUQ3D24YtkwEJB5TxSc58UMUPPUXsD8CzsCb+87/eW3qEQX /sJFQXXsW64tOddt5VuKsZLyGVwzCtY= X-MC-Unique: lg1NPKu-OdGqdC8LNjexNg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 03/12] util: refactor TPM helper methods to reduce duplicationm Date: Wed, 24 Nov 2021 15:44:07 +0000 Message-Id: <20211124154416.369770-4-berrange@redhat.com> In-Reply-To: <20211124154416.369770-1-berrange@redhat.com> References: <20211124154416.369770-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637768696828100001 The TPM helper methods for querying the binary path and capabilities have the same patterns across all swtpm binaries. This code duplication can be reduced by introducing helper methods. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/util/virtpm.c | 53 ++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/src/util/virtpm.c b/src/util/virtpm.c index 1a34f8ce56..cc9173cecd 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -109,49 +109,37 @@ static struct stat swtpm_ioctl_stat; =20 typedef int (*virTPMBinaryCapsParse)(const char *); =20 -char * -virTPMGetSwtpm(void) +static char * +virTPMBinaryGetPath(char **path_var) { char *s; =20 - if (!swtpm_path && virTPMEmulatorInit() < 0) + if (!*path_var && virTPMEmulatorInit() < 0) return NULL; =20 virMutexLock(&swtpm_tools_lock); - s =3D g_strdup(swtpm_path); + s =3D g_strdup(*path_var); virMutexUnlock(&swtpm_tools_lock); =20 return s; } =20 char * -virTPMGetSwtpmSetup(void) +virTPMGetSwtpm(void) { - char *s; - - if (!swtpm_setup_path && virTPMEmulatorInit() < 0) - return NULL; - - virMutexLock(&swtpm_tools_lock); - s =3D g_strdup(swtpm_setup_path); - virMutexUnlock(&swtpm_tools_lock); + return virTPMBinaryGetPath(&swtpm_path); +} =20 - return s; +char * +virTPMGetSwtpmSetup(void) +{ + return virTPMBinaryGetPath(&swtpm_setup_path); } =20 char * virTPMGetSwtpmIoctl(void) { - char *s; - - if (!swtpm_ioctl_path && virTPMEmulatorInit() < 0) - return NULL; - - virMutexLock(&swtpm_tools_lock); - s =3D g_strdup(swtpm_ioctl_path); - virMutexUnlock(&swtpm_tools_lock); - - return s; + return virTPMBinaryGetPath(&swtpm_ioctl_path); } =20 /* virTPMExecGetCaps @@ -345,18 +333,23 @@ virTPMEmulatorInit(void) return ret; } =20 -bool -virTPMSwtpmCapsGet(unsigned int cap) +static bool +virTPMBinaryGetCaps(virBitmap **caps_var, + unsigned int cap) { if (virTPMEmulatorInit() < 0) return false; - return virBitmapIsBitSet(swtpm_caps, cap); + return virBitmapIsBitSet(*caps_var, cap); +} + +bool +virTPMSwtpmCapsGet(unsigned int cap) +{ + return virTPMBinaryGetCaps(&swtpm_caps, cap); } =20 bool virTPMSwtpmSetupCapsGet(unsigned int cap) { - if (virTPMEmulatorInit() < 0) - return false; - return virBitmapIsBitSet(swtpm_setup_caps, cap); + return virTPMBinaryGetCaps(&swtpm_setup_caps, cap); } --=20 2.33.1