You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/12/04 15:29:22 UTC

[GitHub] [nuttx] xiaoxiang781216 opened a new pull request, #7776: Minor change for video framebuff

xiaoxiang781216 opened a new pull request, #7776:
URL: https://github.com/apache/nuttx/pull/7776

   ## Summary
   
   - drivers/video: Zero all video_framebuff_t fields in video_framebuff_init
   - drivers/video: Remove the redundant vbuf_alloced != NULL check from video_framebuff_realloc_container
   - drivers/video: Clear the internal state if video_framebuff_realloc_container fail
   
   ## Impact
   
   Minor
   
   ## Testing
   
   Pass CI


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#discussion_r1041755219


##########
drivers/video/video_framebuff.c:
##########
@@ -114,35 +95,28 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)
 {
-  if (fbuf->vbuf_alloced == NULL || fbuf->container_size != sz)
-    {
-      if (fbuf->container_size != sz)
-        {
-          if (fbuf->vbuf_alloced != NULL)
-            {
-              kmm_free(fbuf->vbuf_alloced);
-            }
+  vbuf_container_t *vbuf;
 
-          fbuf->vbuf_alloced   = NULL;
-          fbuf->container_size = 0;
-        }
-
-      if (sz > 0)
-        {
-          fbuf->vbuf_alloced
-           = (vbuf_container_t *)kmm_malloc(sizeof(vbuf_container_t)*sz);
-          if (fbuf->vbuf_alloced == NULL)
-            {
-              return -ENOMEM;
-            }
-        }
+  if (fbuf->container_size == sz)
+    {
+      return OK;
+    }
 
-      fbuf->container_size = sz;
+  vbuf = kmm_realloc(fbuf->vbuf_alloced, sizeof(vbuf_container_t) * sz);
+  if (vbuf != NULL)
+    {
+      memset(vbuf, 0, sizeof(vbuf_container_t) * sz);
+    }
+  else if (sz != 0)
+    {
+      return -ENOMEM;
     }
 
-  cleanup_container(fbuf);
+  fbuf->vbuf_alloced = vbuf;
+  fbuf->container_size = sz;
 
-  return OK;
+  init_buf_chain(fbuf);
+  return ret;
 }
 
 vbuf_container_t *video_framebuff_get_container(video_framebuff_t *fbuf)

Review Comment:
   ditto



##########
drivers/video/video_framebuff.c:
##########
@@ -114,35 +95,28 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)
 {
-  if (fbuf->vbuf_alloced == NULL || fbuf->container_size != sz)
-    {
-      if (fbuf->container_size != sz)
-        {
-          if (fbuf->vbuf_alloced != NULL)
-            {
-              kmm_free(fbuf->vbuf_alloced);
-            }
+  vbuf_container_t *vbuf;

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#discussion_r1041613329


##########
drivers/video/video_framebuff.c:
##########
@@ -114,35 +95,28 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)
 {
-  if (fbuf->vbuf_alloced == NULL || fbuf->container_size != sz)
-    {
-      if (fbuf->container_size != sz)
-        {
-          if (fbuf->vbuf_alloced != NULL)
-            {
-              kmm_free(fbuf->vbuf_alloced);
-            }
+  vbuf_container_t *vbuf;
 
-          fbuf->vbuf_alloced   = NULL;
-          fbuf->container_size = 0;
-        }
-
-      if (sz > 0)
-        {
-          fbuf->vbuf_alloced
-           = (vbuf_container_t *)kmm_malloc(sizeof(vbuf_container_t)*sz);
-          if (fbuf->vbuf_alloced == NULL)
-            {
-              return -ENOMEM;
-            }
-        }
+  if (fbuf->container_size == sz)
+    {
+      return OK;
+    }
 
-      fbuf->container_size = sz;
+  vbuf = kmm_realloc(fbuf->vbuf_alloced, sizeof(vbuf_container_t) * sz);
+  if (vbuf != NULL)
+    {
+      memset(vbuf, 0, sizeof(vbuf_container_t) * sz);
+    }
+  else if (sz != 0)
+    {
+      return -ENOMEM;
     }
 
-  cleanup_container(fbuf);
+  fbuf->vbuf_alloced = vbuf;
+  fbuf->container_size = sz;
 
-  return OK;
+  init_buf_chain(fbuf);
+  return ret;

Review Comment:
   ```suggestion
     return OK;
   ```



##########
drivers/video/video_framebuff.c:
##########
@@ -46,24 +46,13 @@ static void init_buf_chain(video_framebuff_t *fbuf)
   fbuf->vbuf_tail  = NULL;
 
   tmp = fbuf->vbuf_alloced;
-  for (i = 0; i < fbuf->container_size - 1; i++)
+  for (i = 1; i < fbuf->container_size; i++)
     {
       tmp->next = &tmp[1];
       tmp++;
     }
 }
 
-static void cleanup_container(video_framebuff_t *fbuf)
-{
-  if (fbuf->vbuf_alloced)
-    {
-      memset(fbuf->vbuf_alloced,
-             0,
-             sizeof(vbuf_container_t)*fbuf->container_size);
-      init_buf_chain(fbuf);
-    }
-}
-
 static inline int is_last_one(video_framebuff_t *fbuf)

Review Comment:
   ```suggestion
   static inline int is_last_one(FAR video_framebuff_t *fbuf)
   ```



##########
drivers/video/video_framebuff.c:
##########
@@ -97,12 +82,8 @@ static inline vbuf_container_t *dequeue_vbuf_unsafe(video_framebuff_t *fbuf)
 
 void video_framebuff_init(video_framebuff_t *fbuf)

Review Comment:
   ```suggestion
   void video_framebuff_init(FAR video_framebuff_t *fbuf)
   ```



##########
drivers/video/video_framebuff.c:
##########
@@ -114,35 +95,28 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)
 {
-  if (fbuf->vbuf_alloced == NULL || fbuf->container_size != sz)
-    {
-      if (fbuf->container_size != sz)
-        {
-          if (fbuf->vbuf_alloced != NULL)
-            {
-              kmm_free(fbuf->vbuf_alloced);
-            }
+  vbuf_container_t *vbuf;

Review Comment:
   ```suggestion
     FAR vbuf_container_t *vbuf;
   ```



##########
drivers/video/video_framebuff.c:
##########
@@ -114,35 +95,28 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)
 {
-  if (fbuf->vbuf_alloced == NULL || fbuf->container_size != sz)
-    {
-      if (fbuf->container_size != sz)
-        {
-          if (fbuf->vbuf_alloced != NULL)
-            {
-              kmm_free(fbuf->vbuf_alloced);
-            }
+  vbuf_container_t *vbuf;
 
-          fbuf->vbuf_alloced   = NULL;
-          fbuf->container_size = 0;
-        }
-
-      if (sz > 0)
-        {
-          fbuf->vbuf_alloced
-           = (vbuf_container_t *)kmm_malloc(sizeof(vbuf_container_t)*sz);
-          if (fbuf->vbuf_alloced == NULL)
-            {
-              return -ENOMEM;
-            }
-        }
+  if (fbuf->container_size == sz)
+    {
+      return OK;
+    }
 
-      fbuf->container_size = sz;
+  vbuf = kmm_realloc(fbuf->vbuf_alloced, sizeof(vbuf_container_t) * sz);
+  if (vbuf != NULL)
+    {
+      memset(vbuf, 0, sizeof(vbuf_container_t) * sz);
+    }
+  else if (sz != 0)
+    {
+      return -ENOMEM;
     }
 
-  cleanup_container(fbuf);
+  fbuf->vbuf_alloced = vbuf;
+  fbuf->container_size = sz;
 
-  return OK;
+  init_buf_chain(fbuf);
+  return ret;
 }
 
 vbuf_container_t *video_framebuff_get_container(video_framebuff_t *fbuf)

Review Comment:
   ```suggestion
   vbuf_container_t *video_framebuff_get_container(FAR video_framebuff_t *fbuf)
   ```



##########
drivers/video/video_framebuff.c:
##########
@@ -114,35 +95,28 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)

Review Comment:
   ```suggestion
   int video_framebuff_realloc_container(FAR video_framebuff_t *fbuf, int sz)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#discussion_r1043167937


##########
drivers/video/video_framebuff.c:
##########
@@ -114,34 +95,27 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)
 {
-  if (fbuf->vbuf_alloced == NULL || fbuf->container_size != sz)
-    {
-      if (fbuf->container_size != sz)
-        {
-          if (fbuf->vbuf_alloced != NULL)
-            {
-              kmm_free(fbuf->vbuf_alloced);
-            }
+  vbuf_container_t *vbuf;
 
-          fbuf->vbuf_alloced   = NULL;
-          fbuf->container_size = 0;
-        }
-
-      if (sz > 0)
-        {
-          fbuf->vbuf_alloced
-           = (vbuf_container_t *)kmm_malloc(sizeof(vbuf_container_t)*sz);
-          if (fbuf->vbuf_alloced == NULL)
-            {
-              return -ENOMEM;
-            }
-        }
+  if (fbuf->container_size == sz)
+    {
+      return OK;
+    }
 
-      fbuf->container_size = sz;
+  vbuf = kmm_realloc(fbuf->vbuf_alloced, sizeof(vbuf_container_t) * sz);

Review Comment:
   Zero mean free and return null pointer which is the standard behavior required by realloc:
   https://github.com/apache/nuttx/blob/master/mm/mm_heap/mm_realloc.c#L85-L89
   This is also the reason why the following code check sz != 0 before return -ENOMEM:
   https://github.com/apache/nuttx/pull/7776/files#diff-ce724983e0699b4ea65c8509598f6b6d31e824418383f5efb12a279cb932d8f1R110-R113



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#discussion_r1043138737


##########
drivers/video/video_framebuff.c:
##########
@@ -97,12 +82,8 @@ static inline vbuf_container_t *dequeue_vbuf_unsafe(video_framebuff_t *fbuf)
 
 void video_framebuff_init(video_framebuff_t *fbuf)
 {
-  fbuf->mode       = V4L2_BUF_MODE_RING;
-  fbuf->vbuf_empty = NULL;
-  fbuf->vbuf_top   = NULL;
-  fbuf->vbuf_tail  = NULL;
-  fbuf->vbuf_next  = NULL;
-
+  memset(fbuf, 0, sizeof(*fbuf));

Review Comment:
   optional
   ```suggestion
     memset(fbuf, 0, sizeof(video_framebuff_t));
   ```



##########
drivers/video/video_framebuff.c:
##########
@@ -114,34 +95,27 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)
 {
-  if (fbuf->vbuf_alloced == NULL || fbuf->container_size != sz)
-    {
-      if (fbuf->container_size != sz)
-        {
-          if (fbuf->vbuf_alloced != NULL)
-            {
-              kmm_free(fbuf->vbuf_alloced);
-            }
+  vbuf_container_t *vbuf;
 
-          fbuf->vbuf_alloced   = NULL;
-          fbuf->container_size = 0;
-        }
-
-      if (sz > 0)
-        {
-          fbuf->vbuf_alloced
-           = (vbuf_container_t *)kmm_malloc(sizeof(vbuf_container_t)*sz);
-          if (fbuf->vbuf_alloced == NULL)
-            {
-              return -ENOMEM;
-            }
-        }
+  if (fbuf->container_size == sz)
+    {
+      return OK;
+    }
 
-      fbuf->container_size = sz;
+  vbuf = kmm_realloc(fbuf->vbuf_alloced, sizeof(vbuf_container_t) * sz);

Review Comment:
   what if `sz` is zero?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#discussion_r1041755219


##########
drivers/video/video_framebuff.c:
##########
@@ -114,35 +95,28 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)
 {
-  if (fbuf->vbuf_alloced == NULL || fbuf->container_size != sz)
-    {
-      if (fbuf->container_size != sz)
-        {
-          if (fbuf->vbuf_alloced != NULL)
-            {
-              kmm_free(fbuf->vbuf_alloced);
-            }
+  vbuf_container_t *vbuf;
 
-          fbuf->vbuf_alloced   = NULL;
-          fbuf->container_size = 0;
-        }
-
-      if (sz > 0)
-        {
-          fbuf->vbuf_alloced
-           = (vbuf_container_t *)kmm_malloc(sizeof(vbuf_container_t)*sz);
-          if (fbuf->vbuf_alloced == NULL)
-            {
-              return -ENOMEM;
-            }
-        }
+  if (fbuf->container_size == sz)
+    {
+      return OK;
+    }
 
-      fbuf->container_size = sz;
+  vbuf = kmm_realloc(fbuf->vbuf_alloced, sizeof(vbuf_container_t) * sz);
+  if (vbuf != NULL)
+    {
+      memset(vbuf, 0, sizeof(vbuf_container_t) * sz);
+    }
+  else if (sz != 0)
+    {
+      return -ENOMEM;
     }
 
-  cleanup_container(fbuf);
+  fbuf->vbuf_alloced = vbuf;
+  fbuf->container_size = sz;
 
-  return OK;
+  init_buf_chain(fbuf);
+  return ret;
 }
 
 vbuf_container_t *video_framebuff_get_container(video_framebuff_t *fbuf)

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko merged pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
pkarashchenko merged PR #7776:
URL: https://github.com/apache/nuttx/pull/7776


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#discussion_r1041706459


##########
drivers/video/video_framebuff.c:
##########
@@ -46,24 +46,13 @@ static void init_buf_chain(video_framebuff_t *fbuf)
   fbuf->vbuf_tail  = NULL;
 
   tmp = fbuf->vbuf_alloced;
-  for (i = 0; i < fbuf->container_size - 1; i++)
+  for (i = 1; i < fbuf->container_size; i++)
     {
       tmp->next = &tmp[1];
       tmp++;
     }
 }
 
-static void cleanup_container(video_framebuff_t *fbuf)
-{
-  if (fbuf->vbuf_alloced)
-    {
-      memset(fbuf->vbuf_alloced,
-             0,
-             sizeof(vbuf_container_t)*fbuf->container_size);
-      init_buf_chain(fbuf);
-    }
-}
-
 static inline int is_last_one(video_framebuff_t *fbuf)

Review Comment:
   @pkarashchenko since the whole video_framebuff.* doesn't add FAR, it's better to do FAR addition to the new patch.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#discussion_r1043200862


##########
drivers/video/video_framebuff.c:
##########
@@ -97,12 +82,8 @@ static inline vbuf_container_t *dequeue_vbuf_unsafe(video_framebuff_t *fbuf)
 
 void video_framebuff_init(video_framebuff_t *fbuf)
 {
-  fbuf->mode       = V4L2_BUF_MODE_RING;
-  fbuf->vbuf_empty = NULL;
-  fbuf->vbuf_top   = NULL;
-  fbuf->vbuf_tail  = NULL;
-  fbuf->vbuf_next  = NULL;
-
+  memset(fbuf, 0, sizeof(*fbuf));

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#issuecomment-1348227218

   @pkarashchenko could you merge this pr?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#discussion_r1041755109


##########
drivers/video/video_framebuff.c:
##########
@@ -97,12 +82,8 @@ static inline vbuf_container_t *dequeue_vbuf_unsafe(video_framebuff_t *fbuf)
 
 void video_framebuff_init(video_framebuff_t *fbuf)

Review Comment:
   ditto



##########
drivers/video/video_framebuff.c:
##########
@@ -114,35 +95,28 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#discussion_r1039360580


##########
drivers/video/video_framebuff.c:
##########
@@ -114,40 +95,41 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)
 {
+  int ret = OK;
+
   if (sz > V4L2_REQBUFS_COUNT_MAX)
     {
       return -EINVAL;
     }
 
-  if (fbuf->vbuf_alloced == NULL || fbuf->container_size != sz)
+  if (fbuf->container_size == sz)
     {
-      if (fbuf->container_size != sz)
-        {
-          if (fbuf->vbuf_alloced != NULL)
-            {
-              kmm_free(fbuf->vbuf_alloced);
-            }
+      return OK;
+    }
 
-          fbuf->vbuf_alloced   = NULL;
-          fbuf->container_size = 0;
-        }
+  if (fbuf->vbuf_alloced != NULL)
+    {
+      kmm_free(fbuf->vbuf_alloced);
+      fbuf->vbuf_alloced   = NULL;
+      fbuf->container_size = 0;
+    }
 
-      if (sz > 0)
+  if (sz > 0)
+    {
+      fbuf->vbuf_alloced =
+        (vbuf_container_t *)kmm_zalloc(sizeof(vbuf_container_t) * sz);

Review Comment:
   do we need type cast here?
   also maybe use `kmm_calloc`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#discussion_r1039499272


##########
drivers/video/video_framebuff.c:
##########
@@ -114,40 +95,41 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)
 {
+  int ret = OK;
+
   if (sz > V4L2_REQBUFS_COUNT_MAX)
     {
       return -EINVAL;
     }
 
-  if (fbuf->vbuf_alloced == NULL || fbuf->container_size != sz)
+  if (fbuf->container_size == sz)
     {
-      if (fbuf->container_size != sz)
-        {
-          if (fbuf->vbuf_alloced != NULL)
-            {
-              kmm_free(fbuf->vbuf_alloced);
-            }
+      return OK;
+    }
 
-          fbuf->vbuf_alloced   = NULL;
-          fbuf->container_size = 0;
-        }
+  if (fbuf->vbuf_alloced != NULL)
+    {
+      kmm_free(fbuf->vbuf_alloced);
+      fbuf->vbuf_alloced   = NULL;
+      fbuf->container_size = 0;
+    }
 
-      if (sz > 0)
+  if (sz > 0)
+    {
+      fbuf->vbuf_alloced =
+        (vbuf_container_t *)kmm_zalloc(sizeof(vbuf_container_t) * sz);

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#discussion_r1041693534


##########
drivers/video/video_framebuff.c:
##########
@@ -114,35 +95,28 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)
 {
-  if (fbuf->vbuf_alloced == NULL || fbuf->container_size != sz)
-    {
-      if (fbuf->container_size != sz)
-        {
-          if (fbuf->vbuf_alloced != NULL)
-            {
-              kmm_free(fbuf->vbuf_alloced);
-            }
+  vbuf_container_t *vbuf;
 
-          fbuf->vbuf_alloced   = NULL;
-          fbuf->container_size = 0;
-        }
-
-      if (sz > 0)
-        {
-          fbuf->vbuf_alloced
-           = (vbuf_container_t *)kmm_malloc(sizeof(vbuf_container_t)*sz);
-          if (fbuf->vbuf_alloced == NULL)
-            {
-              return -ENOMEM;
-            }
-        }
+  if (fbuf->container_size == sz)
+    {
+      return OK;
+    }
 
-      fbuf->container_size = sz;
+  vbuf = kmm_realloc(fbuf->vbuf_alloced, sizeof(vbuf_container_t) * sz);
+  if (vbuf != NULL)
+    {
+      memset(vbuf, 0, sizeof(vbuf_container_t) * sz);
+    }
+  else if (sz != 0)
+    {
+      return -ENOMEM;
     }
 
-  cleanup_container(fbuf);
+  fbuf->vbuf_alloced = vbuf;
+  fbuf->container_size = sz;
 
-  return OK;
+  init_buf_chain(fbuf);
+  return ret;

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7776: Minor change for video framebuff

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7776:
URL: https://github.com/apache/nuttx/pull/7776#discussion_r1043167937


##########
drivers/video/video_framebuff.c:
##########
@@ -114,34 +95,27 @@ void video_framebuff_uninit(video_framebuff_t *fbuf)
 
 int video_framebuff_realloc_container(video_framebuff_t *fbuf, int sz)
 {
-  if (fbuf->vbuf_alloced == NULL || fbuf->container_size != sz)
-    {
-      if (fbuf->container_size != sz)
-        {
-          if (fbuf->vbuf_alloced != NULL)
-            {
-              kmm_free(fbuf->vbuf_alloced);
-            }
+  vbuf_container_t *vbuf;
 
-          fbuf->vbuf_alloced   = NULL;
-          fbuf->container_size = 0;
-        }
-
-      if (sz > 0)
-        {
-          fbuf->vbuf_alloced
-           = (vbuf_container_t *)kmm_malloc(sizeof(vbuf_container_t)*sz);
-          if (fbuf->vbuf_alloced == NULL)
-            {
-              return -ENOMEM;
-            }
-        }
+  if (fbuf->container_size == sz)
+    {
+      return OK;
+    }
 
-      fbuf->container_size = sz;
+  vbuf = kmm_realloc(fbuf->vbuf_alloced, sizeof(vbuf_container_t) * sz);

Review Comment:
   Zero mean free and return null pointer which is the standard behavior required by realloc:
   https://github.com/apache/nuttx/blob/master/mm/mm_heap/mm_realloc.c#L85-L89
   This is the reason why the following code check sz != 0 before return -ENOMEM:
   https://github.com/apache/nuttx/pull/7776/files#diff-ce724983e0699b4ea65c8509598f6b6d31e824418383f5efb12a279cb932d8f1R110-R113



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org