Userspace has no way of knowing the pad index for the entity that
owns the pad with the MEDIA_IOC_G_TOPOLOGY ioctl. However, various
v4l-subdev ioctls need to pass this as an argument.

Add this missing information.

Signed-off-by: Hans Verkuil <>
RFC, so no documentation yet. This works fine, but how would applications
know that media_v2_pad has been extended with a new index field? Currently
this is 0, which is a valid index.

If no one is using this API (or only for DVB devices) then we can do that.
The other alternative is to add a new pad flag MEDIA_PAD_FL_HAS_INDEX.
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index e79f72b8b858..16964d3dfb1e 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -318,6 +320,7 @@ static long media_device_get_topology(struct media_device 
       = pad->;
                kpad.entity_id = pad->entity->;
                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 b9b9446095e9..c3e7a668e122 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -375,7 +375,8 @@ struct media_v2_pad {
        __u32 id;
        __u32 entity_id;
        __u32 flags;
-       __u32 reserved[5];
+       __u16 index;
+       __u16 reserved[9];
 } __attribute__ ((packed));

 struct media_v2_link {

Reply via email to