diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-08-23 09:02:40 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-08-23 09:24:10 +0200 |
commit | dbdfc78fc72d71a3c1544ede34d1c831d4891f02 (patch) | |
tree | ef0c1488b4aad944fdc36d765b82343ed1253046 /cpukit/libblock/src | |
parent | libtests/flashdisk01: Update screen file (diff) | |
download | rtems-dbdfc78fc72d71a3c1544ede34d1c831d4891f02.tar.bz2 |
libblock: PR2040: Avoid NULL pointer access
This partly reverts commit 08b9d534604fbf437743a9925ef28eb1b848510d.
Avoid a NULL pointer access and perform the source segment erase if
necessary.
Diffstat (limited to '')
-rw-r--r-- | 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 ccea2e6a34..9580dde8e4 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)--; } |