linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/2] mesh: Move SEQ_MASK define in mesh-defs.h
@ 2020-04-02  0:04 Inga Stotland
  2020-04-02  0:04 ` [PATCH BlueZ 2/2] mesh: Fix segfault related to idle config write Inga Stotland
  2020-04-02  1:33 ` [PATCH BlueZ 1/2] mesh: Move SEQ_MASK define in mesh-defs.h Gix, Brian
  0 siblings, 2 replies; 3+ messages in thread
From: Inga Stotland @ 2020-04-02  0:04 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

---
 mesh/mesh-config-json.c | 1 -
 mesh/mesh-defs.h        | 1 +
 mesh/net.h              | 1 -
 3 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index ad2d4d0f8..172e0e355 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -40,7 +40,6 @@
 #include "mesh/mesh-defs.h"
 #include "mesh/util.h"
 #include "mesh/mesh-config.h"
-#include "mesh/net.h"
 
 /* To prevent local node JSON cache thrashing, minimum update times */
 #define MIN_SEQ_CACHE_TRIGGER	32
diff --git a/mesh/mesh-defs.h b/mesh/mesh-defs.h
index 9353d7351..bbde53303 100644
--- a/mesh/mesh-defs.h
+++ b/mesh/mesh-defs.h
@@ -110,6 +110,7 @@
 #define APP_IDX_DEV_LOCAL	0x7fff
 
 #define DEFAULT_SEQUENCE_NUMBER 0x000000
+#define SEQ_MASK		0xffffff
 
 #define IS_UNASSIGNED(x)	((x) == UNASSIGNED_ADDRESS)
 #define IS_UNICAST(x)		(((x) > UNASSIGNED_ADDRESS) && \
diff --git a/mesh/net.h b/mesh/net.h
index 60396dbe7..bfc8064f3 100644
--- a/mesh/net.h
+++ b/mesh/net.h
@@ -31,7 +31,6 @@ struct mesh_node;
 #define APP_AID_DEV	0x00
 
 #define CTL		0x80
-#define SEQ_MASK	0xffffff
 
 #define CREDFLAG_MASK	0x1000
 
-- 
2.21.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH BlueZ 2/2] mesh: Fix segfault related to idle config write
  2020-04-02  0:04 [PATCH BlueZ 1/2] mesh: Move SEQ_MASK define in mesh-defs.h Inga Stotland
@ 2020-04-02  0:04 ` Inga Stotland
  2020-04-02  1:33 ` [PATCH BlueZ 1/2] mesh: Move SEQ_MASK define in mesh-defs.h Gix, Brian
  1 sibling, 0 replies; 3+ messages in thread
From: Inga Stotland @ 2020-04-02  0:04 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

If node configuration is completely removed from the system,
remove all pending writes to the configuration file.

Fixes the segfault below:

mesh/cfgmod-server.c:node_reset() Node Reset
mesh/mesh-config-json.c:mesh_config_destroy() Delete node config /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c
mesh/util.c:del_fobject() RM /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c/rpl/00000000/0001
mesh/util.c:del_fobject() RMDIR /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c/rpl/00000000
mesh/util.c:del_fobject() RMDIR /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c/rpl
mesh/util.c:del_fobject() RM /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c/node.json.bak
mesh/util.c:del_fobject() RM /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c/node.json
mesh/util.c:del_fobject() RMDIR /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c
Segmentation fault

Program terminated with signal SIGSEGV, Segmentation fault.

  0x0000563a35df2ed0 in ?? ()
  0x00007fd6b131689f in json_object_to_json_string_length (jso=jso@entry=0x563a35dd8d30, flags=flags@entry=2,
---
 mesh/mesh-config-json.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index 172e0e355..97267b6c3 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -54,6 +54,7 @@ struct mesh_config {
 	uint8_t uuid[16];
 	uint32_t write_seq;
 	struct timeval write_time;
+	struct l_queue *idles;
 };
 
 struct write_info {
@@ -1677,6 +1678,7 @@ static struct mesh_config *create_config(const char *cfg_path,
 	memcpy(cfg->uuid, uuid, 16);
 	cfg->node_dir_path = l_strdup(cfg_path);
 	cfg->write_seq = node->seq_number;
+	cfg->idles = l_queue_new();
 	gettimeofday(&cfg->write_time, NULL);
 
 	return cfg;
@@ -2104,6 +2106,7 @@ static bool load_node(const char *fname, const uint8_t uuid[16],
 		memcpy(cfg->uuid, uuid, 16);
 		cfg->node_dir_path = l_strdup(fname);
 		cfg->write_seq = node.seq_number;
+		cfg->idles = l_queue_new();
 		gettimeofday(&cfg->write_time, NULL);
 
 		result = cb(&node, uuid, cfg, user_data);
@@ -2130,17 +2133,26 @@ done:
 	return result;
 }
 
+static void release_idle(void *data)
+{
+	struct l_idle *idle = data;
+
+	l_idle_remove(idle);
+}
+
 void mesh_config_release(struct mesh_config *cfg)
 {
 	if (!cfg)
 		return;
 
+	l_queue_destroy(cfg->idles, release_idle);
+
 	l_free(cfg->node_dir_path);
 	json_object_put(cfg->jnode);
 	l_free(cfg);
 }
 
-static void idle_save_config(void *user_data)
+static void idle_save_config(struct l_idle *idle, void *user_data)
 {
 	struct write_info *info = user_data;
 	char *fname_tmp, *fname_bak, *fname_cfg;
@@ -2169,6 +2181,11 @@ static void idle_save_config(void *user_data)
 	if (info->cb)
 		info->cb(info->user_data, result);
 
+	if (idle) {
+		l_queue_remove(info->cfg->idles, idle);
+		l_idle_remove(idle);
+	}
+
 	l_free(info);
 
 }
@@ -2186,10 +2203,14 @@ bool mesh_config_save(struct mesh_config *cfg, bool no_wait,
 	info->cb = cb;
 	info->user_data = user_data;
 
-	if (no_wait)
-		idle_save_config(info);
-	else
-		l_idle_oneshot(idle_save_config, info, NULL);
+	if (no_wait) {
+		idle_save_config(NULL, info);
+	} else {
+		struct l_idle *idle;
+
+		idle = l_idle_create(idle_save_config, info, NULL);
+		l_queue_push_tail(cfg->idles, idle);
+	}
 
 	return true;
 }
-- 
2.21.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH BlueZ 1/2] mesh: Move SEQ_MASK define in mesh-defs.h
  2020-04-02  0:04 [PATCH BlueZ 1/2] mesh: Move SEQ_MASK define in mesh-defs.h Inga Stotland
  2020-04-02  0:04 ` [PATCH BlueZ 2/2] mesh: Fix segfault related to idle config write Inga Stotland
@ 2020-04-02  1:33 ` Gix, Brian
  1 sibling, 0 replies; 3+ messages in thread
From: Gix, Brian @ 2020-04-02  1:33 UTC (permalink / raw)
  To: linux-bluetooth@vger.kernel.org, Stotland, Inga

Patchset applied
On Wed, 2020-04-01 at 17:04 -0700, Inga Stotland wrote:
> ---
>  mesh/mesh-config-json.c | 1 -
>  mesh/mesh-defs.h        | 1 +
>  mesh/net.h              | 1 -
>  3 files changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
> index ad2d4d0f8..172e0e355 100644
> --- a/mesh/mesh-config-json.c
> +++ b/mesh/mesh-config-json.c
> @@ -40,7 +40,6 @@
>  #include "mesh/mesh-defs.h"
>  #include "mesh/util.h"
>  #include "mesh/mesh-config.h"
> -#include "mesh/net.h"
>  
>  /* To prevent local node JSON cache thrashing, minimum update times */
>  #define MIN_SEQ_CACHE_TRIGGER	32
> diff --git a/mesh/mesh-defs.h b/mesh/mesh-defs.h
> index 9353d7351..bbde53303 100644
> --- a/mesh/mesh-defs.h
> +++ b/mesh/mesh-defs.h
> @@ -110,6 +110,7 @@
>  #define APP_IDX_DEV_LOCAL	0x7fff
>  
>  #define DEFAULT_SEQUENCE_NUMBER 0x000000
> +#define SEQ_MASK		0xffffff
>  
>  #define IS_UNASSIGNED(x)	((x) == UNASSIGNED_ADDRESS)
>  #define IS_UNICAST(x)		(((x) > UNASSIGNED_ADDRESS) && \
> diff --git a/mesh/net.h b/mesh/net.h
> index 60396dbe7..bfc8064f3 100644
> --- a/mesh/net.h
> +++ b/mesh/net.h
> @@ -31,7 +31,6 @@ struct mesh_node;
>  #define APP_AID_DEV	0x00
>  
>  #define CTL		0x80
> -#define SEQ_MASK	0xffffff
>  
>  #define CREDFLAG_MASK	0x1000
>  

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-02  1:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-02  0:04 [PATCH BlueZ 1/2] mesh: Move SEQ_MASK define in mesh-defs.h Inga Stotland
2020-04-02  0:04 ` [PATCH BlueZ 2/2] mesh: Fix segfault related to idle config write Inga Stotland
2020-04-02  1:33 ` [PATCH BlueZ 1/2] mesh: Move SEQ_MASK define in mesh-defs.h Gix, Brian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).