This removes checks for the return values of l_dbus_message...()
calls in the few places where we can rely on ell to handle error
cases gracefully.
---
mesh/dbus.c | 20 ++++++++++----------
mesh/dbus.h | 2 +-
mesh/model.c | 33 +++++++++------------------------
3 files changed, 20 insertions(+), 35 deletions(-)
diff --git a/mesh/dbus.c b/mesh/dbus.c
index 2b700a1ad..6b9694ab7 100644
--- a/mesh/dbus.c
+++ b/mesh/dbus.c
@@ -113,29 +113,29 @@ bool dbus_match_interface(struct l_dbus_message_iter *interfaces,
return false;
}
-bool dbus_append_byte_array(struct l_dbus_message_builder *builder,
+void dbus_append_byte_array(struct l_dbus_message_builder *builder,
const uint8_t *data, int len)
{
int i;
- if (!l_dbus_message_builder_enter_array(builder, "y"))
- return false;
+ if (!builder)
+ return;
- for (i = 0; i < len; i++)
- if (!l_dbus_message_builder_append_basic(builder, 'y',
- data + i))
- return false;
+ l_dbus_message_builder_enter_array(builder, "y");
- if (!l_dbus_message_builder_leave_array(builder))
- return false;
+ for (i = 0; i < len; i++)
+ l_dbus_message_builder_append_basic(builder, 'y', data + i);
- return true;
+ l_dbus_message_builder_leave_array(builder);
}
void dbus_append_dict_entry_basic(struct l_dbus_message_builder *builder,
const char *key, const char *signature,
const void *data)
{
+ if (!builder)
+ return;
+
l_dbus_message_builder_enter_dict(builder, "sv");
l_dbus_message_builder_append_basic(builder, 's', key);
l_dbus_message_builder_enter_variant(builder, signature);
diff --git a/mesh/dbus.h b/mesh/dbus.h
index 879649452..e7643a59d 100644
--- a/mesh/dbus.h
+++ b/mesh/dbus.h
@@ -22,7 +22,7 @@
bool dbus_init(struct l_dbus *dbus);
struct l_dbus *dbus_get_bus(void);
-bool dbus_append_byte_array(struct l_dbus_message_builder *builder,
+void dbus_append_byte_array(struct l_dbus_message_builder *builder,
const uint8_t *data, int len);
void dbus_append_dict_entry_basic(struct l_dbus_message_builder *builder,
const char *key, const char *signature,
diff --git a/mesh/model.c b/mesh/model.c
index e4a7ba94e..b605d0148 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -249,10 +249,9 @@ static void config_update_model_pub_period(struct mesh_node *node,
&period);
l_dbus_message_builder_leave_array(builder);
- if (l_dbus_message_builder_finalize(builder))
- l_dbus_send(dbus, msg);
-
+ l_dbus_message_builder_finalize(builder);
l_dbus_message_builder_destroy(builder);
+ l_dbus_send(dbus, msg);
}
static void append_dict_uint16_array(struct l_dbus_message_builder *builder,
@@ -291,10 +290,9 @@ static void config_update_model_bindings(struct mesh_node *node,
append_dict_uint16_array(builder, mod->bindings, "Bindings");
l_dbus_message_builder_leave_array(builder);
- if (l_dbus_message_builder_finalize(builder))
- l_dbus_send(dbus, msg);
-
+ l_dbus_message_builder_finalize(builder);
l_dbus_message_builder_destroy(builder);
+ l_dbus_send(dbus, msg);
}
static void forward_model(void *a, void *b)
@@ -714,28 +712,15 @@ static void send_msg_rcvd(struct mesh_node *node, uint8_t ele_idx, bool is_sub,
builder = l_dbus_message_builder_new(msg);
- if (!l_dbus_message_builder_append_basic(builder, 'q', &src))
- goto error;
-
- if (!l_dbus_message_builder_append_basic(builder, 'q', &key_idx))
- goto error;
+ l_dbus_message_builder_append_basic(builder, 'q', &src);
+ l_dbus_message_builder_append_basic(builder, 'q', &key_idx);
+ l_dbus_message_builder_append_basic(builder, 'b', &is_sub);
- if (!l_dbus_message_builder_append_basic(builder, 'b', &is_sub))
- goto error;
-
- if (!dbus_append_byte_array(builder, data, size))
- goto error;
-
- if (!l_dbus_message_builder_finalize(builder))
- goto error;
+ dbus_append_byte_array(builder, data, size);
+ l_dbus_message_builder_finalize(builder);
l_dbus_message_builder_destroy(builder);
l_dbus_send(dbus, msg);
- return;
-
-error:
- l_dbus_message_builder_destroy(builder);
- l_dbus_message_unref(msg);
}
bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t seq0,
--
2.21.0
Applied
On Thu, 2019-07-04 at 00:40 -0700, Inga Stotland wrote:
> This removes checks for the return values of l_dbus_message...()
> calls in the few places where we can rely on ell to handle error
> cases gracefully.
> ---
> mesh/dbus.c | 20 ++++++++++----------
> mesh/dbus.h | 2 +-
> mesh/model.c | 33 +++++++++------------------------
> 3 files changed, 20 insertions(+), 35 deletions(-)
>
> diff --git a/mesh/dbus.c b/mesh/dbus.c
> index 2b700a1ad..6b9694ab7 100644
> --- a/mesh/dbus.c
> +++ b/mesh/dbus.c
> @@ -113,29 +113,29 @@ bool dbus_match_interface(struct
> l_dbus_message_iter *interfaces,
> return false;
> }
>
> -bool dbus_append_byte_array(struct l_dbus_message_builder *builder,
> +void dbus_append_byte_array(struct l_dbus_message_builder *builder,
> const uint8_t *data,
> int len)
> {
> int i;
>
> - if (!l_dbus_message_builder_enter_array(builder, "y"))
> - return false;
> + if (!builder)
> + return;
>
> - for (i = 0; i < len; i++)
> - if (!l_dbus_message_builder_append_basic(builder, 'y',
> - data + i))
> - return false;
> + l_dbus_message_builder_enter_array(builder, "y");
>
> - if (!l_dbus_message_builder_leave_array(builder))
> - return false;
> + for (i = 0; i < len; i++)
> + l_dbus_message_builder_append_basic(builder, 'y', data
> + i);
>
> - return true;
> + l_dbus_message_builder_leave_array(builder);
> }
>
> void dbus_append_dict_entry_basic(struct l_dbus_message_builder
> *builder,
> const char *key, const char
> *signature,
> const void *data)
> {
> + if (!builder)
> + return;
> +
> l_dbus_message_builder_enter_dict(builder, "sv");
> l_dbus_message_builder_append_basic(builder, 's', key);
> l_dbus_message_builder_enter_variant(builder, signature);
> diff --git a/mesh/dbus.h b/mesh/dbus.h
> index 879649452..e7643a59d 100644
> --- a/mesh/dbus.h
> +++ b/mesh/dbus.h
> @@ -22,7 +22,7 @@
>
> bool dbus_init(struct l_dbus *dbus);
> struct l_dbus *dbus_get_bus(void);
> -bool dbus_append_byte_array(struct l_dbus_message_builder *builder,
> +void dbus_append_byte_array(struct l_dbus_message_builder *builder,
> const uint8_t *data,
> int len);
> void dbus_append_dict_entry_basic(struct l_dbus_message_builder
> *builder,
> const char *key, const char
> *signature,
> diff --git a/mesh/model.c b/mesh/model.c
> index e4a7ba94e..b605d0148 100644
> --- a/mesh/model.c
> +++ b/mesh/model.c
> @@ -249,10 +249,9 @@ static void
> config_update_model_pub_period(struct mesh_node *node,
> &period
> );
>
> l_dbus_message_builder_leave_array(builder);
> - if (l_dbus_message_builder_finalize(builder))
> - l_dbus_send(dbus, msg);
> -
> + l_dbus_message_builder_finalize(builder);
> l_dbus_message_builder_destroy(builder);
> + l_dbus_send(dbus, msg);
> }
>
> static void append_dict_uint16_array(struct l_dbus_message_builder
> *builder,
> @@ -291,10 +290,9 @@ static void config_update_model_bindings(struct
> mesh_node *node,
> append_dict_uint16_array(builder, mod->bindings, "Bindings");
>
> l_dbus_message_builder_leave_array(builder);
> - if (l_dbus_message_builder_finalize(builder))
> - l_dbus_send(dbus, msg);
> -
> + l_dbus_message_builder_finalize(builder);
> l_dbus_message_builder_destroy(builder);
> + l_dbus_send(dbus, msg);
> }
>
> static void forward_model(void *a, void *b)
> @@ -714,28 +712,15 @@ static void send_msg_rcvd(struct mesh_node
> *node, uint8_t ele_idx, bool is_sub,
>
> builder = l_dbus_message_builder_new(msg);
>
> - if (!l_dbus_message_builder_append_basic(builder, 'q', &src))
> - goto error;
> -
> - if (!l_dbus_message_builder_append_basic(builder, 'q',
> &key_idx))
> - goto error;
> + l_dbus_message_builder_append_basic(builder, 'q', &src);
> + l_dbus_message_builder_append_basic(builder, 'q', &key_idx);
> + l_dbus_message_builder_append_basic(builder, 'b', &is_sub);
>
> - if (!l_dbus_message_builder_append_basic(builder, 'b',
> &is_sub))
> - goto error;
> -
> - if (!dbus_append_byte_array(builder, data, size))
> - goto error;
> -
> - if (!l_dbus_message_builder_finalize(builder))
> - goto error;
> + dbus_append_byte_array(builder, data, size);
>
> + l_dbus_message_builder_finalize(builder);
> l_dbus_message_builder_destroy(builder);
> l_dbus_send(dbus, msg);
> - return;
> -
> -error:
> - l_dbus_message_builder_destroy(builder);
> - l_dbus_message_unref(msg);
> }
>
> bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t
> seq0,