From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Chase Douglas <chasedouglas@gmail.com>
Cc: Henrik Rydberg <rydberg@euromail.se>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] Input: Add EVIOC mechanism for MT slots
Date: Sun, 5 Feb 2012 23:25:35 -0800 [thread overview]
Message-ID: <20120206072535.GB14139@core.coreip.homeip.net> (raw)
In-Reply-To: <4F2F08CD.2010806@gmail.com>
On Sun, Feb 05, 2012 at 11:55:09PM +0100, Chase Douglas wrote:
> On 02/05/2012 08:40 PM, Henrik Rydberg wrote:
> >>> Besides leaving a possible giant stack crash in your code, it assumes
> >>> memory is somehow magically allocated. Not good practise in low-level
> >>> programming. You wouldn't use a template this way, would you?
> >>
> >> No, which is why I think this interface is bad. I should be able to
> >> dynamically set the size of the array, but it's not possible with this
> >> interface.
> >
> > It is possible (using num_slots == 0 or creating your own struct), but
> > not ideal, granted. The patch serves the purpose of definining the
> > binary interface, the rest is up to userland.
> >
> >> I think the implementation is fine in terms of how the plumbing works. I
> >> just don't think this macro should be included. Make the user create the
> >> struct themselves:
> >>
> >> In linux/input.h:
> >>
> >> struct input_mt_request {
> >> __u32 code;
> >> __s32 values[];
> >> };
> >
> > The above (the first) version is not ideal either, since it cannot be
> > used as it is.
> >
> >> It could be argued that we should leave the macro around for people who
> >> want to statically define the size of the request, but I think that is
> >> leading them down the wrong path. It's easier, but it will lead to
> >> broken code if you pick the wrong size.
> >
> > Rather than creating both a suboptimal static and a suboptimal dynamic
> > version, removing the struct altogether is tempting. All that is
> > really needed is a clear definition of the binary interface. The rest
> > can easily be set up in userland, using whatever method is preferred.
>
> I'm normally not a fan of static functions in header files, but maybe it
> would be a good solution here:
>
> struct input_mt_request {
> __u32 code;
> __s32 values[];
> };
>
> static struct input_mt_request *
> linux_input_mt_request_alloc(int num_slots) {
> return (struct input_mt_request *)malloc(
> sizeof(__u32) + num_slots * sizeof(__s32));
> }
Gah, can we please leave it to userspace programs to define and allocate
the structure as it makes most sense for them. As far as kernel goes we
just want to document that we'll need a u32 and a place to put N s32s.
How they are allocated we do not care at all. It could be on stack
(which does not have the same limits as kernel stack) or in the heap.
Thanks.
--
Dmitry
prev parent reply other threads:[~2012-02-06 7:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-31 19:00 Henrik Rydberg
2012-02-03 0:05 ` Chase Douglas
2012-02-03 7:27 ` Henrik Rydberg
2012-02-04 18:21 ` Chase Douglas
2012-02-05 7:59 ` Henrik Rydberg
2012-02-05 17:13 ` Chase Douglas
2012-02-05 19:40 ` Henrik Rydberg
2012-02-05 22:55 ` Chase Douglas
2012-02-06 7:25 ` Dmitry Torokhov [this message]
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=20120206072535.GB14139@core.coreip.homeip.net \
--to=dmitry.torokhov@gmail.com \
--cc=chasedouglas@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rydberg@euromail.se \
/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
all inboxes | Powered by JetHome®