From: Greg KH <greg@kroah.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: mamurph@cs.clemson.edu, linux-kernel@vger.kernel.org,
linux-input@vger.kernel.org, linux-usb@vger.kernel.org,
oliver@neukum.org, fweisbec@gmail.com,
torvalds@linux-foundation.org
Subject: Re: PATCH [1/3] drivers/input/xpad.c: Improve Xbox 360 wireless support and add sysfs interface
Date: Mon, 2 Mar 2009 13:59:10 -0800 [thread overview]
Message-ID: <20090302215910.GA31164@kroah.com> (raw)
In-Reply-To: <20090302133551.1266f725.akpm@linux-foundation.org>
On Mon, Mar 02, 2009 at 01:35:51PM -0800, Andrew Morton wrote:
> On Mon, 2 Mar 2009 13:18:20 -0800
> Greg KH <greg@kroah.com> wrote:
>
> > On Mon, Mar 02, 2009 at 01:04:25PM -0800, Andrew Morton wrote:
> > > On Sat, 28 Feb 2009 23:53:03 -0500
> > > Mike Murphy <mamurph@cs.clemson.edu> wrote:
> > > > ...
> > > >
> > > > +static ssize_t xpad_show_int(struct device *dev, struct device_attribute *attr,
> > > > + char *buf)
> > > > +{
> > > > + struct usb_xpad *xpad = to_xpad(dev);
> > > > + int value;
> > > > + if (attr == &dev_attr_rumble_enable)
> > > > + value = xpad->rumble_enable;
> > > > + else if (attr == &dev_attr_controller_number)
> > > > + value = xpad->controller_number;
> > > > + else if (attr == &dev_attr_controller_present)
> > > > + value = xpad->controller_present;
> > > > + else if (attr == &dev_attr_controller_type)
> > > > + value = xpad->controller_type;
> > > > + else if (attr == &dev_attr_left_trigger_full_axis)
> > > > + value = xpad->left_trigger_full_axis;
> > > > + else if (attr == &dev_attr_right_trigger_full_axis)
> > > > + value = xpad->right_trigger_full_axis;
> > > > + else
> > > > + return -EIO;
> > > > + return snprintf(buf, PAGE_SIZE, "%d\n", value);
> > > > +}
> > >
> > > The code's a bit unusual. Most drivers don't have all that
> > > if-then-else stuff. They use a separate function for each sysfs file
> > > and then they wrap it all up into a macro which emits all the data and
> > > code for each file.
> >
> > Yes, most don't, but that is because we used to not pass the attribute
> > variable to the show/store functions. It was added so that we could
> > reduce the huge numbers of functions needed, to do stuff like this. The
> > hwmon drivers are examples of other drivers that do their show/store
> > like this.
> >
> > There's nothing wrong with it that I can see.
> >
>
> OK. I think.
>
> - This approach will require a large number of edits each time an
> attribute is added/removed.
That's really not a big dea.
> - otoh, removing nasty macros is always nice.
>
> - This approach will generate slower code (which doesn't matter
> here).
True.
> - Was it demonstrated that this approach generates less code?
Yes it was. I can go dig through the archives if you want real numbers.
thanks,
greg k-h
next prev parent reply other threads:[~2009-03-02 22:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-01 4:53 PATCH [1/3] drivers/input/xpad.c: Improve Xbox 360 wireless support and add sysfs interface Mike Murphy
2009-03-02 21:04 ` Andrew Morton
2009-03-02 21:18 ` Greg KH
2009-03-02 21:35 ` Andrew Morton
2009-03-02 21:59 ` Greg KH [this message]
2009-03-02 21:59 ` Mike Murphy
2009-03-02 22:39 ` Greg KH
2009-03-02 23:04 ` Mike Murphy
2009-03-02 23:13 ` Greg KH
2009-03-02 21:46 ` Mike Murphy
2009-03-02 22:00 ` Andrew Morton
2009-03-02 22:27 ` Mike Murphy
2009-03-03 2:47 ` Mike Murphy
2009-03-03 3:09 ` Mike Murphy
2009-03-03 3:12 ` Linus Torvalds
2009-03-03 4:16 ` Mike Murphy
2009-03-03 4:20 ` Mike Murphy
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=20090302215910.GA31164@kroah.com \
--to=greg@kroah.com \
--cc=akpm@linux-foundation.org \
--cc=fweisbec@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mamurph@cs.clemson.edu \
--cc=oliver@neukum.org \
--cc=torvalds@linux-foundation.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