This is a preparation patch thats add kdbus_meta_memdup() to memdup a metadata object. This is useful to connections with a KDBUS_HELLO_CACHE_META flag.
Signed-off-by: Djalal Harouni <tix...@opendz.org> --- metadata.c | 27 +++++++++++++++++++++++++++ metadata.h | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/metadata.c b/metadata.c index 0db5392..6516402 100644 --- a/metadata.c +++ b/metadata.c @@ -70,6 +70,33 @@ void kdbus_meta_free(struct kdbus_meta *meta) kfree(meta); } +/** + * kdbus_meta_memdup() - duplicate metadata object + * + * @src: metadata to duplicate + * @meta: New metadata object + * + * Return: 0 on success, negative errno on failure. + */ +int kdbus_meta_memdup(struct kdbus_meta *src, struct kdbus_meta **meta) +{ + struct kdbus_meta *m; + + m = kmemdup(src, sizeof(*m), GFP_KERNEL); + if (!m) + return -ENOMEM; + + m->data = kmemdup(src->data, src->allocated_size, GFP_KERNEL); + if (!m->data) { + kfree(m); + return -ENOMEM; + } + + *meta = m; + + return 0; +} + static struct kdbus_item * kdbus_meta_append_item(struct kdbus_meta *meta, size_t extra_size) { diff --git a/metadata.h b/metadata.h index 77b7303..766dade 100644 --- a/metadata.h +++ b/metadata.h @@ -16,7 +16,7 @@ /** * struct kdbus_meta - metadata buffer * @attached: Flags for already attached data - * @domain: Domain the metadata belongs to + * @domain: Domain the metadata belongs to * @data: Allocated buffer * @size: Number of bytes used * @allocated_size: Size of buffer @@ -35,6 +35,7 @@ struct kdbus_meta { struct kdbus_conn; int kdbus_meta_new(struct kdbus_meta **meta); +int kdbus_meta_memdup(struct kdbus_meta *src, struct kdbus_meta **meta); int kdbus_meta_append_data(struct kdbus_meta *meta, u64 type, const void *buf, size_t len); int kdbus_meta_append(struct kdbus_meta *meta, -- 1.9.3 _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel