linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: Hans Verkuil <hansverk@cisco.com>
Cc: Prabhakar Lad <prabhakar.csengg@gmail.com>,
	LMML <linux-media@vger.kernel.org>,
	Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [PATCH] v4l2-compliance: fix function pointer prototype
Date: Tue, 01 Apr 2014 16:42:29 +0200	[thread overview]
Message-ID: <533AD055.2040700@xs4all.nl> (raw)
In-Reply-To: <533ACC78.8000102@cisco.com>

On 04/01/14 16:26, Hans Verkuil wrote:
> 
> 
> On 04/01/14 16:06, Prabhakar Lad wrote:
>> Hi Hans,
>>
>> On Tue, Apr 1, 2014 at 7:20 PM, Hans Verkuil <hansverk@cisco.com> wrote:
>>> Hi Prabhakar,
>>>
>>> On 04/01/14 15:45, Lad, Prabhakar wrote:
>>>> From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>
>>>>
>>>> There was a conflict between the mmap function pointer prototype of
>>>> struct v4l_fd and the actual function used. Make sure it is in sync
>>>> with the prototype of v4l2_mmap.
>>>
>>> The prototype of v4l2_mmap uses int64_t, so I don't understand this
>>> patch.
>>>
>> Actual prototype of mmap is,
>>
>>   void *mmap(void *addr, size_t length, int prot, int flags, int fd,
>> off_t offset);
>>
>> But where as the prototype in v4l_fd mmap the last parameter type is int64_t
>> but that should have been off_t and same applies with test_mmap().
> 
> The problem is that v4l2_mmap (in lib/include/libv4l2.h) uses int64_t.
> So the function pointer uses int64_t as well as does test_mmap.
> 
> I don't see how the current v4l-utils tree can cause a compile error.
> 
> For the record, I know you can't assign mmap to fd->mmap, you would
> have to make a wrapper. Unfortunately mmap and v4l2_mmap do not have
> the same prototype and I had to pick one (I'm not sure why they don't
> use the same prototype).
> 
> Most applications would typically have to use v4l2_mmap, so I went with
> that one.
> 

I missed that mmap is assigned to v4l_fd_init(). Since mmap and v4l2_mmap
have different prototypes the only solution is to make a wrapper.

Does this work?

diff --git a/utils/v4l2-compliance/v4l-helpers.h b/utils/v4l2-compliance/v4l-helpers.h
index 48ea602..e718a24 100644
--- a/utils/v4l2-compliance/v4l-helpers.h
+++ b/utils/v4l2-compliance/v4l-helpers.h
@@ -14,11 +14,21 @@ struct v4l_fd {
 	int (*munmap)(void *addr, size_t length);
 };
 
+/*
+ * mmap has a different prototype compared to v4l2_mmap. Because of
+ * this we have to make a wrapper for it.
+ */
+static inline void *v4l_fd_mmap(void *addr, size_t length, int prot, int flags,
+		                      int fd, int64_t offset)
+{
+	return mmap(addr, length, prot, flags, fd, offset);
+}
+
 static inline void v4l_fd_init(struct v4l_fd *f, int fd)
 {
 	f->fd = fd;
 	f->ioctl = ioctl;
-	f->mmap = mmap;
+	f->mmap = v4l_fd_mmap;
 	f->munmap = munmap;
 }
 

On a 64-bit system the types are the same, it's only on a 32-bit system that
this will fail.

Regards,

	Hans

  reply	other threads:[~2014-04-01 14:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-01 13:45 [PATCH] v4l2-compliance: fix function pointer prototype Lad, Prabhakar
2014-04-01 13:50 ` Hans Verkuil
2014-04-01 14:06   ` Prabhakar Lad
2014-04-01 14:26     ` Hans Verkuil
2014-04-01 14:42       ` Hans Verkuil [this message]
2014-04-01 14:48         ` Prabhakar Lad

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=533AD055.2040700@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=hans.verkuil@cisco.com \
    --cc=hansverk@cisco.com \
    --cc=linux-media@vger.kernel.org \
    --cc=prabhakar.csengg@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).