Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp199495ybg; Mon, 8 Jun 2020 20:59:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbGat9AyHvi/Xa5wn+0d4f3cL7u5XSJ6A3ijLFDClfvjCOeKzA3kL/I8jUZ0wuSKesDDWQ X-Received: by 2002:a17:906:af62:: with SMTP id os2mr23624276ejb.345.1591675195517; Mon, 08 Jun 2020 20:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591675195; cv=none; d=google.com; s=arc-20160816; b=OORg5SqlBYunG+KRtbKtzn6QPW4B+lF3E4pzUyPFSgkkFcBP75/RTG5RroekZamF5l PFHmgbRAgrVbiY0i66ILNClNyq4Wzt+f5cwkXFkhMj9OV07PO0r5bk2e7wIMk7YKy2Kb qNaRAnB9vM797XKA6LaMmYb0vxairtLbQkqyVCc9cpIkGMukXHQq590zAIl8U6qAABvG GumkJp9Jw8BxJli0gZ5fsyGVQegSbYWcEtM8Nf/DL8CRmLTpxjlquvtM3TetACyTPXQ+ X1oOFA+Jm5IVFN41jHJ0qUBSScbuqEkJJJOjSyp37xhx2zQDITEtieL8KTv7yDwlbknG Qo2A== 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=fWnJ9Jpp6dsYjaVrpK0kLCjS2N3p2kUOk9R9mDG/pXA=; b=FbVNovHS/0IhMtPWhBow6UThgcpeFThecM0Jok4JbF/tA3j41Ll41qynUaP66cug9l XSNSn//suI2xoWa7XEi/hd3V9894QQlggBj6voUKNcOm/V+EESFidhSq4pwbapW6iBIz tJsV/hJMv0yGMYiWte6EH6W93v0QsmIKYuG4SSF3tC5OIud+TPSgVl9Psm8OLDK80jrV RXTQJL97pXXFMufkaG3r+wgxdWIiFqsac0mZyADiqifYFkL0e5tZcvrwd6SqqTz454Ht lD8Feu1qGa7jTZQp1B44BXiDibb3Weo1jVI5EHL7YhGqcIZB1WlnAsKg3elwbsXHaxMD 0mMw== 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 j27si10356815ejk.350.2020.06.08.20.59.22; Mon, 08 Jun 2020 20:59:55 -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 S1726924AbgFID7P (ORCPT + 99 others); Mon, 8 Jun 2020 23:59:15 -0400 Received: from mga12.intel.com ([192.55.52.136]:17236 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726803AbgFID7N (ORCPT ); Mon, 8 Jun 2020 23:59:13 -0400 IronPort-SDR: obwE9KCuyTUQ1nxsEaweWcjz2EBbnJDd2opYdAolPe4vY3s+RIfmTzG7n4BR8W44dLZ0zaxcUR 95F4HxpCqyfQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2020 20:59:12 -0700 IronPort-SDR: zKH39IKqhmcIEqI+bXNouWkLTKYBTrLsuD8YyUQnAI8rbG0HgqDCORenu82JWY3oW057xscCsA Vf2cKRi0JV1A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,490,1583222400"; d="scan'208";a="274461148" Received: from vrsuryad-mobl1.amr.corp.intel.com (HELO ingas-nuc1.sea.intel.com) ([10.255.228.38]) by orsmga006.jf.intel.com with ESMTP; 08 Jun 2020 20:59:12 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, przemyslaw.fierek@silvair.com, Inga Stotland Subject: [PATCH BlueZ 2/4] mesh: Add destroy callback to dbus_send_with_timeout() Date: Mon, 8 Jun 2020 20:59:07 -0700 Message-Id: <20200609035909.51061-3-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200609035909.51061-1-inga.stotland@intel.com> References: <20200609035909.51061-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 adds a destroy callback as a function parameter to dbus_send_with_timeout() to allow automatic release of user data on either reply or timeout. --- mesh/dbus.c | 11 ++++++++--- mesh/dbus.h | 1 + mesh/mesh.c | 12 ++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mesh/dbus.c b/mesh/dbus.c index 83ae22c9f..ba2a28de5 100644 --- a/mesh/dbus.c +++ b/mesh/dbus.c @@ -41,6 +41,7 @@ struct send_info { struct l_dbus *dbus; struct l_timeout *timeout; l_dbus_message_func_t cb; + l_dbus_destroy_func_t destroy_cb; void *user_data; uint32_t serial; }; @@ -153,12 +154,14 @@ void dbus_append_dict_entry_basic(struct l_dbus_message_builder *builder, l_dbus_message_builder_leave_dict(builder); } -static void send_reply(struct l_dbus_message *message, void *user_data) +static void send_reply_cb(struct l_dbus_message *message, void *user_data) { struct send_info *info = user_data; l_timeout_remove(info->timeout); info->cb(message, info->user_data); + if (info->destroy_cb) + info->destroy_cb(info->user_data); l_free(info); } @@ -167,12 +170,13 @@ static void send_timeout(struct l_timeout *timeout, void *user_data) struct send_info *info = user_data; l_dbus_cancel(info->dbus, info->serial); - send_reply(NULL, info); + send_reply_cb(NULL, info); } void dbus_send_with_timeout(struct l_dbus *dbus, struct l_dbus_message *msg, l_dbus_message_func_t cb, void *user_data, + l_dbus_destroy_func_t destroy, unsigned int seconds) { struct send_info *info = l_new(struct send_info, 1); @@ -180,7 +184,8 @@ void dbus_send_with_timeout(struct l_dbus *dbus, struct l_dbus_message *msg, info->dbus = dbus; info->cb = cb; info->user_data = user_data; - info->serial = l_dbus_send_with_reply(dbus, msg, send_reply, + info->destroy_cb = destroy; + info->serial = l_dbus_send_with_reply(dbus, msg, send_reply_cb, info, NULL); info->timeout = l_timeout_create(seconds, send_timeout, info, NULL); } diff --git a/mesh/dbus.h b/mesh/dbus.h index aafb85f6b..89d6b1d31 100644 --- a/mesh/dbus.h +++ b/mesh/dbus.h @@ -36,4 +36,5 @@ struct l_dbus_message *dbus_error(struct l_dbus_message *msg, int err, void dbus_send_with_timeout(struct l_dbus *dbus, struct l_dbus_message *msg, l_dbus_message_func_t cb, void *user_data, + l_dbus_destroy_func_t destroy, unsigned int seconds); diff --git a/mesh/mesh.c b/mesh/mesh.c index 24ea3afd6..a5935c216 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -439,12 +439,12 @@ static void send_join_failed(const char *owner, const char *path, free_pending_join_call(true); } -static void prov_join_complete_reply_cb(struct l_dbus_message *message, +static void prov_join_complete_reply_cb(struct l_dbus_message *msg, void *user_data) { bool failed = false; - if (!message || l_dbus_message_is_error(message)) + if (!msg || l_dbus_message_is_error(msg)) failed = true; if (!failed) @@ -488,7 +488,7 @@ static bool prov_complete_cb(void *user_data, uint8_t status, l_dbus_message_set_arguments(msg, "t", l_get_be64(token)); dbus_send_with_timeout(dbus, msg, prov_join_complete_reply_cb, - NULL, DEFAULT_DBUS_TIMEOUT); + NULL, NULL, DEFAULT_DBUS_TIMEOUT); return true; } @@ -666,12 +666,12 @@ static struct l_dbus_message *leave_call(struct l_dbus *dbus, return l_dbus_message_new_method_return(msg); } -static void create_join_complete_reply_cb(struct l_dbus_message *message, +static void create_join_complete_reply_cb(struct l_dbus_message *msg, void *user_data) { struct mesh_node *node = user_data; - if (!message || l_dbus_message_is_error(message)) { + if (!msg || l_dbus_message_is_error(msg)) { node_remove(node); return; } @@ -716,7 +716,7 @@ static void create_node_ready_cb(void *user_data, int status, l_dbus_message_set_arguments(msg, "t", l_get_be64(token)); dbus_send_with_timeout(dbus, msg, create_join_complete_reply_cb, - node, DEFAULT_DBUS_TIMEOUT); + node, NULL, DEFAULT_DBUS_TIMEOUT); l_dbus_message_unref(pending_msg); } -- 2.26.2