From patchwork Wed Jan 16 15:15:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yuval Shaia X-Patchwork-Id: 10766249 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 E0C9B1390 for ; Wed, 16 Jan 2019 15:16:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE2BE2EBDD for ; Wed, 16 Jan 2019 15:16:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFE5B2EBE6; Wed, 16 Jan 2019 15:16:58 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 68D902EBDD for ; Wed, 16 Jan 2019 15:16:58 +0000 (UTC) Received: from localhost ([127.0.0.1]:49667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjmw5-0003Qy-HF for patchwork-qemu-devel@patchwork.kernel.org; Wed, 16 Jan 2019 10:16:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjmvD-00037X-FT for qemu-devel@nongnu.org; Wed, 16 Jan 2019 10:16:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjmvB-0004KT-L9 for qemu-devel@nongnu.org; Wed, 16 Jan 2019 10:16:03 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:33048) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjmvB-0004Gx-D9 for qemu-devel@nongnu.org; Wed, 16 Jan 2019 10:16:01 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0GFCnXn043100; Wed, 16 Jan 2019 15:15:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=CowujjTf2uKhd+GU/PTPzSCuDr7RQRhQOMGMX0x0XxE=; b=n916JruBrivzxPOuHj9qtyGF63nDDyo7HjETBBdIJnucLXgQNDQLjc1zzVrNOjQiSiT9 Gli9C0g+PWtpDZMHDj8CC5zqKV4IbjxvazYCEnlfoDb8dCm7fCOAhBsBa6WJeGwWeBoL Wei4wjoGTQk60QgTb+f9BpMG3r+qM0u824rfCNTf4fmBtJkbhvEbsmhp5ieS8Lj09dfp UMfWRuCdRxIF+htbzpRAGicJjU+hiQZ4jo8IAEoUWWwtYFZWrg7LL0FkvFJTyLPQJ6i0 FXpyman5OtXbRev68IcbUrwhfVmNSCag/9KYmzVrDj7+ZQqLsrijGlXS8EOsOSIlJ83b 4g== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2pybjntfqm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Jan 2019 15:15:58 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x0GFFvcK007033 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Jan 2019 15:15:58 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x0GFFvjl024610; Wed, 16 Jan 2019 15:15:57 GMT Received: from localhost.localdomain (/77.138.186.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 16 Jan 2019 07:15:57 -0800 From: Yuval Shaia To: yuval.shaia@oracle.com, marcel.apfelbaum@gmail.com, qemu-devel@nongnu.org, philmd@redhat.com Date: Wed, 16 Jan 2019 17:15:38 +0200 Message-Id: <20190116151538.14088-1-yuval.shaia@oracle.com> X-Mailer: git-send-email 2.17.2 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9138 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=936 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901160125 X-MIME-Autoconverted: from 8bit to quoted-printable by aserp2130.oracle.com id x0GFCnXn043100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [PATCH v1] hw/rdma: Verify that ptr is not NULL before freeing 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP To cover the case where fini() was called even when init() fails make sure objects are not NULL before calling to non-null-safe destructors. Signed-off-by: Yuval Shaia Reviewed-by: Philippe Mathieu-Daudé --- v0 -> v1: * Fix comment per Philippe's comment * Add Philippe's r-b --- hw/rdma/rdma_backend.c | 6 ++++-- hw/rdma/rdma_rm.c | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c index b49edaacaf..3ee5172c96 100644 --- a/hw/rdma/rdma_backend.c +++ b/hw/rdma/rdma_backend.c @@ -1066,8 +1066,10 @@ static void mad_fini(RdmaBackendDev *backend_dev) pr_dbg("Stopping MAD\n"); disable_rdmacm_mux_async(backend_dev); qemu_chr_fe_disconnect(backend_dev->rdmacm_mux.chr_be); - qlist_destroy_obj(QOBJECT(backend_dev->recv_mads_list.list)); - qemu_mutex_destroy(&backend_dev->recv_mads_list.lock); + if (backend_dev->recv_mads_list.list) { + qlist_destroy_obj(QOBJECT(backend_dev->recv_mads_list.list)); + qemu_mutex_destroy(&backend_dev->recv_mads_list.lock); + } } int rdma_backend_get_gid_index(RdmaBackendDev *backend_dev, diff --git a/hw/rdma/rdma_rm.c b/hw/rdma/rdma_rm.c index f5b1295890..8bf241e91f 100644 --- a/hw/rdma/rdma_rm.c +++ b/hw/rdma/rdma_rm.c @@ -41,6 +41,9 @@ static inline void res_tbl_init(const char *name, RdmaRmResTbl *tbl, static inline void res_tbl_free(RdmaRmResTbl *tbl) { + if (!tbl->bitmap) { + return; + } qemu_mutex_destroy(&tbl->lock); g_free(tbl->tbl); g_free(tbl->bitmap); @@ -655,5 +658,7 @@ void rdma_rm_fini(RdmaDeviceResources *dev_res, RdmaBackendDev *backend_dev, res_tbl_free(&dev_res->cq_tbl); res_tbl_free(&dev_res->pd_tbl); - g_hash_table_destroy(dev_res->qp_hash); + if (dev_res->qp_hash) { + g_hash_table_destroy(dev_res->qp_hash); + } }