public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org, Hans Verkuil <hansverk@cisco.com>
Subject: Re: [PATCHv5 01/12] media: add 'index' to struct media_v2_pad
Date: Wed, 11 Jul 2018 14:33:47 +0300	[thread overview]
Message-ID: <2727885.HQxqLs6WZl@avalon> (raw)
In-Reply-To: <360b9ee9-8e29-1c34-0887-182f5c91be38@xs4all.nl>

Hi Hans,

On Monday, 9 July 2018 16:40:51 EEST Hans Verkuil wrote:
> On 09/07/18 14:55, Laurent Pinchart wrote:
> > On Friday, 29 June 2018 14:43:20 EEST Hans Verkuil wrote:
> >> From: Hans Verkuil <hansverk@cisco.com>
> >> 
> >> The v2 pad structure never exposed the pad index, which made it
> >> impossible
> >> to call the MEDIA_IOC_SETUP_LINK ioctl, which needs that information.
> >> 
> >> It is really trivial to just expose this information, so implement this.
> >> 
> >> Signed-off-by: Hans Verkuil <hansverk@cisco.com>
> >> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> >> ---
> >> 
> >>  drivers/media/media-device.c |  1 +
> >>  include/uapi/linux/media.h   | 12 +++++++++++-
> >>  2 files changed, 12 insertions(+), 1 deletion(-)
> >> 
> >> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> >> index 47bb2254fbfd..047d38372a27 100644
> >> --- a/drivers/media/media-device.c
> >> +++ b/drivers/media/media-device.c
> >> @@ -331,6 +331,7 @@ static long media_device_get_topology(struct
> >> media_device *mdev, void *arg)
> >>  		kpad.id = pad->graph_obj.id;
> >>  		kpad.entity_id = pad->entity->graph_obj.id;
> >>  		kpad.flags = pad->flags;
> >> +		kpad.index = pad->index;
> >> 
> >>  		if (copy_to_user(upad, &kpad, sizeof(kpad)))
> >>  			ret = -EFAULT;
> >> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> >> index 86c7dcc9cba3..f6338bd57929 100644
> >> --- a/include/uapi/linux/media.h
> >> +++ b/include/uapi/linux/media.h
> >> @@ -305,11 +305,21 @@ struct media_v2_interface {
> >>  	};
> >>  } __attribute__ ((packed));
> >> 
> >> +/*
> >> + * Appeared in 4.19.0.
> >> + *
> >> + * The media_version argument comes from the media_version field in
> >> + * struct media_device_info.
> >> + */
> >> +#define MEDIA_V2_PAD_HAS_INDEX(media_version) \
> >> +	((media_version) >= ((4 << 16) | (19 << 8) | 0))
> > 
> > I agree that we need tn index field, but I don't think we need to care
> > about backward compatibility. The lack of an index field makes it clear
> > that the API has never been properly used, as it was impossible to do so.
> 
> We do need to care: there is no reason why a v4l2 application can't be used
> on an older kernel. Most v4l2 applications copy the V4L2 headers to the
> application (in fact, that's what v4l-utils does) and so they need to know
> if a field is actually filled in by whatever kernel is used. In most cases
> they can just check against 0, but that happens to be a valid index :-(
> 
> So this is really needed. Same for the flags field.

You're right. I was thinking we could detect this on the kernel side by 
checking the ioctl argument size if we added the index field to the 
media_v2_pad structure instead of replacing one of the reserved fields, but 
media_v2_pad is not passed directly to the G_TOPOLOGY ioctl, so that won't 
help.

I wonder whether we shouldn't just define

#define MEDIA_V2_IS_BROKEN(media_version) \
	((media_version) < ((4 << 16) | (19 << 8) | 0))

as in practice applications should really avoid the G_TOPOLOGY ioctl without 
this patch series. Having multiple version-based macros to check for features 
won't be very helpful, and could be counter-productive as applications might 
incorrectly decide to still use the API to retrieve some information when they 
should really avoid it.

And, while at it, should we use KERNEL_VERSION() instead of hardcoding it ?

#define MEDIA_V2_IS_BROKEN(media_version) \
	((media_version) < KERNEL_VERSION(4, 19, 0))

Still thinking out loud, the fact that we can't change the size of the 
structures pointed to by media_v2_topology bothers me. We could add a version 
field to media_v2_topology that would be set by applications to tell the 
kernel which version of the API they expect. On the other hand, maybe we'll 
just do a media_v3_topology when the need arises...

(And I still really don't like the use of media_v2_link to describe the 
association between an entity and an interface, I think a media_v2_association 
structure would have been cleaner :-().

> >>  struct media_v2_pad {
> >>  	__u32 id;
> >>  	__u32 entity_id;
> >>  	__u32 flags;
> >> -	__u32 reserved[5];
> >> +	__u32 index;
> >> +	__u32 reserved[4];
> >>  } __attribute__ ((packed));
> >>  
> >>  struct media_v2_link {

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2018-07-11 11:37 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-29 11:43 [PATCHv5 00/12] media/mc: fix inconsistencies Hans Verkuil
2018-06-29 11:43 ` [PATCHv5 01/12] media: add 'index' to struct media_v2_pad Hans Verkuil
2018-07-09 12:55   ` Laurent Pinchart
2018-07-09 13:40     ` Hans Verkuil
2018-07-11 11:33       ` Laurent Pinchart [this message]
2018-07-11 11:45         ` Hans Verkuil
2018-08-03 12:34         ` Sakari Ailus
2018-08-03 14:47           ` Mauro Carvalho Chehab
2018-06-29 11:43 ` [PATCHv5 02/12] media-ioc-g-topology.rst: document new 'index' field Hans Verkuil
2018-07-09 12:57   ` Laurent Pinchart
2018-06-29 11:43 ` [PATCHv5 03/12] media: add flags field to struct media_v2_entity Hans Verkuil
2018-07-09 12:58   ` Laurent Pinchart
2018-06-29 11:43 ` [PATCHv5 04/12] media-ioc-g-topology.rst: document new 'flags' field Hans Verkuil
2018-06-29 11:43 ` [PATCHv5 05/12] media: rename MEDIA_ENT_F_DTV_DECODER to MEDIA_ENT_F_DV_DECODER Hans Verkuil
2018-06-29 17:40   ` Ezequiel Garcia
2018-07-09 13:00     ` Laurent Pinchart
2018-07-09 13:42       ` Hans Verkuil
2018-07-11 11:36         ` Laurent Pinchart
2018-06-29 11:43 ` [PATCHv5 06/12] media.h: add MEDIA_ENT_F_DV_ENCODER Hans Verkuil
2018-07-09 13:02   ` Laurent Pinchart
2018-06-29 11:43 ` [PATCHv5 07/12] media.h: reorder video en/decoder functions Hans Verkuil
2018-07-09 13:02   ` Laurent Pinchart
2018-06-29 11:43 ` [PATCHv5 08/12] ad9389b/adv7511: set proper media entity function Hans Verkuil
2018-07-09 13:04   ` Laurent Pinchart
2018-07-09 13:44     ` Hans Verkuil
2018-06-29 11:43 ` [PATCHv5 09/12] adv7180/tvp514x/tvp7002: fix " Hans Verkuil
2018-07-09 13:04   ` Laurent Pinchart
2018-06-29 11:43 ` [PATCHv5 10/12] media/i2c: add missing entity functions Hans Verkuil
2018-07-09 13:05   ` Laurent Pinchart
2018-06-29 11:43 ` [PATCHv5 11/12] media-ioc-enum-links.rst: improve pad index description Hans Verkuil
2018-07-09 13:10   ` Laurent Pinchart
2018-07-09 13:47     ` Hans Verkuil
2018-06-29 11:43 ` [PATCHv5 12/12] media-ioc-enum-entities.rst/-g-topology.rst: clarify ID/name usage Hans Verkuil
2018-07-09 13:12   ` Laurent Pinchart

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=2727885.HQxqLs6WZl@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=hansverk@cisco.com \
    --cc=hverkuil@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox