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

acassis 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 d09dc08eab sched/mqueue: do sanity check if DEBUG_FEATURES is enabled
d09dc08eab is described below

commit d09dc08eabde2b50b02b66c2f5700b1ca5cb3da4
Author: chao.an <anc...@xiaomi.com>
AuthorDate: Thu Jun 9 13:37:11 2022 +0800

    sched/mqueue: do sanity check if DEBUG_FEATURES is enabled
    
    Signed-off-by: chao.an <anc...@xiaomi.com>
---
 sched/mqueue/mq_rcvinternal.c  | 18 ++++++++++++++----
 sched/mqueue/mq_receive.c      | 12 +++---------
 sched/mqueue/mq_send.c         | 12 +++---------
 sched/mqueue/mq_sndinternal.c  | 19 +++++++++++++++----
 sched/mqueue/mq_timedreceive.c | 12 +++---------
 sched/mqueue/mq_timedsend.c    | 12 +++---------
 sched/mqueue/mqueue.h          | 15 +++++++++++----
 7 files changed, 52 insertions(+), 48 deletions(-)

diff --git a/sched/mqueue/mq_rcvinternal.c b/sched/mqueue/mq_rcvinternal.c
index f369e541e6..f8c56e9524 100644
--- a/sched/mqueue/mq_rcvinternal.c
+++ b/sched/mqueue/mq_rcvinternal.c
@@ -54,7 +54,6 @@
  *
  * Input Parameters:
  *   msgq   - Message queue descriptor
- *   oflags - flags from user set
  *   msg    - Buffer to receive the message
  *   msglen - Size of the buffer in bytes
  *
@@ -69,9 +68,19 @@
  *
  ****************************************************************************/
 
-int nxmq_verify_receive(FAR struct mqueue_inode_s *msgq,
-                        int oflags, FAR char *msg, size_t msglen)
+#ifdef CONFIG_DEBUG_FEATURES
+int nxmq_verify_receive(FAR struct file *mq, FAR char *msg, size_t msglen)
 {
+  FAR struct inode *inode = mq->f_inode;
+  FAR struct mqueue_inode_s *msgq;
+
+  if (inode == NULL)
+    {
+      return -EBADF;
+    }
+
+  msgq = inode->i_private;
+
   /* Verify the input parameters */
 
   if (!msg || !msgq)
@@ -79,7 +88,7 @@ int nxmq_verify_receive(FAR struct mqueue_inode_s *msgq,
       return -EINVAL;
     }
 
-  if ((oflags & O_RDOK) == 0)
+  if ((mq->f_oflags & O_RDOK) == 0)
     {
       return -EPERM;
     }
@@ -91,6 +100,7 @@ int nxmq_verify_receive(FAR struct mqueue_inode_s *msgq,
 
   return OK;
 }
+#endif
 
 /****************************************************************************
  * Name: nxmq_wait_receive
diff --git a/sched/mqueue/mq_receive.c b/sched/mqueue/mq_receive.c
index ebe4209c23..89725e3304 100644
--- a/sched/mqueue/mq_receive.c
+++ b/sched/mqueue/mq_receive.c
@@ -73,31 +73,25 @@
 ssize_t file_mq_receive(FAR struct file *mq, FAR char *msg, size_t msglen,
                         FAR unsigned int *prio)
 {
-  FAR struct inode *inode = mq->f_inode;
   FAR struct mqueue_inode_s *msgq;
   FAR struct mqueue_msg_s *mqmsg;
   irqstate_t flags;
   ssize_t ret;
 
-  if (!inode)
-    {
-      return -EBADF;
-    }
-
-  msgq = inode->i_private;
-
   DEBUGASSERT(up_interrupt_context() == false);
 
   /* Verify the input parameters and, in case of an error, set
    * errno appropriately.
    */
 
-  ret = nxmq_verify_receive(msgq, mq->f_oflags, msg, msglen);
+  ret = nxmq_verify_receive(mq, msg, msglen);
   if (ret < 0)
     {
       return ret;
     }
 
+  msgq = mq->f_inode->i_private;
+
   /* Furthermore, nxmq_wait_receive() expects to have interrupts disabled
    * because messages can be sent from interrupt level.
    */
diff --git a/sched/mqueue/mq_send.c b/sched/mqueue/mq_send.c
index 730e49b262..8fed5373cd 100644
--- a/sched/mqueue/mq_send.c
+++ b/sched/mqueue/mq_send.c
@@ -70,29 +70,23 @@
 int file_mq_send(FAR struct file *mq, FAR const char *msg, size_t msglen,
                  unsigned int prio)
 {
-  FAR struct inode *inode = mq->f_inode;
   FAR struct mqueue_inode_s *msgq;
   FAR struct mqueue_msg_s *mqmsg;
   irqstate_t flags;
   int ret;
 
-  if (!inode)
-    {
-      return -EBADF;
-    }
-
-  msgq = inode->i_private;
-
   /* Verify the input parameters -- setting errno appropriately
    * on any failures to verify.
    */
 
-  ret = nxmq_verify_send(msgq, mq->f_oflags, msg, msglen, prio);
+  ret = nxmq_verify_send(mq, msg, msglen, prio);
   if (ret < 0)
     {
       return ret;
     }
 
+  msgq = mq->f_inode->i_private;
+
   /* Allocate a message structure:
    * - Immediately if we are called from an interrupt handler.
    * - Immediately if the message queue is not full, or
diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c
index 32ae205427..d63716207f 100644
--- a/sched/mqueue/mq_sndinternal.c
+++ b/sched/mqueue/mq_sndinternal.c
@@ -57,7 +57,6 @@
  *
  * Input Parameters:
  *   msgq   - Message queue descriptor
- *   oflags - flags from user set
  *   msg    - Message to send
  *   msglen - The length of the message in bytes
  *   prio   - The priority of the message
@@ -73,9 +72,20 @@
  *
  ****************************************************************************/
 
-int nxmq_verify_send(FAR struct mqueue_inode_s *msgq, int oflags,
-                     FAR const char *msg, size_t msglen, unsigned int prio)
+#ifdef CONFIG_DEBUG_FEATURES
+int nxmq_verify_send(FAR FAR struct file *mq, FAR const char *msg,
+                     size_t msglen, unsigned int prio)
 {
+  FAR struct inode *inode = mq->f_inode;
+  FAR struct mqueue_inode_s *msgq;
+
+  if (inode == NULL)
+    {
+      return -EBADF;
+    }
+
+  msgq = inode->i_private;
+
   /* Verify the input parameters */
 
   if (msg == NULL || msgq == NULL || prio > MQ_PRIO_MAX)
@@ -83,7 +93,7 @@ int nxmq_verify_send(FAR struct mqueue_inode_s *msgq, int 
oflags,
       return -EINVAL;
     }
 
-  if ((oflags & O_WROK) == 0)
+  if ((mq->f_oflags & O_WROK) == 0)
     {
       return -EPERM;
     }
@@ -95,6 +105,7 @@ int nxmq_verify_send(FAR struct mqueue_inode_s *msgq, int 
oflags,
 
   return OK;
 }
+#endif
 
 /****************************************************************************
  * Name: nxmq_alloc_msg
diff --git a/sched/mqueue/mq_timedreceive.c b/sched/mqueue/mq_timedreceive.c
index 9e3f9b8582..71460f65ec 100644
--- a/sched/mqueue/mq_timedreceive.c
+++ b/sched/mqueue/mq_timedreceive.c
@@ -138,27 +138,19 @@ ssize_t file_mq_timedreceive(FAR struct file *mq, FAR 
char *msg,
                              size_t msglen, FAR unsigned int *prio,
                              FAR const struct timespec *abstime)
 {
-  FAR struct inode *inode = mq->f_inode;
   FAR struct tcb_s *rtcb = this_task();
   FAR struct mqueue_inode_s *msgq;
   FAR struct mqueue_msg_s *mqmsg;
   irqstate_t flags;
   int ret;
 
-  if (!inode)
-    {
-      return -EBADF;
-    }
-
-  msgq = inode->i_private;
-
   DEBUGASSERT(up_interrupt_context() == false);
 
   /* Verify the input parameters and, in case of an error, set
    * errno appropriately.
    */
 
-  ret = nxmq_verify_receive(msgq, mq->f_oflags, msg, msglen);
+  ret = nxmq_verify_receive(mq, msg, msglen);
   if (ret < 0)
     {
       return ret;
@@ -169,6 +161,8 @@ ssize_t file_mq_timedreceive(FAR struct file *mq, FAR char 
*msg,
       return -EINVAL;
     }
 
+  msgq = mq->f_inode->i_private;
+
   /* Furthermore, nxmq_wait_receive() expects to have interrupts disabled
    * because messages can be sent from interrupt level.
    */
diff --git a/sched/mqueue/mq_timedsend.c b/sched/mqueue/mq_timedsend.c
index 2d9003f613..9db57621c8 100644
--- a/sched/mqueue/mq_timedsend.c
+++ b/sched/mqueue/mq_timedsend.c
@@ -146,7 +146,6 @@ int file_mq_timedsend(FAR struct file *mq, FAR const char 
*msg,
                       size_t msglen, unsigned int prio,
                       FAR const struct timespec *abstime)
 {
-  FAR struct inode *inode = mq->f_inode;
   FAR struct tcb_s *rtcb = this_task();
   FAR struct mqueue_inode_s *msgq;
   FAR struct mqueue_msg_s *mqmsg;
@@ -154,23 +153,18 @@ int file_mq_timedsend(FAR struct file *mq, FAR const char 
*msg,
   sclock_t ticks;
   int ret;
 
-  if (!inode)
-    {
-      return -EBADF;
-    }
-
-  msgq = inode->i_private;
-
   DEBUGASSERT(up_interrupt_context() == false);
 
   /* Verify the input parameters on any failures to verify. */
 
-  ret = nxmq_verify_send(msgq, mq->f_oflags, msg, msglen, prio);
+  ret = nxmq_verify_send(mq, msg, msglen, prio);
   if (ret < 0)
     {
       return ret;
     }
 
+  msgq = mq->f_inode->i_private;
+
   /* Disable interruption */
 
   flags = enter_critical_section();
diff --git a/sched/mqueue/mqueue.h b/sched/mqueue/mqueue.h
index 0d9aef1d07..ab28437fb2 100644
--- a/sched/mqueue/mqueue.h
+++ b/sched/mqueue/mqueue.h
@@ -115,8 +115,11 @@ void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode);
 
 /* mq_rcvinternal.c 
*************************************************************/
 
-int nxmq_verify_receive(FAR struct mqueue_inode_s *msgq,
-                        int oflags, FAR char *msg, size_t msglen);
+#ifdef CONFIG_DEBUG_FEATURES
+int nxmq_verify_receive(FAR struct file *mq, FAR char *msg, size_t msglen);
+#else
+# define nxmq_verify_receive(msgq, msg, msglen) OK
+#endif
 int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,
                       int oflags, FAR struct mqueue_msg_s **rcvmsg);
 ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
@@ -125,8 +128,12 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
 
 /* mq_sndinternal.c 
*************************************************************/
 
-int nxmq_verify_send(FAR struct mqueue_inode_s *msgq, int oflags,
-                     FAR const char *msg, size_t msglen, unsigned int prio);
+#ifdef CONFIG_DEBUG_FEATURES
+int nxmq_verify_send(FAR struct file *mq, FAR const char *msg,
+                     size_t msglen, unsigned int prio);
+#else
+# define nxmq_verify_send(mq, msg, msglen, prio) OK
+#endif
 FAR struct mqueue_msg_s *nxmq_alloc_msg(void);
 int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags);
 int nxmq_do_send(FAR struct mqueue_inode_s *msgq,

Reply via email to