* [PATCH net-next 1/1] driver: tun: Use new macro SOCK_IOC_MAGIC instead of literal number 0x89
@ 2016-10-25 12:56 fgao
2016-10-26 11:12 ` David Laight
0 siblings, 1 reply; 3+ messages in thread
From: fgao @ 2016-10-25 12:56 UTC (permalink / raw)
To: davem, jasowang, edumazet, pabeni, netdev; +Cc: gfree.wind, Gao Feng
From: Gao Feng <fgao@ikuai8.com>
The current codes use _IOC_TYPE(cmd) == 0x89 to check if the cmd is one
socket ioctl command like SIOCGIFHWADDR. But the literal number 0x89 may
confuse readers. So create one macro SOCK_IOC_MAGIC like SPI_IOC_MAGIC to
enhance the readability.
Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
drivers/net/tun.c | 2 +-
include/uapi/linux/sockios.h | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 9328568..9efd185 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1985,7 +1985,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
int le;
int ret;
- if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
+ if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == SOCK_IOC_MAGIC) {
if (copy_from_user(&ifr, argp, ifreq_len))
return -EFAULT;
} else {
diff --git a/include/uapi/linux/sockios.h b/include/uapi/linux/sockios.h
index 8e7890b..b8f42f2 100644
--- a/include/uapi/linux/sockios.h
+++ b/include/uapi/linux/sockios.h
@@ -24,6 +24,8 @@
#define SIOCINQ FIONREAD
#define SIOCOUTQ TIOCOUTQ /* output queue size (not sent + not acked) */
+#define SOCK_IOC_MAGIC 0x89
+
/* Routing table calls. */
#define SIOCADDRT 0x890B /* add routing table entry */
#define SIOCDELRT 0x890C /* delete routing table entry */
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH net-next 1/1] driver: tun: Use new macro SOCK_IOC_MAGIC instead of literal number 0x89
2016-10-25 12:56 [PATCH net-next 1/1] driver: tun: Use new macro SOCK_IOC_MAGIC instead of literal number 0x89 fgao
@ 2016-10-26 11:12 ` David Laight
2016-10-26 14:10 ` Gao Feng
0 siblings, 1 reply; 3+ messages in thread
From: David Laight @ 2016-10-26 11:12 UTC (permalink / raw)
To: 'fgao@ikuai8.com', davem, jasowang, edumazet, pabeni, netdev
Cc: gfree.wind
From: fgao@ikuai8.com
> Sent: 25 October 2016 13:56
> The current codes use _IOC_TYPE(cmd) == 0x89 to check if the cmd is one
> socket ioctl command like SIOCGIFHWADDR. But the literal number 0x89 may
> confuse readers. So create one macro SOCK_IOC_MAGIC like SPI_IOC_MAGIC to
> enhance the readability.
>
> Signed-off-by: Gao Feng <fgao@ikuai8.com>
> ---
> drivers/net/tun.c | 2 +-
> include/uapi/linux/sockios.h | 2 ++
> 2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 9328568..9efd185 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1985,7 +1985,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
> int le;
> int ret;
>
> - if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
> + if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == SOCK_IOC_MAGIC) {
> if (copy_from_user(&ifr, argp, ifreq_len))
> return -EFAULT;
> } else {
> diff --git a/include/uapi/linux/sockios.h b/include/uapi/linux/sockios.h
> index 8e7890b..b8f42f2 100644
> --- a/include/uapi/linux/sockios.h
> +++ b/include/uapi/linux/sockios.h
> @@ -24,6 +24,8 @@
> #define SIOCINQ FIONREAD
> #define SIOCOUTQ TIOCOUTQ /* output queue size (not sent + not acked) */
>
> +#define SOCK_IOC_MAGIC 0x89
> +
> /* Routing table calls. */
> #define SIOCADDRT 0x890B /* add routing table entry */
> #define SIOCDELRT 0x890C /* delete routing table entry */
Shouldn't these constants be defined in terms of SOCK_IOC_MAGIC?
And there must be a better name!
David
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next 1/1] driver: tun: Use new macro SOCK_IOC_MAGIC instead of literal number 0x89
2016-10-26 11:12 ` David Laight
@ 2016-10-26 14:10 ` Gao Feng
0 siblings, 0 replies; 3+ messages in thread
From: Gao Feng @ 2016-10-26 14:10 UTC (permalink / raw)
To: David Laight; +Cc: davem, jasowang, edumazet, pabeni, netdev
Hi David,
On Wed, Oct 26, 2016 at 7:12 PM, David Laight <David.Laight@aculab.com> wrote:
> From: fgao@ikuai8.com
>> Sent: 25 October 2016 13:56
>> The current codes use _IOC_TYPE(cmd) == 0x89 to check if the cmd is one
>> socket ioctl command like SIOCGIFHWADDR. But the literal number 0x89 may
>> confuse readers. So create one macro SOCK_IOC_MAGIC like SPI_IOC_MAGIC to
>> enhance the readability.
>>
>> Signed-off-by: Gao Feng <fgao@ikuai8.com>
>> ---
>> drivers/net/tun.c | 2 +-
>> include/uapi/linux/sockios.h | 2 ++
>> 2 files changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
>> index 9328568..9efd185 100644
>> --- a/drivers/net/tun.c
>> +++ b/drivers/net/tun.c
>> @@ -1985,7 +1985,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
>> int le;
>> int ret;
>>
>> - if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
>> + if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == SOCK_IOC_MAGIC) {
>> if (copy_from_user(&ifr, argp, ifreq_len))
>> return -EFAULT;
>> } else {
>> diff --git a/include/uapi/linux/sockios.h b/include/uapi/linux/sockios.h
>> index 8e7890b..b8f42f2 100644
>> --- a/include/uapi/linux/sockios.h
>> +++ b/include/uapi/linux/sockios.h
>> @@ -24,6 +24,8 @@
>> #define SIOCINQ FIONREAD
>> #define SIOCOUTQ TIOCOUTQ /* output queue size (not sent + not acked) */
>>
>> +#define SOCK_IOC_MAGIC 0x89
>> +
>> /* Routing table calls. */
>> #define SIOCADDRT 0x890B /* add routing table entry */
>> #define SIOCDELRT 0x890C /* delete routing table entry */
>
> Shouldn't these constants be defined in terms of SOCK_IOC_MAGIC?
> And there must be a better name!
>
> David
>
How about the SOCK_IOC_TYPE or SOCK_IOC_BASE ?
There are ETRAXGPIO_IOCTYPE and HARDWALL_IOCTL_BASE already.
Regards
Feng
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-10-26 14:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-25 12:56 [PATCH net-next 1/1] driver: tun: Use new macro SOCK_IOC_MAGIC instead of literal number 0x89 fgao
2016-10-26 11:12 ` David Laight
2016-10-26 14:10 ` Gao Feng
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.