Re: [RFCv11 PATCH 07/29] media-request: add media_request_object_find

2018-04-23 Thread Hans Verkuil
On 04/17/2018 06:36 AM, Alexandre Courbot wrote:
> On Mon, Apr 9, 2018 at 11:21 PM Hans Verkuil  wrote:
> 
>> From: Hans Verkuil 
> 
>> Add media_request_object_find to find a request object inside a
>> request based on ops and/or priv values.
> 
>> Objects of the same type (vb2 buffer, control handler) will have
>> the same ops value. And objects that refer to the same 'parent'
>> object (e.g. the v4l2_ctrl_handler that has the current driver
>> state) will have the same priv value.
> 
>> The caller has to call media_request_object_put() for the returned
>> object since this function increments the refcount.
> 
>> Signed-off-by: Hans Verkuil 
>> ---
>>   drivers/media/media-request.c | 26 ++
>>   include/media/media-request.h | 25 +
>>   2 files changed, 51 insertions(+)
> 
>> diff --git a/drivers/media/media-request.c b/drivers/media/media-request.c
>> index 02b620c81de5..415f7e31019d 100644
>> --- a/drivers/media/media-request.c
>> +++ b/drivers/media/media-request.c
>> @@ -322,6 +322,32 @@ static void media_request_object_release(struct kref
> *kref)
>>  obj->ops->release(obj);
>>   }
> 
>> +struct media_request_object *
>> +media_request_object_find(struct media_request *req,
>> + const struct media_request_object_ops *ops,
>> + void *priv)
>> +{
>> +   struct media_request_object *obj;
>> +   struct media_request_object *found = NULL;
>> +   unsigned long flags;
>> +
>> +   if (!ops && !priv)
>> +   return NULL;
>> +
>> +   spin_lock_irqsave(>lock, flags);
>> +   list_for_each_entry(obj, >objects, list) {
>> +   if ((!ops || obj->ops == ops) &&
>> +   (!priv || obj->priv == priv)) {
>> +   media_request_object_get(obj);
>> +   found = obj;
>> +   break;
>> +   }
>> +   }
>> +   spin_unlock_irqrestore(>lock, flags);
>> +   return found;
>> +}
>> +EXPORT_SYMBOL_GPL(media_request_object_find);
>> +
>>   void media_request_object_put(struct media_request_object *obj)
>>   {
>>  kref_put(>kref, media_request_object_release);
>> diff --git a/include/media/media-request.h b/include/media/media-request.h
>> index 033697d493cd..ea990c8f76bc 100644
>> --- a/include/media/media-request.h
>> +++ b/include/media/media-request.h
>> @@ -130,6 +130,23 @@ static inline void media_request_object_get(struct
> media_request_object *obj)
>>*/
>>   void media_request_object_put(struct media_request_object *obj);
> 
>> +/**
>> + * media_request_object_find - Find an object in a request
>> + *
>> + * @ops: Find an object with this ops value, may be NULL.
>> + * @priv: Find an object with this priv value, may be NULL.
>> + *
>> + * At least one of @ops and @priv must be non-NULL. If one of
>> + * these is NULL, then skip checking for that field.
>> + *
>> + * Returns NULL if not found or the object (the refcount is increased
>> + * in that case).
>> + */
>> +struct media_request_object *
>> +media_request_object_find(struct media_request *req,
>> + const struct media_request_object_ops *ops,
>> + void *priv);
> 
> Mm, that signature is weird. I don't yet know how this function is going to
> be
> called, but wouldn't priv be enough? If we look for ops, this means we are
> looking for the first object of a given class (IIUC the class/objects
> mechanism
> here), and I cannot see where we would want to do that.

This allows you to associate objects of different types with the same
priv pointer. E.g. right now only buffers objects are associated with
a vb2_queue. But what if you want to associate other objects with the vb2_queue
as well? That's what the ops is for.

This will almost certainly be needed for complex video pipelines.

If I am wrong, then this can be removed in the future.

Regards,

Hans

> 
>> +
>>   /**
>>* media_request_object_init - Initialise a media request object
>>*
>> @@ -162,6 +179,14 @@ static inline void media_request_object_put(struct
> media_request_object *obj)
>>   {
>>   }
> 
>> +static inline struct media_request_object *
>> +media_request_object_find(struct media_request *req,
>> + const struct media_request_object_ops *ops,
>> + void *priv)
>> +{
>> +   return NULL;
>> +}
>> +
>>   static inline void media_request_object_init(struct media_request_object
> *obj)
>>   {
>>  obj->ops = NULL;
>> --
>> 2.16.3



Re: [RFCv11 PATCH 07/29] media-request: add media_request_object_find

2018-04-23 Thread Hans Verkuil
On 04/12/2018 02:23 PM, Sakari Ailus wrote:
> Hi Hans,
> 
> On Mon, Apr 09, 2018 at 04:20:04PM +0200, Hans Verkuil wrote:
>> From: Hans Verkuil 
>>
>> Add media_request_object_find to find a request object inside a
>> request based on ops and/or priv values.
>>
>> Objects of the same type (vb2 buffer, control handler) will have
>> the same ops value. And objects that refer to the same 'parent'
>> object (e.g. the v4l2_ctrl_handler that has the current driver
>> state) will have the same priv value.
>>
>> The caller has to call media_request_object_put() for the returned
>> object since this function increments the refcount.
>>
>> Signed-off-by: Hans Verkuil 
>> ---
>>  drivers/media/media-request.c | 26 ++
>>  include/media/media-request.h | 25 +
>>  2 files changed, 51 insertions(+)
>>
>> diff --git a/drivers/media/media-request.c b/drivers/media/media-request.c
>> index 02b620c81de5..415f7e31019d 100644
>> --- a/drivers/media/media-request.c
>> +++ b/drivers/media/media-request.c
>> @@ -322,6 +322,32 @@ static void media_request_object_release(struct kref 
>> *kref)
>>  obj->ops->release(obj);
>>  }
>>  
>> +struct media_request_object *
>> +media_request_object_find(struct media_request *req,
>> +  const struct media_request_object_ops *ops,
>> +  void *priv)
>> +{
>> +struct media_request_object *obj;
>> +struct media_request_object *found = NULL;
>> +unsigned long flags;
>> +
>> +if (!ops && !priv)
>> +return NULL;
>> +
>> +spin_lock_irqsave(>lock, flags);
>> +list_for_each_entry(obj, >objects, list) {
>> +if ((!ops || obj->ops == ops) &&
>> +(!priv || obj->priv == priv)) {
> 
> I think I may have given the similar comment on an earlier version but I
> don't remember a reply to that at least --- is there a case where the
> object wouldn't be uniquely identified by req together with priv?
> 
> It'd be still prudent to check that ops match, but failing that check, I'd
> add WARN_ON() because it's a sign something is wrong.

Currently both ops and priv are always non-NULL, so I've made that the
requirement and call WARN_ON if either is NULL.

Regards,

Hans

> 
>> +media_request_object_get(obj);
>> +found = obj;
>> +break;
>> +}
>> +}
>> +spin_unlock_irqrestore(>lock, flags);
>> +return found;
>> +}
>> +EXPORT_SYMBOL_GPL(media_request_object_find);
>> +
>>  void media_request_object_put(struct media_request_object *obj)
>>  {
>>  kref_put(>kref, media_request_object_release);
>> diff --git a/include/media/media-request.h b/include/media/media-request.h
>> index 033697d493cd..ea990c8f76bc 100644
>> --- a/include/media/media-request.h
>> +++ b/include/media/media-request.h
>> @@ -130,6 +130,23 @@ static inline void media_request_object_get(struct 
>> media_request_object *obj)
>>   */
>>  void media_request_object_put(struct media_request_object *obj);
>>  
>> +/**
>> + * media_request_object_find - Find an object in a request
>> + *
>> + * @ops: Find an object with this ops value, may be NULL.
>> + * @priv: Find an object with this priv value, may be NULL.
>> + *
>> + * At least one of @ops and @priv must be non-NULL. If one of
>> + * these is NULL, then skip checking for that field.
>> + *
>> + * Returns NULL if not found or the object (the refcount is increased
>> + * in that case).
>> + */
>> +struct media_request_object *
>> +media_request_object_find(struct media_request *req,
>> +  const struct media_request_object_ops *ops,
>> +  void *priv);
>> +
>>  /**
>>   * media_request_object_init - Initialise a media request object
>>   *
>> @@ -162,6 +179,14 @@ static inline void media_request_object_put(struct 
>> media_request_object *obj)
>>  {
>>  }
>>  
>> +static inline struct media_request_object *
>> +media_request_object_find(struct media_request *req,
>> +  const struct media_request_object_ops *ops,
>> +  void *priv)
>> +{
>> +return NULL;
>> +}
>> +
>>  static inline void media_request_object_init(struct media_request_object 
>> *obj)
>>  {
>>  obj->ops = NULL;
> 



Re: [RFCv11 PATCH 07/29] media-request: add media_request_object_find

2018-04-16 Thread Alexandre Courbot
On Mon, Apr 9, 2018 at 11:21 PM Hans Verkuil  wrote:

> From: Hans Verkuil 

> Add media_request_object_find to find a request object inside a
> request based on ops and/or priv values.

> Objects of the same type (vb2 buffer, control handler) will have
> the same ops value. And objects that refer to the same 'parent'
> object (e.g. the v4l2_ctrl_handler that has the current driver
> state) will have the same priv value.

> The caller has to call media_request_object_put() for the returned
> object since this function increments the refcount.

> Signed-off-by: Hans Verkuil 
> ---
>   drivers/media/media-request.c | 26 ++
>   include/media/media-request.h | 25 +
>   2 files changed, 51 insertions(+)

> diff --git a/drivers/media/media-request.c b/drivers/media/media-request.c
> index 02b620c81de5..415f7e31019d 100644
> --- a/drivers/media/media-request.c
> +++ b/drivers/media/media-request.c
> @@ -322,6 +322,32 @@ static void media_request_object_release(struct kref
*kref)
>  obj->ops->release(obj);
>   }

> +struct media_request_object *
> +media_request_object_find(struct media_request *req,
> + const struct media_request_object_ops *ops,
> + void *priv)
> +{
> +   struct media_request_object *obj;
> +   struct media_request_object *found = NULL;
> +   unsigned long flags;
> +
> +   if (!ops && !priv)
> +   return NULL;
> +
> +   spin_lock_irqsave(>lock, flags);
> +   list_for_each_entry(obj, >objects, list) {
> +   if ((!ops || obj->ops == ops) &&
> +   (!priv || obj->priv == priv)) {
> +   media_request_object_get(obj);
> +   found = obj;
> +   break;
> +   }
> +   }
> +   spin_unlock_irqrestore(>lock, flags);
> +   return found;
> +}
> +EXPORT_SYMBOL_GPL(media_request_object_find);
> +
>   void media_request_object_put(struct media_request_object *obj)
>   {
>  kref_put(>kref, media_request_object_release);
> diff --git a/include/media/media-request.h b/include/media/media-request.h
> index 033697d493cd..ea990c8f76bc 100644
> --- a/include/media/media-request.h
> +++ b/include/media/media-request.h
> @@ -130,6 +130,23 @@ static inline void media_request_object_get(struct
media_request_object *obj)
>*/
>   void media_request_object_put(struct media_request_object *obj);

> +/**
> + * media_request_object_find - Find an object in a request
> + *
> + * @ops: Find an object with this ops value, may be NULL.
> + * @priv: Find an object with this priv value, may be NULL.
> + *
> + * At least one of @ops and @priv must be non-NULL. If one of
> + * these is NULL, then skip checking for that field.
> + *
> + * Returns NULL if not found or the object (the refcount is increased
> + * in that case).
> + */
> +struct media_request_object *
> +media_request_object_find(struct media_request *req,
> + const struct media_request_object_ops *ops,
> + void *priv);

Mm, that signature is weird. I don't yet know how this function is going to
be
called, but wouldn't priv be enough? If we look for ops, this means we are
looking for the first object of a given class (IIUC the class/objects
mechanism
here), and I cannot see where we would want to do that.

> +
>   /**
>* media_request_object_init - Initialise a media request object
>*
> @@ -162,6 +179,14 @@ static inline void media_request_object_put(struct
media_request_object *obj)
>   {
>   }

> +static inline struct media_request_object *
> +media_request_object_find(struct media_request *req,
> + const struct media_request_object_ops *ops,
> + void *priv)
> +{
> +   return NULL;
> +}
> +
>   static inline void media_request_object_init(struct media_request_object
*obj)
>   {
>  obj->ops = NULL;
> --
> 2.16.3


Re: [RFCv11 PATCH 07/29] media-request: add media_request_object_find

2018-04-12 Thread Sakari Ailus
Hi Hans,

On Mon, Apr 09, 2018 at 04:20:04PM +0200, Hans Verkuil wrote:
> From: Hans Verkuil 
> 
> Add media_request_object_find to find a request object inside a
> request based on ops and/or priv values.
> 
> Objects of the same type (vb2 buffer, control handler) will have
> the same ops value. And objects that refer to the same 'parent'
> object (e.g. the v4l2_ctrl_handler that has the current driver
> state) will have the same priv value.
> 
> The caller has to call media_request_object_put() for the returned
> object since this function increments the refcount.
> 
> Signed-off-by: Hans Verkuil 
> ---
>  drivers/media/media-request.c | 26 ++
>  include/media/media-request.h | 25 +
>  2 files changed, 51 insertions(+)
> 
> diff --git a/drivers/media/media-request.c b/drivers/media/media-request.c
> index 02b620c81de5..415f7e31019d 100644
> --- a/drivers/media/media-request.c
> +++ b/drivers/media/media-request.c
> @@ -322,6 +322,32 @@ static void media_request_object_release(struct kref 
> *kref)
>   obj->ops->release(obj);
>  }
>  
> +struct media_request_object *
> +media_request_object_find(struct media_request *req,
> +   const struct media_request_object_ops *ops,
> +   void *priv)
> +{
> + struct media_request_object *obj;
> + struct media_request_object *found = NULL;
> + unsigned long flags;
> +
> + if (!ops && !priv)
> + return NULL;
> +
> + spin_lock_irqsave(>lock, flags);
> + list_for_each_entry(obj, >objects, list) {
> + if ((!ops || obj->ops == ops) &&
> + (!priv || obj->priv == priv)) {

I think I may have given the similar comment on an earlier version but I
don't remember a reply to that at least --- is there a case where the
object wouldn't be uniquely identified by req together with priv?

It'd be still prudent to check that ops match, but failing that check, I'd
add WARN_ON() because it's a sign something is wrong.

> + media_request_object_get(obj);
> + found = obj;
> + break;
> + }
> + }
> + spin_unlock_irqrestore(>lock, flags);
> + return found;
> +}
> +EXPORT_SYMBOL_GPL(media_request_object_find);
> +
>  void media_request_object_put(struct media_request_object *obj)
>  {
>   kref_put(>kref, media_request_object_release);
> diff --git a/include/media/media-request.h b/include/media/media-request.h
> index 033697d493cd..ea990c8f76bc 100644
> --- a/include/media/media-request.h
> +++ b/include/media/media-request.h
> @@ -130,6 +130,23 @@ static inline void media_request_object_get(struct 
> media_request_object *obj)
>   */
>  void media_request_object_put(struct media_request_object *obj);
>  
> +/**
> + * media_request_object_find - Find an object in a request
> + *
> + * @ops: Find an object with this ops value, may be NULL.
> + * @priv: Find an object with this priv value, may be NULL.
> + *
> + * At least one of @ops and @priv must be non-NULL. If one of
> + * these is NULL, then skip checking for that field.
> + *
> + * Returns NULL if not found or the object (the refcount is increased
> + * in that case).
> + */
> +struct media_request_object *
> +media_request_object_find(struct media_request *req,
> +   const struct media_request_object_ops *ops,
> +   void *priv);
> +
>  /**
>   * media_request_object_init - Initialise a media request object
>   *
> @@ -162,6 +179,14 @@ static inline void media_request_object_put(struct 
> media_request_object *obj)
>  {
>  }
>  
> +static inline struct media_request_object *
> +media_request_object_find(struct media_request *req,
> +   const struct media_request_object_ops *ops,
> +   void *priv)
> +{
> + return NULL;
> +}
> +
>  static inline void media_request_object_init(struct media_request_object 
> *obj)
>  {
>   obj->ops = NULL;

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi


Re: [RFCv11 PATCH 07/29] media-request: add media_request_object_find

2018-04-10 Thread Hans Verkuil
On 04/10/18 13:07, Mauro Carvalho Chehab wrote:
> Em Mon,  9 Apr 2018 16:20:04 +0200
> Hans Verkuil  escreveu:
> 
>> From: Hans Verkuil 
>>
>> Add media_request_object_find to find a request object inside a
>> request based on ops and/or priv values.
>>
>> Objects of the same type (vb2 buffer, control handler) will have
>> the same ops value. And objects that refer to the same 'parent'
>> object (e.g. the v4l2_ctrl_handler that has the current driver
>> state) will have the same priv value.
>>
>> The caller has to call media_request_object_put() for the returned
>> object since this function increments the refcount.
>>
>> Signed-off-by: Hans Verkuil 
>> ---
>>  drivers/media/media-request.c | 26 ++
>>  include/media/media-request.h | 25 +
>>  2 files changed, 51 insertions(+)
>>
>> diff --git a/drivers/media/media-request.c b/drivers/media/media-request.c
>> index 02b620c81de5..415f7e31019d 100644
>> --- a/drivers/media/media-request.c
>> +++ b/drivers/media/media-request.c
>> @@ -322,6 +322,32 @@ static void media_request_object_release(struct kref 
>> *kref)
>>  obj->ops->release(obj);
>>  }
>>  
>> +struct media_request_object *
>> +media_request_object_find(struct media_request *req,
>> +  const struct media_request_object_ops *ops,
>> +  void *priv)
>> +{
>> +struct media_request_object *obj;
>> +struct media_request_object *found = NULL;
>> +unsigned long flags;
>> +
>> +if (!ops && !priv)
>> +return NULL;
>> +
>> +spin_lock_irqsave(>lock, flags);
>> +list_for_each_entry(obj, >objects, list) {
>> +if ((!ops || obj->ops == ops) &&
>> +(!priv || obj->priv == priv)) {
>> +media_request_object_get(obj);
>> +found = obj;
>> +break;
>> +}
>> +}
>> +spin_unlock_irqrestore(>lock, flags);
> 
> Huh? The spin lock were used before only to protect the req->state,
> while the mutex is the one that protects the request itself.
> 
> So, here, it should be doing mutex_lock/unlock() instead.

The mutex only serializes the actual queuing operation where you queue a
request (and will likely have to sleep etc.). The spinlock is for the the
other fields of the media_request struct.

Regards,

Hans

> 
>> +return found;
>> +}
>> +EXPORT_SYMBOL_GPL(media_request_object_find);
>> +
>>  void media_request_object_put(struct media_request_object *obj)
>>  {
>>  kref_put(>kref, media_request_object_release);
>> diff --git a/include/media/media-request.h b/include/media/media-request.h
>> index 033697d493cd..ea990c8f76bc 100644
>> --- a/include/media/media-request.h
>> +++ b/include/media/media-request.h
>> @@ -130,6 +130,23 @@ static inline void media_request_object_get(struct 
>> media_request_object *obj)
>>   */
>>  void media_request_object_put(struct media_request_object *obj);
>>  
>> +/**
>> + * media_request_object_find - Find an object in a request
>> + *
>> + * @ops: Find an object with this ops value, may be NULL.
>> + * @priv: Find an object with this priv value, may be NULL.
> 
> @req ?
> 
>> + *
>> + * At least one of @ops and @priv must be non-NULL. If one of
>> + * these is NULL, then skip checking for that field.
>> + *
>> + * Returns NULL if not found or the object (the refcount is increased
>> + * in that case).
>> + */
>> +struct media_request_object *
>> +media_request_object_find(struct media_request *req,
>> +  const struct media_request_object_ops *ops,
>> +  void *priv);
>> +
>>  /**
>>   * media_request_object_init - Initialise a media request object
>>   *
>> @@ -162,6 +179,14 @@ static inline void media_request_object_put(struct 
>> media_request_object *obj)
>>  {
>>  }
>>  
>> +static inline struct media_request_object *
>> +media_request_object_find(struct media_request *req,
>> +  const struct media_request_object_ops *ops,
>> +  void *priv)
>> +{
>> +return NULL;
>> +}
>> +
>>  static inline void media_request_object_init(struct media_request_object 
>> *obj)
>>  {
>>  obj->ops = NULL;
> 
> 
> 
> Thanks,
> Mauro
> 



Re: [RFCv11 PATCH 07/29] media-request: add media_request_object_find

2018-04-10 Thread Mauro Carvalho Chehab
Em Mon,  9 Apr 2018 16:20:04 +0200
Hans Verkuil  escreveu:

> From: Hans Verkuil 
> 
> Add media_request_object_find to find a request object inside a
> request based on ops and/or priv values.
> 
> Objects of the same type (vb2 buffer, control handler) will have
> the same ops value. And objects that refer to the same 'parent'
> object (e.g. the v4l2_ctrl_handler that has the current driver
> state) will have the same priv value.
> 
> The caller has to call media_request_object_put() for the returned
> object since this function increments the refcount.
> 
> Signed-off-by: Hans Verkuil 
> ---
>  drivers/media/media-request.c | 26 ++
>  include/media/media-request.h | 25 +
>  2 files changed, 51 insertions(+)
> 
> diff --git a/drivers/media/media-request.c b/drivers/media/media-request.c
> index 02b620c81de5..415f7e31019d 100644
> --- a/drivers/media/media-request.c
> +++ b/drivers/media/media-request.c
> @@ -322,6 +322,32 @@ static void media_request_object_release(struct kref 
> *kref)
>   obj->ops->release(obj);
>  }
>  
> +struct media_request_object *
> +media_request_object_find(struct media_request *req,
> +   const struct media_request_object_ops *ops,
> +   void *priv)
> +{
> + struct media_request_object *obj;
> + struct media_request_object *found = NULL;
> + unsigned long flags;
> +
> + if (!ops && !priv)
> + return NULL;
> +
> + spin_lock_irqsave(>lock, flags);
> + list_for_each_entry(obj, >objects, list) {
> + if ((!ops || obj->ops == ops) &&
> + (!priv || obj->priv == priv)) {
> + media_request_object_get(obj);
> + found = obj;
> + break;
> + }
> + }
> + spin_unlock_irqrestore(>lock, flags);

Huh? The spin lock were used before only to protect the req->state,
while the mutex is the one that protects the request itself.

So, here, it should be doing mutex_lock/unlock() instead.

> + return found;
> +}
> +EXPORT_SYMBOL_GPL(media_request_object_find);
> +
>  void media_request_object_put(struct media_request_object *obj)
>  {
>   kref_put(>kref, media_request_object_release);
> diff --git a/include/media/media-request.h b/include/media/media-request.h
> index 033697d493cd..ea990c8f76bc 100644
> --- a/include/media/media-request.h
> +++ b/include/media/media-request.h
> @@ -130,6 +130,23 @@ static inline void media_request_object_get(struct 
> media_request_object *obj)
>   */
>  void media_request_object_put(struct media_request_object *obj);
>  
> +/**
> + * media_request_object_find - Find an object in a request
> + *
> + * @ops: Find an object with this ops value, may be NULL.
> + * @priv: Find an object with this priv value, may be NULL.

@req ?

> + *
> + * At least one of @ops and @priv must be non-NULL. If one of
> + * these is NULL, then skip checking for that field.
> + *
> + * Returns NULL if not found or the object (the refcount is increased
> + * in that case).
> + */
> +struct media_request_object *
> +media_request_object_find(struct media_request *req,
> +   const struct media_request_object_ops *ops,
> +   void *priv);
> +
>  /**
>   * media_request_object_init - Initialise a media request object
>   *
> @@ -162,6 +179,14 @@ static inline void media_request_object_put(struct 
> media_request_object *obj)
>  {
>  }
>  
> +static inline struct media_request_object *
> +media_request_object_find(struct media_request *req,
> +   const struct media_request_object_ops *ops,
> +   void *priv)
> +{
> + return NULL;
> +}
> +
>  static inline void media_request_object_init(struct media_request_object 
> *obj)
>  {
>   obj->ops = NULL;



Thanks,
Mauro


[RFCv11 PATCH 07/29] media-request: add media_request_object_find

2018-04-09 Thread Hans Verkuil
From: Hans Verkuil 

Add media_request_object_find to find a request object inside a
request based on ops and/or priv values.

Objects of the same type (vb2 buffer, control handler) will have
the same ops value. And objects that refer to the same 'parent'
object (e.g. the v4l2_ctrl_handler that has the current driver
state) will have the same priv value.

The caller has to call media_request_object_put() for the returned
object since this function increments the refcount.

Signed-off-by: Hans Verkuil 
---
 drivers/media/media-request.c | 26 ++
 include/media/media-request.h | 25 +
 2 files changed, 51 insertions(+)

diff --git a/drivers/media/media-request.c b/drivers/media/media-request.c
index 02b620c81de5..415f7e31019d 100644
--- a/drivers/media/media-request.c
+++ b/drivers/media/media-request.c
@@ -322,6 +322,32 @@ static void media_request_object_release(struct kref *kref)
obj->ops->release(obj);
 }
 
+struct media_request_object *
+media_request_object_find(struct media_request *req,
+ const struct media_request_object_ops *ops,
+ void *priv)
+{
+   struct media_request_object *obj;
+   struct media_request_object *found = NULL;
+   unsigned long flags;
+
+   if (!ops && !priv)
+   return NULL;
+
+   spin_lock_irqsave(>lock, flags);
+   list_for_each_entry(obj, >objects, list) {
+   if ((!ops || obj->ops == ops) &&
+   (!priv || obj->priv == priv)) {
+   media_request_object_get(obj);
+   found = obj;
+   break;
+   }
+   }
+   spin_unlock_irqrestore(>lock, flags);
+   return found;
+}
+EXPORT_SYMBOL_GPL(media_request_object_find);
+
 void media_request_object_put(struct media_request_object *obj)
 {
kref_put(>kref, media_request_object_release);
diff --git a/include/media/media-request.h b/include/media/media-request.h
index 033697d493cd..ea990c8f76bc 100644
--- a/include/media/media-request.h
+++ b/include/media/media-request.h
@@ -130,6 +130,23 @@ static inline void media_request_object_get(struct 
media_request_object *obj)
  */
 void media_request_object_put(struct media_request_object *obj);
 
+/**
+ * media_request_object_find - Find an object in a request
+ *
+ * @ops: Find an object with this ops value, may be NULL.
+ * @priv: Find an object with this priv value, may be NULL.
+ *
+ * At least one of @ops and @priv must be non-NULL. If one of
+ * these is NULL, then skip checking for that field.
+ *
+ * Returns NULL if not found or the object (the refcount is increased
+ * in that case).
+ */
+struct media_request_object *
+media_request_object_find(struct media_request *req,
+ const struct media_request_object_ops *ops,
+ void *priv);
+
 /**
  * media_request_object_init - Initialise a media request object
  *
@@ -162,6 +179,14 @@ static inline void media_request_object_put(struct 
media_request_object *obj)
 {
 }
 
+static inline struct media_request_object *
+media_request_object_find(struct media_request *req,
+ const struct media_request_object_ops *ops,
+ void *priv)
+{
+   return NULL;
+}
+
 static inline void media_request_object_init(struct media_request_object *obj)
 {
obj->ops = NULL;
-- 
2.16.3