linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Murphy <mamurph-ZCNwHF9ErpZ2icitjWtXSw@public.gmane.org>
To: Linus Torvalds
	<torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Cc: Andrew Morton
	<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	greg-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org,
	oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org,
	fweisbec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Subject: Re: PATCH [1/3] drivers/input/xpad.c: Improve Xbox 360 wireless support and add sysfs interface
Date: Mon, 2 Mar 2009 23:16:10 -0500	[thread overview]
Message-ID: <5aa163d00903022016s14b7ad32qfbaf82a07b9e0921@mail.gmail.com> (raw)
In-Reply-To: <alpine.LFD.2.00.0903021902460.3111-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>

On Mon, Mar 2, 2009 at 10:12 PM, Linus Torvalds
<torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org> wrote:
>
> You should do the ~ before the cast, or use - if you just want to reverse
> things. It probably doesn't much matter (the difference between ~ and - i
> just one), but still..
>
> Also, quite frankly, it looks like your 'coords[]' array should just be of
> type 's16' (rather than 'int') to begin with. You seem to really never use
> it as an int anyway. That would get rid of the cast.
>
>> Is there a cleaner way to accomplish the transition from 16-bit
>> unsigned little endian to 16-bit signed host endian?
>
> I think the code is fine, but I think you'd be better off if the "data"
> pointer was perhaps of type "le16 *" to begin with.
>
> That obviously means that your "offset" addition should now be in 16-bit
> words rather than in bytes, so you'd need to divide the offsets by two to
> do that, but those are just numbers anyway. And quite frankly, it looks
> like the actual data is just offset differently - but with the same fixed
> offset between values - for the two cases, so you could just have _one_
> offset (and even just add that into the 'data' pointer).
>
> That would get rid of the second cast. You'd end up with just
>
>        s16 coords[4];
>
>        /* In words - so this is 12 vs 6 bytes into the data */
>        data += (xpad->xtype == XTYPE_XBOX) ? 6 : 3;
>
>        coords[0] = le16_to_cpup(data);
>        coords[1] = ~le16_to_cpup(data + 1);
>        coords[2] = le16_to_cpup(data + 2);
>        coords[3] = ~le16_to_cpup(data + 3);
>        ..
>
> which looks a bit shorter and avoids those casts. I dunno.
>
>                Linus
>

Thanks Linus... that solution worked, and it did make the code
shorter. To get a clean compile, I had to cast the actual argument
data pointer to (__le16 *), but that only adds 2 casts. I will send
the revision shortly.

Thanks,
Mike
-- 
Mike Murphy
Ph.D. Candidate and NSF Graduate Research Fellow
Clemson University School of Computing
120 McAdams Hall
Clemson, SC 29634-0974 USA
Tel: +1 864.656.2838   Fax: +1 864.656.0145
http://cirg.cs.clemson.edu/~mamurph
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2009-03-03  4:16 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
     [not found] ` <5aa163d00902282053h38b0febbyb37fc30855fdc985-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-03-02 21:04   ` Andrew Morton
2009-03-02 21:18     ` Greg KH
     [not found]       ` <20090302211820.GA21489-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2009-03-02 21:35         ` Andrew Morton
     [not found]           ` <20090302133551.1266f725.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2009-03-02 21:59             ` Greg KH
2009-03-02 21:59           ` Mike Murphy
     [not found]             ` <5aa163d00903021359x3a4693f5tbb7f1e3fec4d88b8-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-03-02 22:39               ` Greg KH
2009-03-02 23:04                 ` Mike Murphy
     [not found]                   ` <5aa163d00903021504l1965ecdi3423a43134de10d0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
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
     [not found]       ` <5aa163d00903021847n525e8704jd332610c45e4675a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-03-03  3:12         ` Linus Torvalds
     [not found]           ` <alpine.LFD.2.00.0903021902460.3111-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2009-03-03  4:16             ` Mike Murphy [this message]
     [not found]               ` <5aa163d00903022016s14b7ad32qfbaf82a07b9e0921-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
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=5aa163d00903022016s14b7ad32qfbaf82a07b9e0921@mail.gmail.com \
    --to=mamurph-zcnwhf9erpz2icitjwtxsw@public.gmane.org \
    --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=fweisbec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=greg-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org \
    --cc=linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org \
    --cc=torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.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;
as well as URLs for NNTP newsgroup(s).