Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1859070ybk; Thu, 21 May 2020 17:38:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfgKPXC1kr0C8SBtysY036PRA498snF8RiJbMpDtknxaY+nffvZJQgFizyrP4FwzsyQiYR X-Received: by 2002:a17:906:b182:: with SMTP id w2mr6077864ejy.261.1590107914877; Thu, 21 May 2020 17:38:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590107914; cv=none; d=google.com; s=arc-20160816; b=nYOkL2tDm3DFq5j2XRqJdOkgN45eppOeLRTx/rdIcvV1MyvlTGs0+WsjAhLSZs+QEY D5SVzdgx4v7BqiSEybXCdCatboisQYTbfoT38iC9S++3bmC9h7Lj9zxiFfbVeUpPvdio 3N5V49pgx6W+thGEpBxMhoFin6XRVhTYG3E7CgJAGmWlHBoCfLUmtCEAIyxyujjEoNL7 VVwwaMTwpZFNGvN4mQ7nV+oQ0Q5qR6AziB5V9CbydMZC/ur5ih8oo88sZ78V+EOPynAv XM5D5UoBqoWFWs8ly/jexVl3AgUCScjsvqOxq18QT8DmqNAxEIrTtc1XEQeOqWv8rmXM CeMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=grlFbO+5IWG7OSMraA3DhUOn5kUp4HlhRXlTNjdZgfI=; b=sdKs2Xs93dpzMOVLYu8+d6CcFjH9O/Ei4bFGVDhCfmbn1JjSIt9XVL+Js/D3ls9BCy Y1MQyNMUDDmO00p7vmZOxWOg4MFrkvA2U4tEgLWvuSBp4R1uEP99WF1xZcq7mC6XbNEX a7zWkUBP2r4AL7KT/bPgEL8uatnsCzN5FR0zxs8DjBTAh79MyIPShXIUwgSChDUKCHB+ ScbFLLo4vsrQZ+ehH01DTN2KFsO/h0PUI9YrzonrcZ4oRHw/vdyGL8eJrCk6klSs+fL6 2eKcdzMEmQGqzIUVUa+IvTr57H9Nq11Tj2egAoEaCICekONMV+wGrE3xVpq+DLTGs+MI t/OA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q12si4049773edn.500.2020.05.21.17.38.11; Thu, 21 May 2020 17:38:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726966AbgEVAfJ (ORCPT + 99 others); Thu, 21 May 2020 20:35:09 -0400 Received: from mga14.intel.com ([192.55.52.115]:55685 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727000AbgEVAfI (ORCPT ); Thu, 21 May 2020 20:35:08 -0400 IronPort-SDR: jpHkh++iznV5bEp74OigBIUsdPyIxahmlr5OqVAdAe+kRWrdMxR4J2ZS64IB9Y1usagUoUBV5c c5yZd1YXyqnA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2020 17:35:07 -0700 IronPort-SDR: joLupDWfE32RtaprLZBqREJTZrr9FbG71lRQBOm8+qPoht1CANhjedAhZu/umtxJzV4Rwsierx rWp0qJ1i+BmA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,419,1583222400"; d="scan'208";a="300961706" Received: from nsalivat-mobl.amr.corp.intel.com (HELO ingas-nuc1.sea.intel.com) ([10.254.98.52]) by orsmga008.jf.intel.com with ESMTP; 21 May 2020 17:35:07 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ 10/10] mesh: Clean up Join() method Date: Thu, 21 May 2020 17:35:01 -0700 Message-Id: <20200522003501.106165-11-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200522003501.106165-1-inga.stotland@intel.com> References: <20200522003501.106165-1-inga.stotland@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This consolidates various places where a pending response to Join() is created and makes sure that l_dus_message_unref() is called correctly. --- mesh/mesh.c | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/mesh/mesh.c b/mesh/mesh.c index 6f8974745..24ea3afd6 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -341,6 +341,7 @@ void mesh_cleanup(void) reply = dbus_error(join_pending->msg, MESH_ERROR_FAILED, "Failed. Exiting"); l_dbus_send(dbus_get_bus(), reply); + l_dbus_message_unref(join_pending->msg); } acceptor_cancel(&mesh); @@ -391,11 +392,6 @@ static void prov_disc_cb(struct l_dbus *bus, void *user_data) if (!join_pending) return; - if (join_pending->msg) { - l_dbus_message_unref(join_pending->msg); - join_pending->msg = NULL; - } - acceptor_cancel(&mesh); join_pending->disc_watch = 0; @@ -501,39 +497,40 @@ static void node_init_cb(struct mesh_node *node, struct mesh_agent *agent) { struct l_dbus_message *reply; uint8_t num_ele; + bool is_error = false; + struct l_dbus *dbus = dbus_get_bus(); if (!node) { reply = dbus_error(join_pending->msg, MESH_ERROR_FAILED, "Failed to create node from application"); - goto fail; + is_error = true; + goto done; } join_pending->node = node; num_ele = node_get_num_elements(node); if (!acceptor_start(num_ele, join_pending->uuid, mesh.algorithms, - mesh.prov_timeout, agent, prov_complete_cb, - &mesh)) - { + mesh.prov_timeout, agent, + prov_complete_cb, &mesh)) { reply = dbus_error(join_pending->msg, MESH_ERROR_FAILED, "Failed to start provisioning acceptor"); - goto fail; - } + is_error = true; + } else + reply = l_dbus_message_new_method_return(join_pending->msg); - reply = l_dbus_message_new_method_return(join_pending->msg); - l_dbus_send(dbus_get_bus(), reply); +done: + l_dbus_send(dbus, reply); + l_dbus_message_unref(join_pending->msg); join_pending->msg = NULL; - /* Setup disconnect watch */ - join_pending->disc_watch = l_dbus_add_disconnect_watch(dbus_get_bus(), + if (is_error) + free_pending_join_call(true); + else + /* Setup disconnect watch */ + join_pending->disc_watch = l_dbus_add_disconnect_watch(dbus, join_pending->sender, prov_disc_cb, NULL, NULL); - - return; - -fail: - l_dbus_send(dbus_get_bus(), reply); - free_pending_join_call(true); } static struct l_dbus_message *join_network_call(struct l_dbus *dbus, @@ -591,25 +588,23 @@ static struct l_dbus_message *cancel_join_call(struct l_dbus *dbus, l_debug("Cancel Join"); - if (!join_pending) { - reply = dbus_error(msg, MESH_ERROR_DOES_NOT_EXIST, + if (!join_pending) + return dbus_error(msg, MESH_ERROR_DOES_NOT_EXIST, "No join in progress"); - goto done; - } - acceptor_cancel(&mesh); /* Return error to the original Join call */ if (join_pending->msg) { reply = dbus_error(join_pending->msg, MESH_ERROR_FAILED, NULL); l_dbus_send(dbus_get_bus(), reply); + l_dbus_message_unref(join_pending->msg); } reply = l_dbus_message_new_method_return(msg); l_dbus_message_set_arguments(reply, ""); free_pending_join_call(true); -done: + return reply; } -- 2.26.2