From: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
To: hverkuil-cisco@xs4all.nl
Cc: linux-media@vger.kernel.org
Subject: Re: [RFCv5 PATCH 3/4] media: add functions to add properties to objects
Date: Thu, 13 Dec 2018 15:30:29 -0200 [thread overview]
Message-ID: <20181213153029.29b35064@coco.lan> (raw)
In-Reply-To: <20181213134113.15247-4-hverkuil-cisco@xs4all.nl>
Em Thu, 13 Dec 2018 14:41:12 +0100
hverkuil-cisco@xs4all.nl escreveu:
> From: Hans Verkuil <hverkuil-cisco@xs4all.nl>
>
> Add functions to add properties to entities, pads and other
> properties. This can be extended to include interfaces and links
> in the future when needed.
>
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> ---
> drivers/media/media-entity.c | 64 +++++++++
> include/media/media-entity.h | 264 +++++++++++++++++++++++++++++++++++
> 2 files changed, 328 insertions(+)
>
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 62c4d5b4d33f..cdb35bc8e9a0 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -251,6 +251,70 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
> }
> EXPORT_SYMBOL_GPL(media_entity_pads_init);
>
> +static struct media_prop *media_create_prop(struct media_gobj *owner, u32 type,
> + const char *name, const void *ptr,
> + u32 payload_size)
> +{
> + struct media_prop *prop = kzalloc(sizeof(*prop) + payload_size,
> + GFP_KERNEL);
> +
> + if (!prop)
> + return ERR_PTR(-ENOMEM);
> + prop->type = type;
> + strscpy(prop->name, name, sizeof(prop->name));
> + if (owner->mdev)
> + media_gobj_create(owner->mdev, MEDIA_GRAPH_PROP,
> + &prop->graph_obj);
> + prop->owner = owner;
> + prop->payload_size = payload_size;
> + if (payload_size && ptr)
> + memcpy(prop->payload, ptr, payload_size);
> + INIT_LIST_HEAD(&prop->props);
> + return prop;
> +}
> +
> +struct media_prop *media_entity_add_prop(struct media_entity *ent, u32 type,
> + const char *name, const void *ptr,
> + u32 payload_size)
> +{
> + struct media_prop *prop;
> +
> + if (!ent->inited)
> + media_entity_init(ent);
> + prop = media_create_prop(&ent->graph_obj, type,
> + name, ptr, payload_size);
> + if (!IS_ERR(prop))
> + list_add_tail(&prop->list, &ent->props);
> + return prop;
> +}
> +EXPORT_SYMBOL_GPL(media_entity_add_prop);
> +
> +struct media_prop *media_pad_add_prop(struct media_pad *pad, u32 type,
> + const char *name, const void *ptr,
> + u32 payload_size)
> +{
> + struct media_prop *prop = media_create_prop(&pad->graph_obj, type,
> + name, ptr, payload_size);
> +
> + if (!IS_ERR(prop))
> + list_add_tail(&prop->list, &pad->props);
> + return prop;
> +}
> +EXPORT_SYMBOL_GPL(media_pad_add_prop);
> +
> +struct media_prop *media_prop_add_prop(struct media_prop *prop, u32 type,
> + const char *name, const void *ptr,
> + u32 payload_size)
> +{
> + struct media_prop *subprop = media_create_prop(&prop->graph_obj, type,
> + name, ptr, payload_size);
> +
> + if (!IS_ERR(subprop))
> + list_add_tail(&subprop->list, &prop->props);
> + return subprop;
> +}
> +EXPORT_SYMBOL_GPL(media_prop_add_prop);
> +
> /* -----------------------------------------------------------------------------
> * Graph traversal
> */
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 5d05ebf712d0..695acfd3fe9c 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -833,6 +833,270 @@ int media_create_pad_links(const struct media_device *mdev,
>
> void __media_entity_remove_links(struct media_entity *entity);
>
> +/**
> + * media_entity_add_prop() - Add property to entity
> + *
> + * @entity: entity where to add the property
> + * @type: property type
> + * @name: property name
> + * @ptr: property pointer to payload
> + * @payload_size: property payload size
> + *
> + * Returns the new property on success, or an error pointer on failure.
> + */
> +struct media_prop *media_entity_add_prop(struct media_entity *ent, u32 type,
> + const char *name, const void *ptr,
> + u32 payload_size);
> +
> +/**
> + * media_pad_add_prop() - Add property to pad
> + *
> + * @pad: pad where to add the property
> + * @type: property type
> + * @name: property name
> + * @ptr: property pointer to payload
> + * @payload_size: property payload size
> + *
> + * Returns the new property on success, or an error pointer on failure.
> + */
> +struct media_prop *media_pad_add_prop(struct media_pad *pad, u32 type,
> + const char *name, const void *ptr,
> + u32 payload_size);
> +
> +/**
> + * media_prop() - Add sub-property to property
> + *
> + * @prop: property where to add the sub-property
> + * @type: sub-property type
> + * @name: sub-property name
> + * @ptr: sub-property pointer to payload
> + * @payload_size: sub-property payload size
> + *
> + * Returns the new property on success, or an error pointer on failure.
> + */
> +struct media_prop *media_prop_add_prop(struct media_prop *prop, u32 type,
> + const char *name, const void *ptr,
> + u32 payload_size);
> +
> +/**
> + * media_entity_add_prop_group() - Add group property to entity
> + *
> + * @entity: entity where to add the property
> + * @name: property name
> + *
> + * Returns the new property on success, or an error pointer on failure.
> + */
> +static inline struct media_prop *
> +media_entity_add_prop_group(struct media_entity *entity, const char *name)
> +{
> + return media_entity_add_prop(entity, MEDIA_PROP_TYPE_GROUP,
> + name, NULL, 0);
> +}
Hmm... group is just a string? On my past comments for patches 1/4 and 2/4
I assumed it would be an u32 array :-)
That's btw why I asked you to add some documentation. That would avoid
reviewers of guessing some things ;-)
Why are you using zero for the payload? At patch 1/4, you said that
only u64 and s64 would have payload_size == 0:
+ * @payload_size: Property payload size, 0 for U64/S64
One would infer that, for all other types, payload_size would be
a non-zero value.
> +
> +/**
> + * media_entity_add_prop_u64() - Add u64 property to entity
> + *
> + * @entity: entity where to add the property
> + * @name: property name
> + * @val: property value
> + *
> + * Returns 0 on success, or an error on failure.
> + */
> +static inline int media_entity_add_prop_u64(struct media_entity *entity,
> + const char *name, u64 val)
> +{
> + struct media_prop *prop =
> + media_entity_add_prop(entity, MEDIA_PROP_TYPE_U64,
> + name, &val, sizeof(val));
> +
> + return PTR_ERR_OR_ZERO(prop);
> +}
> +
> +/**
> + * media_entity_add_prop_s64() - Add s64 property to entity
> + *
> + * @entity: entity where to add the property
> + * @name: property name
> + * @val: property value
> + *
> + * Returns 0 on success, or an error on failure.
> + */
> +static inline int media_entity_add_prop_s64(struct media_entity *entity,
> + const char *name, s64 val)
> +{
> + struct media_prop *prop =
> + media_entity_add_prop(entity, MEDIA_PROP_TYPE_S64,
> + name, &val, sizeof(val));
> +
> + return PTR_ERR_OR_ZERO(prop);
> +}
> +
> +/**
> + * media_entity_add_prop_string() - Add string property to entity
> + *
> + * @entity: entity where to add the property
> + * @name: property name
> + * @string: property string value
> + *
> + * Returns 0 on success, or an error on failure.
> + */
> +static inline int media_entity_add_prop_string(struct media_entity *entity,
> + const char *name,
> + const char *string)
> +{
> + struct media_prop *prop =
> + media_entity_add_prop(entity, MEDIA_PROP_TYPE_STRING,
> + name, string, strlen(string) + 1);
Ok, so, you're assuming that, for strings, payload_type will include
the ending '\0' character, and that strings are NUL-terminated.
Please document it, as we usually have NUL-terminated strings OR
LEN + string. Having both is non-trivial.
> +
> + return PTR_ERR_OR_ZERO(prop);
> +}
> +
> +/**
> + * media_pad_add_prop_group() - Add group property to pad
> + *
> + * @pad: pad where to add the property
> + * @name: property name
> + *
> + * Returns the new property on success, or an error pointer on failure.
> + */
> +static inline struct media_prop *media_pad_add_prop_group(struct media_pad *pad,
> + const char *name)
> +{
> + return media_pad_add_prop(pad, MEDIA_PROP_TYPE_GROUP,
> + name, NULL, 0);
> +}
> +
> +/**
> + * media_pad_add_prop_u64() - Add u64 property to pad
> + *
> + * @pad: pad where to add the property
> + * @name: property name
> + * @val: property value
> + *
> + * Returns 0 on success, or an error on failure.
> + */
> +static inline int media_pad_add_prop_u64(struct media_pad *pad,
> + const char *name, u64 val)
> +{
> + struct media_prop *prop =
> + media_pad_add_prop(pad, MEDIA_PROP_TYPE_U64,
> + name, &val, sizeof(val));
> +
> + return PTR_ERR_OR_ZERO(prop);
> +}
> +
> +/**
> + * media_pad_add_prop_s64() - Add s64 property to pad
> + *
> + * @pad: pad where to add the property
> + * @name: property name
> + * @val: property value
> + *
> + * Returns 0 on success, or an error on failure.
> + */
> +static inline int media_pad_add_prop_s64(struct media_pad *pad,
> + const char *name, s64 val)
> +{
> + struct media_prop *prop =
> + media_pad_add_prop(pad, MEDIA_PROP_TYPE_S64,
> + name, &val, sizeof(val));
> +
> + return PTR_ERR_OR_ZERO(prop);
> +}
> +
> +/**
> + * media_pad_add_prop_string() - Add string property to pad
> + *
> + * @pad: pad where to add the property
> + * @name: property name
> + * @string: property string value
> + *
> + * Returns 0 on success, or an error on failure.
> + */
> +static inline int media_pad_add_prop_string(struct media_pad *pad,
> + const char *name,
> + const char *string)
> +{
> + struct media_prop *prop =
> + media_pad_add_prop(pad, MEDIA_PROP_TYPE_STRING,
> + name, string, strlen(string) + 1);
> +
> + return PTR_ERR_OR_ZERO(prop);
> +}
> +
> +/**
> + * media_prop_add_prop_group() - Add group sub-property to property
> + *
> + * @prop: property where to add the sub-property
> + * @name: sub-property name
> + *
> + * Returns the new property on success, or an error pointer on failure.
> + */
> +static inline struct media_prop *
> +media_prop_add_prop_group(struct media_prop *prop, const char *name)
> +{
> + return media_prop_add_prop(prop, MEDIA_PROP_TYPE_GROUP,
> + name, NULL, 0);
> +}
> +
> +/**
> + * media_prop_add_prop_u64() - Add u64 property to property
> + *
> + * @prop: property where to add the sub-property
> + * @name: sub-property name
> + * @val: sub-property value
> + *
> + * Returns 0 on success, or an error on failure.
> + */
> +static inline int media_prop_add_prop_u64(struct media_prop *prop,
> + const char *name, u64 val)
> +{
> + struct media_prop *subprop =
> + media_prop_add_prop(prop, MEDIA_PROP_TYPE_U64,
> + name, &val, sizeof(val));
> +
> + return PTR_ERR_OR_ZERO(subprop);
> +}
> +
> +/**
> + * media_prop_add_prop_s64() - Add s64 property to property
> + *
> + * @prop: property where to add the sub-property
> + * @name: sub-property name
> + * @val: sub-property value
> + *
> + * Returns 0 on success, or an error on failure.
> + */
> +static inline int media_prop_add_prop_s64(struct media_prop *prop,
> + const char *name, s64 val)
> +{
> + struct media_prop *subprop =
> + media_prop_add_prop(prop, MEDIA_PROP_TYPE_S64,
> + name, &val, sizeof(val));
> +
> + return PTR_ERR_OR_ZERO(subprop);
> +}
> +
> +/**
> + * media_prop_add_prop_string() - Add string property to property
> + *
> + * @prop: property where to add the sub-property
> + * @name: sub-property name
> + * @string: sub-property string value
> + *
> + * Returns 0 on success, or an error on failure.
> + */
> +static inline int media_prop_add_prop_string(struct media_prop *prop,
> + const char *name,
> + const char *string)
> +{
> + struct media_prop *subprop =
> + media_prop_add_prop(prop, MEDIA_PROP_TYPE_STRING,
> + name, string, strlen(string) + 1);
> +
> + return PTR_ERR_OR_ZERO(subprop);
> +}
> +
> /**
> * media_entity_remove_links() - remove all links associated with an entity
> *
Thanks,
Mauro
next prev parent reply other threads:[~2018-12-13 17:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-13 13:41 [RFCv5 PATCH 0/4] Add properties support to the media controller hverkuil-cisco
2018-12-13 13:41 ` [RFCv5 PATCH 1/4] uapi/linux/media.h: add property support hverkuil-cisco
2018-12-13 16:41 ` Mauro Carvalho Chehab
2018-12-13 17:13 ` Hans Verkuil
2018-12-13 17:54 ` Mauro Carvalho Chehab
2018-12-13 17:17 ` Mauro Carvalho Chehab
2018-12-13 13:41 ` [RFCv5 PATCH 2/4] media controller: add properties support hverkuil-cisco
2018-12-13 17:14 ` Mauro Carvalho Chehab
2018-12-13 17:35 ` Hans Verkuil
2018-12-13 18:01 ` Mauro Carvalho Chehab
2018-12-13 13:41 ` [RFCv5 PATCH 3/4] media: add functions to add properties to objects hverkuil-cisco
2018-12-13 17:30 ` Mauro Carvalho Chehab [this message]
2018-12-13 13:41 ` [RFCv5 PATCH 4/4] vimc: add property test code hverkuil-cisco
2018-12-13 17:31 ` Mauro Carvalho Chehab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181213153029.29b35064@coco.lan \
--to=mchehab+samsung@kernel.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.