[rtems commit] libblock: PR2040: Avoid NULL pointer access

Sebastian Huber sebh at rtems.org
Fri Aug 23 07:25:00 UTC 2013


Module:    rtems
Branch:    master
Commit:    dbdfc78fc72d71a3c1544ede34d1c831d4891f02
Changeset: http://git.rtems.org/rtems/commit/?id=dbdfc78fc72d71a3c1544ede34d1c831d4891f02

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Aug 23 09:02:40 2013 +0200

libblock: PR2040: Avoid NULL pointer access

This partly reverts commit 08b9d534604fbf437743a9925ef28eb1b848510d.

Avoid a NULL pointer access and perform the source segment erase if
necessary.

---

 cpukit/libblock/src/flashdisk.c |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/cpukit/libblock/src/flashdisk.c b/cpukit/libblock/src/flashdisk.c
index ccea2e6..9580dde 100644
--- a/cpukit/libblock/src/flashdisk.c
+++ b/cpukit/libblock/src/flashdisk.c
@@ -1266,12 +1266,6 @@ rtems_fdisk_recycle_segment (rtems_flashdisk*         fd,
   {
     rtems_fdisk_page_desc* spd = &ssc->page_descriptors[spage];
 
-    if (!dsc && ssc->pages_active > 0)
-    {
-      rtems_fdisk_error ("recycle: no available dst segment");
-      return EIO;
-    }
-
     if (rtems_fdisk_page_desc_flags_set (spd, RTEMS_FDISK_PAGE_ACTIVE) &&
         !rtems_fdisk_page_desc_flags_set (spd, RTEMS_FDISK_PAGE_USED))
     {
@@ -1361,7 +1355,23 @@ rtems_fdisk_recycle_segment (rtems_flashdisk*         fd,
        */
       dst_pages = rtems_fdisk_seg_pages_available (dsc);
       if (dst_pages == 0)
+      {
         dsc = rtems_fdisk_seg_most_available (&fd->available);
+        if (!dsc)
+        {
+          if (ssc->pages_active == 0)
+          {
+            ret = rtems_fdisk_erase_segment (fd, ssc);
+          }
+          else
+          {
+            rtems_fdisk_error ("recycle: no available dst segment");
+            ret = EIO;
+          }
+
+          return ret;
+        }
+      }
 
       (*pages)--;
     }




More information about the vc mailing list