From patchwork Fri Mar 31 13:10:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amarnath Valluri X-Patchwork-Id: 9656559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8B23B60349 for ; Fri, 31 Mar 2017 15:01:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DDED275A2 for ; Fri, 31 Mar 2017 15:01:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72AE12856E; Fri, 31 Mar 2017 15:01:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 453AF284D1 for ; Fri, 31 Mar 2017 15:01:16 +0000 (UTC) Received: from localhost ([::1]:41460 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cty39-0006lF-CZ for patchwork-qemu-devel@patchwork.kernel.org; Fri, 31 Mar 2017 11:01:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctwJq-0003kp-OZ for qemu-devel@nongnu.org; Fri, 31 Mar 2017 09:10:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ctwJm-0000Vs-7Q for qemu-devel@nongnu.org; Fri, 31 Mar 2017 09:10:22 -0400 Received: from mga09.intel.com ([134.134.136.24]:48955) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ctwJl-0000UK-Te for qemu-devel@nongnu.org; Fri, 31 Mar 2017 09:10:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490965817; x=1522501817; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=MTxtwu2Kg2Hh73n8q6u+MxXDCmLKukJh2+l61SFzOpU=; b=K92HqtG2AesFdMzHNGBGPZjnyoPnvgqybPlR0NG+T72i4+YM0U/HjWgF a9IytS1etsKsQaBuNEoU7hlDb6Mm4Q==; Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Mar 2017 06:10:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.36,251,1486454400"; d="scan'208"; a="1129316591" Received: from avallurigigabyte.fi.intel.com ([10.237.72.170]) by fmsmga001.fm.intel.com with ESMTP; 31 Mar 2017 06:10:15 -0700 From: Amarnath Valluri To: qemu-devel@nongnu.org Date: Fri, 31 Mar 2017 16:10:12 +0300 Message-Id: <1490965817-16913-4-git-send-email-amarnath.valluri@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490965817-16913-1-git-send-email-amarnath.valluri@intel.com> References: <1490965817-16913-1-git-send-email-amarnath.valluri@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.24 X-Mailman-Approved-At: Fri, 31 Mar 2017 10:56:08 -0400 Subject: [Qemu-devel] [PATCH 3/7] tpm-backend: Initialize and free data members in it's own methods X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amarnath Valluri , patrick.ohly@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Initialize and free TPMBackend data members in it's own instance_init() and instance_finalize methods. Took the opportunity to fix object cleanup in tpm_backend_destroy() method Signed-off-by: Amarnath Valluri --- backends/tpm.c | 14 +++++++++++++- hw/tpm/tpm_passthrough.c | 8 +------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/backends/tpm.c b/backends/tpm.c index 50a7809..00c82d7 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -59,7 +59,7 @@ void tpm_backend_destroy(TPMBackend *s) k->ops->destroy(s); - tpm_backend_thread_end(s); + object_unref(OBJECT(s)); } int tpm_backend_init(TPMBackend *s, TPMState *state, @@ -187,10 +187,20 @@ static void tpm_backend_prop_set_opened(Object *obj, bool value, Error **errp) static void tpm_backend_instance_init(Object *obj) { + TPMBackend *s = TPM_BACKEND(obj); + object_property_add_bool(obj, "opened", tpm_backend_prop_get_opened, tpm_backend_prop_set_opened, NULL); + s->id = NULL; + s->fe_model = -1; + s->opened = false; + s->tpm_state = NULL; + s->thread_pool = NULL; + s->recv_data_callback = NULL; + s->path = NULL; + s->cancel_path = NULL; } @@ -199,6 +209,8 @@ static void tpm_backend_instance_finalize(Object *obj) TPMBackend *s = TPM_BACKEND(obj); g_free(s->id); + g_free(s->path); + g_free(s->cancel_path); tpm_backend_thread_end(s); } diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 606e064..cb63079 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -418,8 +418,6 @@ static TPMBackend *tpm_passthrough_create(QemuOpts *opts, const char *id) TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); tb->id = g_strdup(id); - /* let frontend set the fe_model to proper value */ - tb->fe_model = -1; if (tpm_passthrough_handle_device_opts(opts, tb)) { goto err_exit; @@ -433,7 +431,7 @@ static TPMBackend *tpm_passthrough_create(QemuOpts *opts, const char *id) return tb; err_exit: - g_free(tb->id); + object_unref(obj); return NULL; } @@ -446,10 +444,6 @@ static void tpm_passthrough_destroy(TPMBackend *tb) qemu_close(tpm_pt->tpm_fd); qemu_close(tpm_pt->cancel_fd); - - g_free(tb->id); - g_free(tb->path); - g_free(tb->cancel_path); g_free(tpm_pt->tpm_dev); }