From patchwork Fri Oct 19 10:50:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10648973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E06FD15E2 for ; Fri, 19 Oct 2018 10:52:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAB1228A3F for ; Fri, 19 Oct 2018 10:52:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B897E28A7E; Fri, 19 Oct 2018 10:52:05 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 565CB28A3F for ; Fri, 19 Oct 2018 10:52:05 +0000 (UTC) Received: from localhost ([::1]:48526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDSNw-0006sA-DK for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Oct 2018 06:52:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDSMq-0006GE-KQ for qemu-devel@nongnu.org; Fri, 19 Oct 2018 06:50:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDSMn-0001T7-CU for qemu-devel@nongnu.org; Fri, 19 Oct 2018 06:50:56 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:38344) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDSMn-0001Mh-1K for qemu-devel@nongnu.org; Fri, 19 Oct 2018 06:50:53 -0400 Received: by mail-pl1-x641.google.com with SMTP id q19-v6so12641501pll.5 for ; Fri, 19 Oct 2018 03:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TIGzoKqij/nRCgv4gNsQniF5Gw2tSa9hzvJ9fVS8nXU=; b=JH7s4VZCpLJXeYdfWuTmMTjmFIYNp8oCBSAQ0sNXRYjQc6T9X3PAxZOKTIJpPJh2D7 qAHBIgUNUpCQFBXW6RVZDRKqhEFcr5XbkwfjZz3+MPlsm9gA9OHOPF5NvP8yJ+8pJVqz 1F09c5r8c9LPgVOW6yEk8Jcuy+tPo1TOnkg0zz0SCZTJIx+2ABjYainMXLX+Jq3O3N2b jxH5m90NH6CfqNXwCRVoJtGAPlkoqVCVBtiS9DmW3fnL8mGbPAlS0ljEnpz2RrBlJm2A 15t5QbkVSRektnJYYttRiynxoKcKdmIQsBwqAb3LklZZTtbd3y30ZH0Y6w3+vvt3CS6b KHPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TIGzoKqij/nRCgv4gNsQniF5Gw2tSa9hzvJ9fVS8nXU=; b=Mzs/aUuOVKEtJ1emUu7NYeePU8JnlMtBE8a3GaP68JwBO7fgjDf93aM1GuNRRsAtia CEJtVr19ART/MIJxoyp0A1Sftz12ot46MwxDl5Q54/msdNIzp9l1LQ5H2NggUQ1tV1i1 b4ODdG0S8ebnG6x3hJbmLm+O/64wXHQGvF6KZzlv4PLFD8mubpRvS5PErrWixLhn4rqA Ef25mVlftJWyQ15Fh/dDDLKyU59sphkwIk45DB0iGuTtQgPHzjLodQtNiOmJf7qO4Vjz 6MrFyFFcPU5JoS8yU5jFZS3L5racAmz5Sy4B4zQdBfmtI6U90pDEK9DyehhL8CCeGSKe ZbNg== X-Gm-Message-State: ABuFfoiDaXcAzubaSNEwu6uuA8BbFTBVR2hiu1AfBD0aQ5/+c6YRVvh8 xnHEQJHgqfllDK85zN2vPirRWzAq X-Google-Smtp-Source: ACcGV629je7sbC6nJXuvFAKy8bVDFO/A9Qz+2+8I1w/TNdDpiQCtoLcJdN+9OOEGuJBV2LX9gUnT3w== X-Received: by 2002:a17:902:7109:: with SMTP id a9-v6mr33523731pll.310.1539946245629; Fri, 19 Oct 2018 03:50:45 -0700 (PDT) Received: from localhost.localdomain.localdomain ([103.65.40.65]) by smtp.gmail.com with ESMTPSA id t64-v6sm42884856pfb.44.2018.10.19.03.50.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 03:50:45 -0700 (PDT) From: Li Qiang To: kraxel@redhat.com Date: Fri, 19 Oct 2018 03:50:36 -0700 Message-Id: <1539946236-18028-3-git-send-email-liq3ea@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539946236-18028-1-git-send-email-liq3ea@gmail.com> References: <1539946236-18028-1-git-send-email-liq3ea@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [PATCH 2/2] hw: ccid-card-emulated: cleanup resource when realize in error path 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: Li Qiang , liq3ea@163.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Li Qiang --- hw/usb/ccid-card-emulated.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c index b356edb..25976ed 100644 --- a/hw/usb/ccid-card-emulated.c +++ b/hw/usb/ccid-card-emulated.c @@ -499,7 +499,7 @@ static void emulated_realize(CCIDCardState *base, Error **errp) card->reader = NULL; card->quit_apdu_thread = 0; if (init_event_notifier(card, errp) < 0) { - return; + goto out1; } card->backend = 0; @@ -513,7 +513,7 @@ static void emulated_realize(CCIDCardState *base, Error **errp) for (ptable = backend_enum_table; ptable->name != NULL; ++ptable) { error_append_hint(errp, "%s\n", ptable->name); } - return; + goto out2; } /* TODO: a passthru backened that works on local machine. third card type?*/ @@ -523,31 +523,39 @@ static void emulated_realize(CCIDCardState *base, Error **errp) } else { error_setg(errp, "%s: you must provide all three certs for" " certificates backend", TYPE_EMULATED_CCID); - return; + goto out2; } } else { if (card->backend != BACKEND_NSS_EMULATED) { error_setg(errp, "%s: bad backend specified. The options are:%s" " (default), %s.", TYPE_EMULATED_CCID, BACKEND_NSS_EMULATED_NAME, BACKEND_CERTIFICATES_NAME); - return; + goto out2; } if (card->cert1 != NULL || card->cert2 != NULL || card->cert3 != NULL) { error_setg(errp, "%s: unexpected cert parameters to nss emulated " "backend", TYPE_EMULATED_CCID); - return; + goto out2; } /* default to mirroring the local hardware readers */ ret = wrap_vcard_emul_init(NULL); } if (ret != VCARD_EMUL_OK) { error_setg(errp, "%s: failed to initialize vcard", TYPE_EMULATED_CCID); - return; + goto out2; } qemu_thread_create(&card->event_thread_id, "ccid/event", event_thread, card, QEMU_THREAD_JOINABLE); qemu_thread_create(&card->apdu_thread_id, "ccid/apdu", handle_apdu_thread, card, QEMU_THREAD_JOINABLE); + +out2: + clean_event_notifier(card); +out1: + qemu_cond_destroy(&card->handle_apdu_cond); + qemu_mutex_destroy(&card->handle_apdu_mutex); + qemu_mutex_destroy(&card->vreader_mutex); + qemu_mutex_destroy(&card->event_list_mutex); } static void emulated_unrealize(CCIDCardState *base, Error **errp)