From: tobias@gambas-buch.de (Tobias Boege)
To: kernelnewbies@lists.kernelnewbies.org
Subject: why not choose another way to define the _IOC_xxxMASK related to the ioctl
Date: Sat, 30 Mar 2013 09:41:55 +0100 [thread overview]
Message-ID: <20130330084155.GF498@aurora> (raw)
In-Reply-To: <1c383348.16eac.13db9d5e5a0.Coremail.tinyshrimp@163.com>
On Sat, 30 Mar 2013, RS wrote:
> it defines in the kernel: #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) //define ... #define _IOC_NRSHIFT 0 ... #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) //when decode
>
> why not define it like this:
> #define _IOC_NRSHIFT 0
> ...
> #define _IOC_NRMASK ((_IOC_NRSHIFT >> _IOC_NRBITS) - _IOC_NRSHIFT) //define
> ...
> #define _IOC_DIR(nr) ((nr & _IOC_DIRMASK) >> _IOC_DIRSHIFT) // when decode
>
>
> I think it is better for the word "mask" .
>
It can't be better this way because it's wrong. Let's compute a bit:
You are referring include/uapi/asm-generic/ioctl.h AFAICS:
#define _IOC_NRBITS 8
#define _IOC_NRSHIFT 0
#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
This gives _IOC_NRMASK = ((1 << 8) - 1) = 0xff. But supposing your
_IOC_NRMASK ((_IOC_NRSHIFT >> _IOC_NRBITS) - _IOC_NRSHIFT)
it yields _IOC_NRMASK = ((0 >> 8) - 0) = 0x00.
You see? With your mask you'll never get any bits out of the ioctl number
because it's just wrong.
The same applies to _IOC_DIR(nr). You can't just exchange bitwise ands and
shifts - you'd have to change the constants for this... and there is really
no point in it.
Regards,
Tobi
next prev parent reply other threads:[~2013-03-30 8:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-30 5:47 why not choose another way to define the _IOC_xxxMASK related to the ioctl RS
2013-03-30 8:41 ` Tobias Boege [this message]
2013-03-30 10:01 ` RS
2013-03-30 15:59 ` Valdis.Kletnieks at vt.edu
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=20130330084155.GF498@aurora \
--to=tobias@gambas-buch.de \
--cc=kernelnewbies@lists.kernelnewbies.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.