Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp585203ybi; Wed, 17 Jul 2019 01:39:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXsJvZYNzBG6RxVTCMdzXjX38Qw2q4yqTlTzVlGhM86T8V+F6hW0E1+SfVBvw0c0IQu+kV X-Received: by 2002:a17:90a:bf0e:: with SMTP id c14mr40689790pjs.55.1563352776820; Wed, 17 Jul 2019 01:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563352776; cv=none; d=google.com; s=arc-20160816; b=D2cfPIqCwtH0wS2VzBrMxYo+9Nyw5WP53Bl5f1T+i/1ABDquz6O5gicuHMKSVyBUKu r+C5BeJsOXXb9OVwRzXAVOUmrJRTAi3J8dqBO3utblOvXVLwD6kDqVJbZv32ZwAjxP2u YijICpyBUk4r0Hi4fh8yYCcb3BBrCykeatNbLU1GwokdxYZ7KWiIRv/vME0uyH6FIT9P 2D31qlNKo5JBMgVcWAC/g5quz5+6B90HTigOxo/8HsR//g4wcmgK/3nznUsx4isdqs7v cOEdE7FNKfFs7ZrmAmd5EMRTujrsBCrAP9i3/LaWStC7S3hpNnjCHgH9jVTjW6FhQSA7 gxHg== 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:to:from :dkim-signature; bh=9/TnBhjqofSLZTuk4X2e91/4T2StXPyjA/joZ3UiOEU=; b=SF49ertyZbfyVnpwjINDp30iI6tfwhfhs5b15U5PrcpkdKM42YD7MHQTo7u9vguq6a HGlux/+PLgwlE1w6qxkZ31OxI2ewL+sf85+dRfuMs6qyRIn2OqnkLWeue0cvJ71sDUyc Y83hZcCBV2HYDvKVcQbBCSlhCllC3KOdSwmYiA20fQkEGR0p+1/6j8ajKmtvG1cAleKb ny4kPsieakRc8MYT5c8nH8MYzVG6pOv/KepTOeGcS7hFQf9tXPhch27bL8ByMjgNWiRA oq2ocoFijSWxotdlrX4TEzx5x9pwWvb58uBCHGHd0Dt3R6OjU/5j7L0lOibH63wAotS8 azPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=jssnYUHS; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f25si7957648pfd.157.2019.07.17.01.39.21; Wed, 17 Jul 2019 01:39:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=jssnYUHS; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726695AbfGQIhM (ORCPT + 99 others); Wed, 17 Jul 2019 04:37:12 -0400 Received: from mail-lf1-f44.google.com ([209.85.167.44]:44462 "EHLO mail-lf1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725873AbfGQIhM (ORCPT ); Wed, 17 Jul 2019 04:37:12 -0400 Received: by mail-lf1-f44.google.com with SMTP id r15so10913177lfm.11 for ; Wed, 17 Jul 2019 01:37:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=9/TnBhjqofSLZTuk4X2e91/4T2StXPyjA/joZ3UiOEU=; b=jssnYUHSX0W/BDI3tzTvnBPx3ojFGsz3BRv6b4xFniMtcPZQH8Lt+h8jvUtNoztII5 IIJsGvWMRhTZ1i5VgrFV2UR/Hf/vq0N1rgQQIm2xW0svX5Bol5nFgy39xnhBmWoOI1K5 +jFEN4tLn8ifJ1EpKTqSZX9DN3Of8u6aVp6UTYlWBJzdRmEveqMvCS3HWXskYRsBoG/4 z0tnEpINg1f6Vi/rbwEd5tD0Drjxd3vKxM7N15smurQNILHN1CeeUuYHelCgG7kJ6kdY z201pJ9eoE9iwBSJVVP+bwJqYCcvIXNfF17i2NlLToX4deU5DNmoBmSCHMP72slc3ntM 9Mlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9/TnBhjqofSLZTuk4X2e91/4T2StXPyjA/joZ3UiOEU=; b=pFHVpfWFhtfdQv2PJjOnYnFbAfV2gneNOOjKrSyIp390KsIN/aoprFvLXvOfJ4M2sB mPoN/bPRKQJuv7pXjaZW9isjh8md40vxd4RWhyRTeNIt+Q2pIXyj6wmM330B1h4QN9MD cpvX1baA3N8M12065/byDD641qO/ibWe1rxjoNU82Gi8vZteMJJE3qvzCtoDi94ORapY G27qIWRwaTvc1lnc00/iE2F2DL0SVTwjXYlc5BnjTkyblKAhfifZrTRiQ8jug29W8RI/ HnZNoycUS2/f66awWHPOTBQb/3BwnaT7MobgHh0xNa+8v2DuTq0AYuGb5ZMVDKsaNydr OmpA== X-Gm-Message-State: APjAAAXK3CYrbT0bZftcsZvH5tZAmr9XzzDTGUmLb5s51M+TojO9vrGC HndSKuyrXQUUna677RzzVeXvFBulPCs= X-Received: by 2002:a19:7f17:: with SMTP id a23mr18567449lfd.49.1563352629996; Wed, 17 Jul 2019 01:37:09 -0700 (PDT) Received: from localhost.localdomain ([31.0.84.191]) by smtp.gmail.com with ESMTPSA id v202sm3338708lfa.28.2019.07.17.01.37.08 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 17 Jul 2019 01:37:09 -0700 (PDT) From: =?UTF-8?q?Micha=C5=82=20Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v5 4/4] mesh: Convert void pointers to anonymous unions in managed_obj_request:wq Date: Wed, 17 Jul 2019 10:36:50 +0200 Message-Id: <20190717083650.26346-5-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190717083650.26346-1-michal.lowas-rzechonek@silvair.com> References: <20190717083650.26346-1-michal.lowas-rzechonek@silvair.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 --- mesh/node.c | 69 +++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/mesh/node.c b/mesh/node.c index d1b37a5da..d631b9324 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -112,8 +112,14 @@ struct mesh_node { }; struct managed_obj_request { - void *data; - void *cb; + union { + const uint8_t *uuid; + struct mesh_node *node; + }; + union { + node_ready_func_t ready_cb; + node_join_ready_func_t join_ready_cb; + }; struct l_dbus_message *pending_msg; enum request_type type; struct mesh_config_import *import; @@ -1571,10 +1577,10 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) } if (is_new) { - node = node_new(req->data); + node = node_new(req->uuid); node->elements = l_queue_new(); } else { - node = req->data; + node = req->node; } num_ele = 0; @@ -1644,8 +1650,6 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) } if (req->type == REQUEST_TYPE_ATTACH) { - node_ready_func_t cb = req->cb; - if (num_ele != node->num_ele) goto fail; @@ -1654,13 +1658,11 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) node->disc_watch = l_dbus_add_disconnect_watch(bus, node->owner, app_disc_cb, node, NULL); - cb(req->pending_msg, MESH_ERROR_NONE, node); + req->ready_cb(req->pending_msg, MESH_ERROR_NONE, node); } else goto fail; } else if (req->type == REQUEST_TYPE_JOIN) { - node_join_ready_func_t cb = req->cb; - if (!agent) { l_error("Interface %s not found", MESH_PROVISION_AGENT_INTERFACE); @@ -1669,16 +1671,14 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) node->num_ele = num_ele; set_defaults(node); - memcpy(node->uuid, req->data, 16); + memcpy(node->uuid, req->uuid, 16); if (!create_node_config(node, node->uuid)) goto fail; - cb(node, agent); + req->join_ready_cb(node, agent); } else if (req->type == REQUEST_TYPE_IMPORT) { - - node_ready_func_t cb = req->cb; struct mesh_config_import *import = req->import; struct keyring_net_key net_key; @@ -1694,7 +1694,7 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) if (node->seq_number != import->node->seq_number) node->seq_number = import->node->seq_number; - memcpy(node->uuid, req->data, 16); + memcpy(node->uuid, req->uuid, 16); if (!create_node_config(node, node->uuid)) goto fail; @@ -1719,17 +1719,16 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) if (!keyring_put_net_key(node, import->net_key.idx, &net_key)) goto fail; - cb(req->pending_msg, MESH_ERROR_NONE, node); + req->ready_cb(req->pending_msg, MESH_ERROR_NONE, node); } else { /* Callback for create node request */ - node_ready_func_t cb = req->cb; struct keyring_net_key net_key; uint8_t dev_key[16]; node->num_ele = num_ele; set_defaults(node); - memcpy(node->uuid, req->data, 16); + memcpy(node->uuid, req->uuid, 16); if (!create_node_config(node, node->uuid)) goto fail; @@ -1756,7 +1755,7 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) if (!keyring_put_net_key(node, PRIMARY_NET_IDX, &net_key)) goto fail; - cb(req->pending_msg, MESH_ERROR_NONE, node); + req->ready_cb(req->pending_msg, MESH_ERROR_NONE, node); } return; @@ -1765,26 +1764,18 @@ fail: mesh_agent_remove(agent); if (!is_new) { - /* Handle failed Attach request */ - node_ready_func_t cb = req->cb; - free_node_dbus_resources(node); - cb(req->pending_msg, MESH_ERROR_FAILED, node); + req->ready_cb(req->pending_msg, MESH_ERROR_FAILED, node); } else { /* Handle failed Join, Create and Import requests */ if (node) node_remove(node); - if (req->type == REQUEST_TYPE_JOIN) { - node_join_ready_func_t cb = req->cb; - - cb(NULL, NULL); - } else { - node_ready_func_t cb = req->cb; - - cb(req->pending_msg, MESH_ERROR_FAILED, NULL); - } + if (req->type == REQUEST_TYPE_JOIN) + req->join_ready_cb(NULL, NULL); + else + req->ready_cb(req->pending_msg, MESH_ERROR_FAILED, NULL); } } @@ -1809,8 +1800,8 @@ int node_attach(const char *app_path, const char *sender, uint64_t token, node->owner = l_strdup(sender); req = l_new(struct managed_obj_request, 1); - req->data = node; - req->cb = cb; + req->node = node; + req->ready_cb = cb; req->pending_msg = user_data; req->type = REQUEST_TYPE_ATTACH; @@ -1833,8 +1824,8 @@ void node_join(const char *app_path, const char *sender, const uint8_t *uuid, l_debug(""); req = l_new(struct managed_obj_request, 1); - req->data = (void *) uuid; - req->cb = cb; + req->uuid = uuid; + req->join_ready_cb = cb; req->type = REQUEST_TYPE_JOIN; l_dbus_method_call(dbus_get_bus(), sender, app_path, @@ -1859,8 +1850,8 @@ bool node_import(const char *app_path, const char *sender, req = l_new(struct managed_obj_request, 1); - req->data = (void *) uuid; - req->cb = cb; + req->uuid = uuid; + req->ready_cb = cb; req->pending_msg = user_data; req->import = import; req->type = REQUEST_TYPE_IMPORT; @@ -1881,8 +1872,8 @@ void node_create(const char *app_path, const char *sender, const uint8_t *uuid, l_debug(""); req = l_new(struct managed_obj_request, 1); - req->data = (void *) uuid; - req->cb = cb; + req->uuid = uuid; + req->ready_cb = cb; req->pending_msg = user_data; req->type = REQUEST_TYPE_CREATE; -- 2.19.1