You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ar...@apache.org on 2022/09/06 14:46:44 UTC

[incubator-nuttx] branch master updated: net: Align the prototype of sock_intf_s::si_ioctl with file_operations::ioctl

This is an automated email from the ASF dual-hosted git repository.

archer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new e0bb281e7a net: Align the prototype of sock_intf_s::si_ioctl with file_operations::ioctl
e0bb281e7a is described below

commit e0bb281e7afbc17ce5bf142b1760540ce41c004c
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Aug 31 02:18:33 2022 +0800

    net: Align the prototype of sock_intf_s::si_ioctl with file_operations::ioctl
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 include/nuttx/net/net.h     | 21 +++++++++++++++++++--
 include/nuttx/net/netdev.h  | 17 -----------------
 net/icmp/icmp.h             |  4 +---
 net/icmp/icmp_ioctl.c       |  4 +---
 net/icmpv6/icmpv6.h         |  4 +---
 net/icmpv6/icmpv6_ioctl.c   |  4 +---
 net/inet/inet_sockif.c      | 12 +++++-------
 net/local/local_sockif.c    |  8 +++-----
 net/netdev/netdev_ioctl.c   | 10 +---------
 net/rpmsg/rpmsg_sockif.c    | 24 ++++++------------------
 net/tcp/tcp.h               |  4 +---
 net/tcp/tcp_ioctl.c         |  3 +--
 net/udp/udp.h               |  4 +---
 net/udp/udp_ioctl.c         |  4 +---
 net/usrsock/usrsock.h       |  4 +---
 net/usrsock/usrsock_ioctl.c | 18 ++++++++++++------
 16 files changed, 55 insertions(+), 90 deletions(-)

diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h
index 4f0bc45c18..47dde9ebf3 100644
--- a/include/nuttx/net/net.h
+++ b/include/nuttx/net/net.h
@@ -196,8 +196,8 @@ struct sock_intf_s
   CODE ssize_t    (*si_recvmsg)(FAR struct socket *psock,
                     FAR struct msghdr *msg, int flags);
   CODE int        (*si_close)(FAR struct socket *psock);
-  CODE int        (*si_ioctl)(FAR struct socket *psock, int cmd,
-                    FAR void *arg, size_t arglen);
+  CODE int        (*si_ioctl)(FAR struct socket *psock,
+                    int cmd, unsigned long arg);
   CODE int        (*si_socketpair)(FAR struct socket *psocks[2]);
 #ifdef CONFIG_NET_SENDFILE
   CODE ssize_t    (*si_sendfile)(FAR struct socket *psock,
@@ -314,6 +314,23 @@ extern "C"
 
 void net_initialize(void);
 
+/****************************************************************************
+ * Name: net_ioctl_arglen
+ *
+ * Description:
+ *   Calculate the ioctl argument buffer length.
+ *
+ * Input Parameters:
+ *
+ *   cmd      The ioctl command
+ *
+ * Returned Value:
+ *   The argument buffer length, or error code.
+ *
+ ****************************************************************************/
+
+ssize_t net_ioctl_arglen(int cmd);
+
 /****************************************************************************
  * Critical section management.
  *
diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h
index 98b57edf97..5b10a13a5b 100644
--- a/include/nuttx/net/netdev.h
+++ b/include/nuttx/net/netdev.h
@@ -621,23 +621,6 @@ int netdev_ifdown(FAR struct net_driver_s *dev);
 int netdev_carrier_on(FAR struct net_driver_s *dev);
 int netdev_carrier_off(FAR struct net_driver_s *dev);
 
-/****************************************************************************
- * Name: net_ioctl_arglen
- *
- * Description:
- *   Calculate the ioctl argument buffer length.
- *
- * Input Parameters:
- *
- *   cmd      The ioctl command
- *
- * Returned Value:
- *   The argument buffer length, or error code.
- *
- ****************************************************************************/
-
-ssize_t net_ioctl_arglen(int cmd);
-
 /****************************************************************************
  * Name: net_chksum
  *
diff --git a/net/icmp/icmp.h b/net/icmp/icmp.h
index 6015804abb..4580334ea7 100644
--- a/net/icmp/icmp.h
+++ b/net/icmp/icmp.h
@@ -390,13 +390,11 @@ void icmp_reply(FAR struct net_driver_s *dev, int type, int code);
  *   conn     The ICMP connection of interest
  *   cmd      The ioctl command
  *   arg      The argument of the ioctl cmd
- *   arglen   The length of 'arg'
  *
  ****************************************************************************/
 
 #ifdef CONFIG_NET_ICMP_SOCKET
-int icmp_ioctl(FAR struct socket *psock,
-               int cmd, FAR void *arg, size_t arglen);
+int icmp_ioctl(FAR struct socket *psock, int cmd, unsigned long arg);
 #endif
 
 #undef EXTERN
diff --git a/net/icmp/icmp_ioctl.c b/net/icmp/icmp_ioctl.c
index dba9be4256..7c38638d63 100644
--- a/net/icmp/icmp_ioctl.c
+++ b/net/icmp/icmp_ioctl.c
@@ -51,12 +51,10 @@
  *   conn     The ICMP connection of interest
  *   cmd      The ioctl command
  *   arg      The argument of the ioctl cmd
- *   arglen   The length of 'arg'
  *
  ****************************************************************************/
 
-int icmp_ioctl(FAR struct socket *psock,
-               int cmd, FAR void *arg, size_t arglen)
+int icmp_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
 {
   FAR struct icmp_conn_s *conn = psock->s_conn;
   int ret = OK;
diff --git a/net/icmpv6/icmpv6.h b/net/icmpv6/icmpv6.h
index 7821a8ca57..487607afea 100644
--- a/net/icmpv6/icmpv6.h
+++ b/net/icmpv6/icmpv6.h
@@ -771,13 +771,11 @@ void icmpv6_reply(FAR struct net_driver_s *dev,
  *   conn     The ICMP connection of interest
  *   cmd      The ioctl command
  *   arg      The argument of the ioctl cmd
- *   arglen   The length of 'arg'
  *
  ****************************************************************************/
 
 #ifdef CONFIG_NET_ICMPv6_SOCKET
-int icmpv6_ioctl(FAR struct socket *psock,
-                 int cmd, FAR void *arg, size_t arglen);
+int icmpv6_ioctl(FAR struct socket *psock, int cmd, unsigned long arg);
 #endif
 
 #undef EXTERN
diff --git a/net/icmpv6/icmpv6_ioctl.c b/net/icmpv6/icmpv6_ioctl.c
index 28cd658b27..6e97bd3f9b 100644
--- a/net/icmpv6/icmpv6_ioctl.c
+++ b/net/icmpv6/icmpv6_ioctl.c
@@ -51,12 +51,10 @@
  *   conn     The icmpv6 connection of interest
  *   cmd      The ioctl command
  *   arg      The argument of the ioctl cmd
- *   arglen   The length of 'arg'
  *
  ****************************************************************************/
 
-int icmpv6_ioctl(FAR struct socket *psock,
-               int cmd, FAR void *arg, size_t arglen)
+int icmpv6_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
 {
   FAR struct icmpv6_conn_s *conn = psock->s_conn;
   int ret = OK;
diff --git a/net/inet/inet_sockif.c b/net/inet/inet_sockif.c
index 82d1416510..d63cd40873 100644
--- a/net/inet/inet_sockif.c
+++ b/net/inet/inet_sockif.c
@@ -88,8 +88,8 @@ static ssize_t    inet_sendmsg(FAR struct socket *psock,
                     FAR struct msghdr *msg, int flags);
 static ssize_t    inet_recvmsg(FAR struct socket *psock,
                     FAR struct msghdr *msg, int flags);
-static int        inet_ioctl(FAR struct socket *psock, int cmd,
-                    FAR void *arg, size_t arglen);
+static int        inet_ioctl(FAR struct socket *psock,
+                    int cmd, unsigned long arg);
 static int        inet_socketpair(FAR struct socket *psocks[2]);
 #ifdef CONFIG_NET_SENDFILE
 static ssize_t    inet_sendfile(FAR struct socket *psock,
@@ -1338,12 +1338,10 @@ static ssize_t inet_sendmsg(FAR struct socket *psock,
  *   psock    A reference to the socket structure of the socket
  *   cmd      The ioctl command
  *   arg      The argument of the ioctl cmd
- *   arglen   The length of 'arg'
  *
  ****************************************************************************/
 
-static int inet_ioctl(FAR struct socket *psock, int cmd,
-                      FAR void *arg, size_t arglen)
+static int inet_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
 {
   /* Verify that the sockfd corresponds to valid, allocated socket */
 
@@ -1355,14 +1353,14 @@ static int inet_ioctl(FAR struct socket *psock, int cmd,
 #if defined(CONFIG_NET_TCP) && !defined(CONFIG_NET_TCP_NO_STACK)
   if (psock->s_type == SOCK_STREAM)
     {
-      return tcp_ioctl(psock->s_conn, cmd, arg, arglen);
+      return tcp_ioctl(psock->s_conn, cmd, arg);
     }
 #endif
 
 #if defined(CONFIG_NET_UDP) && defined(NET_UDP_HAVE_STACK)
   if (psock->s_type == SOCK_DGRAM)
     {
-      return udp_ioctl(psock->s_conn, cmd, arg, arglen);
+      return udp_ioctl(psock->s_conn, cmd, arg);
     }
 #endif
 
diff --git a/net/local/local_sockif.c b/net/local/local_sockif.c
index 547f029ab1..a34776f348 100644
--- a/net/local/local_sockif.c
+++ b/net/local/local_sockif.c
@@ -69,8 +69,8 @@ static int        local_accept(FAR struct socket *psock,
 static int        local_poll(FAR struct socket *psock,
                     FAR struct pollfd *fds, bool setup);
 static int        local_close(FAR struct socket *psock);
-static int        local_ioctl(FAR struct socket *psock, int cmd,
-                    FAR void *arg, size_t arglen);
+static int        local_ioctl(FAR struct socket *psock,
+                    int cmd, unsigned long arg);
 static int        local_socketpair(FAR struct socket *psocks[2]);
 
 /****************************************************************************
@@ -704,12 +704,10 @@ static int local_close(FAR struct socket *psock)
  *   psock    A reference to the socket structure of the socket
  *   cmd      The ioctl command
  *   arg      The argument of the ioctl cmd
- *   arglen   The length of 'arg'
  *
  ****************************************************************************/
 
-static int local_ioctl(FAR struct socket *psock, int cmd,
-                       FAR void *arg, size_t arglen)
+static int local_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
 {
   FAR struct local_conn_s *conn;
   int ret = OK;
diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c
index 5eff1867b4..d7642a13bd 100644
--- a/net/netdev/netdev_ioctl.c
+++ b/net/netdev/netdev_ioctl.c
@@ -1586,15 +1586,7 @@ static int netdev_ioctl(FAR struct socket *psock, int cmd,
 {
   if (psock->s_sockif && psock->s_sockif->si_ioctl)
     {
-      ssize_t arglen;
-
-      arglen = net_ioctl_arglen(cmd);
-      if (arglen < 0)
-        {
-          return arglen;
-        }
-
-      return psock->s_sockif->si_ioctl(psock, cmd, (FAR void *)arg, arglen);
+      return psock->s_sockif->si_ioctl(psock, cmd, arg);
     }
   else
     {
diff --git a/net/rpmsg/rpmsg_sockif.c b/net/rpmsg/rpmsg_sockif.c
index bd04dd2f6c..da861f03c0 100644
--- a/net/rpmsg/rpmsg_sockif.c
+++ b/net/rpmsg/rpmsg_sockif.c
@@ -149,8 +149,8 @@ static ssize_t    rpmsg_socket_sendmsg(FAR struct socket *psock,
 static ssize_t    rpmsg_socket_recvmsg(FAR struct socket *psock,
                     FAR struct msghdr *msg, int flags);
 static int        rpmsg_socket_close(FAR struct socket *psock);
-static int        rpmsg_socket_ioctl(FAR struct socket *psock, int cmd,
-                                     FAR void *arg, size_t arglen);
+static int        rpmsg_socket_ioctl(FAR struct socket *psock,
+                                     int cmd, unsigned long arg);
 
 /****************************************************************************
  * Public Data
@@ -1310,8 +1310,8 @@ static int rpmsg_socket_close(FAR struct socket *psock)
   return 0;
 }
 
-static int rpmsg_socket_ioctl(FAR struct socket *psock, int cmd,
-                              FAR void *arg, size_t arglen)
+static int rpmsg_socket_ioctl(FAR struct socket *psock,
+                              int cmd, unsigned long arg)
 {
   FAR struct rpmsg_socket_conn_s *conn = psock->s_conn;
   int ret = OK;
@@ -1319,25 +1319,13 @@ static int rpmsg_socket_ioctl(FAR struct socket *psock, int cmd,
   switch (cmd)
     {
       case FIONREAD:
-        if (arglen != sizeof(int))
-          {
-            ret = -EINVAL;
-            break;
-          }
-
         *(FAR int *)((uintptr_t)arg) = circbuf_used(&conn->recvbuf);
-
         break;
-      case FIONSPACE:
-        if (arglen != sizeof(int))
-          {
-            ret = -EINVAL;
-            break;
-          }
 
+      case FIONSPACE:
         *(FAR int *)((uintptr_t)arg) = rpmsg_socket_get_space(conn);
-
         break;
+
       default:
         ret = -ENOTTY;
         break;
diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h
index d41bf843cd..fec08800a9 100644
--- a/net/tcp/tcp.h
+++ b/net/tcp/tcp.h
@@ -2000,12 +2000,10 @@ int tcp_txdrain(FAR struct socket *psock, unsigned int timeout);
  *   conn     The TCP connection of interest
  *   cmd      The ioctl command
  *   arg      The argument of the ioctl cmd
- *   arglen   The length of 'arg'
  *
  ****************************************************************************/
 
-int tcp_ioctl(FAR struct tcp_conn_s *conn, int cmd,
-              FAR void *arg, size_t arglen);
+int tcp_ioctl(FAR struct tcp_conn_s *conn, int cmd, unsigned long arg);
 
 /****************************************************************************
  * Name: tcp_sendbuffer_notify
diff --git a/net/tcp/tcp_ioctl.c b/net/tcp/tcp_ioctl.c
index 9ebd4b50a3..c53252dd26 100644
--- a/net/tcp/tcp_ioctl.c
+++ b/net/tcp/tcp_ioctl.c
@@ -55,8 +55,7 @@
  *
  ****************************************************************************/
 
-int tcp_ioctl(FAR struct tcp_conn_s *conn,
-              int cmd, FAR void *arg, size_t arglen)
+int tcp_ioctl(FAR struct tcp_conn_s *conn, int cmd, unsigned long arg)
 {
   int ret = OK;
 
diff --git a/net/udp/udp.h b/net/udp/udp.h
index 2fa4025190..a95ff706d7 100644
--- a/net/udp/udp.h
+++ b/net/udp/udp.h
@@ -939,12 +939,10 @@ int udp_txdrain(FAR struct socket *psock, unsigned int timeout);
  *   conn     The TCP connection of interest
  *   cmd      The ioctl command
  *   arg      The argument of the ioctl cmd
- *   arglen   The length of 'arg'
  *
  ****************************************************************************/
 
-int udp_ioctl(FAR struct udp_conn_s *conn,
-              int cmd, FAR void *arg, size_t arglen);
+int udp_ioctl(FAR struct udp_conn_s *conn, int cmd, unsigned long arg);
 
 /****************************************************************************
  * Name: udp_sendbuffer_notify
diff --git a/net/udp/udp_ioctl.c b/net/udp/udp_ioctl.c
index 9968c608f9..2f29b9549c 100644
--- a/net/udp/udp_ioctl.c
+++ b/net/udp/udp_ioctl.c
@@ -51,12 +51,10 @@
  *   conn     The TCP connection of interest
  *   cmd      The ioctl command
  *   arg      The argument of the ioctl cmd
- *   arglen   The length of 'arg'
  *
  ****************************************************************************/
 
-int udp_ioctl(FAR struct udp_conn_s *conn,
-              int cmd, FAR void *arg, size_t arglen)
+int udp_ioctl(FAR struct udp_conn_s *conn, int cmd, unsigned long arg)
 {
   FAR struct iob_s *iob;
   int ret = OK;
diff --git a/net/usrsock/usrsock.h b/net/usrsock/usrsock.h
index d663d4661a..dd9a438617 100644
--- a/net/usrsock/usrsock.h
+++ b/net/usrsock/usrsock.h
@@ -656,12 +656,10 @@ int usrsock_getpeername(FAR struct socket *psock,
  *   psock    A reference to the socket structure of the socket
  *   cmd      The ioctl command
  *   arg      The argument of the ioctl cmd
- *   arglen   The length of 'arg'
  *
  ****************************************************************************/
 
-int usrsock_ioctl(FAR struct socket *psock, int cmd, FAR void *arg,
-                  size_t arglen);
+int usrsock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg);
 
 #undef EXTERN
 #ifdef __cplusplus
diff --git a/net/usrsock/usrsock_ioctl.c b/net/usrsock/usrsock_ioctl.c
index 91b252aaad..f98c528a80 100644
--- a/net/usrsock/usrsock_ioctl.c
+++ b/net/usrsock/usrsock_ioctl.c
@@ -103,7 +103,7 @@ static uint16_t ioctl_event(FAR struct net_driver_s *dev,
  ****************************************************************************/
 
 static int do_ioctl_request(FAR struct usrsock_conn_s *conn, int cmd,
-                                 FAR void *arg, size_t arglen)
+                            FAR void *arg, size_t arglen)
 {
   struct usrsock_request_ioctl_s req =
   {
@@ -125,9 +125,9 @@ static int do_ioctl_request(FAR struct usrsock_conn_s *conn, int cmd,
   req.cmd = cmd;
   req.arglen = arglen;
 
-  bufs[0].iov_base = (FAR void *)&req;
+  bufs[0].iov_base = &req;
   bufs[0].iov_len = sizeof(req);
-  bufs[1].iov_base = (FAR void *)arg;
+  bufs[1].iov_base = arg;
   bufs[1].iov_len = req.arglen;
 
 #ifdef CONFIG_NETDEV_WIRELESS_IOCTL
@@ -156,12 +156,10 @@ static int do_ioctl_request(FAR struct usrsock_conn_s *conn, int cmd,
  *   psock    A reference to the socket structure of the socket
  *   cmd      The ioctl command
  *   arg      The argument of the ioctl cmd
- *   arglen   The length of 'arg'
  *
  ****************************************************************************/
 
-int usrsock_ioctl(FAR struct socket *psock, int cmd, FAR void *arg,
-                  size_t arglen)
+int usrsock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg_)
 {
   FAR struct usrsock_conn_s *conn = psock->s_conn;
   struct usrsock_data_reqstate_s state =
@@ -172,6 +170,8 @@ int usrsock_ioctl(FAR struct socket *psock, int cmd, FAR void *arg,
   {
   };
 
+  FAR void *arg = (FAR void *)(uintptr_t)arg_;
+  ssize_t arglen;
   int ret;
 
   /* Bypass FIONBIO to socket level,
@@ -183,6 +183,12 @@ int usrsock_ioctl(FAR struct socket *psock, int cmd, FAR void *arg,
       return -ENOTTY;
     }
 
+  arglen = net_ioctl_arglen(cmd);
+  if (arglen < 0)
+    {
+      return arglen;
+    }
+
   net_lock();
 
   if (conn->state == USRSOCK_CONN_STATE_UNINITIALIZED ||