From: Bernd Moessner <berndmoessne...@gmail.com> Create / update region only if it is aligned to erase size
Updates #4981 --- cpukit/dev/flash/flashdev.c | 14 ++++++++++++++ testsuites/libtests/flashdev01/init.c | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c index d18d14b2f8..8aa4380ab7 100644 --- a/cpukit/dev/flash/flashdev.c +++ b/cpukit/dev/flash/flashdev.c @@ -738,6 +738,13 @@ static int rtems_flashdev_ioctl_create_region( int i; rtems_flashdev_region_table *table = flash->region_table; + /* Region is only valid if it can be erased */ + i = rtems_check_erase_valid(flash, region_in->offset, region_in->size); + if(i < 0) + { + return i; + } + /* Find unallocated region slot */ i = rtems_flashdev_find_unallocated_region(flash->region_table); if (i == RTEMS_FLASHDEV_REGION_ALLOC_FULL) { @@ -764,6 +771,13 @@ static int rtems_flashdev_ioctl_update_region( uint32_t region_index = rtems_flashdev_get_region_index( iop ); rtems_flashdev_region_table *table = flash->region_table; + /* Region is only valid if it can be erased */ + int i = rtems_check_erase_valid(flash, region_in->offset, region_in->size); + if(i < 0) + { + return i; + } + /** * If region index is larger then maximum region index or region * index at given index is undefined return an error. diff --git a/testsuites/libtests/flashdev01/init.c b/testsuites/libtests/flashdev01/init.c index fd3bda769e..5755708525 100644 --- a/testsuites/libtests/flashdev01/init.c +++ b/testsuites/libtests/flashdev01/init.c @@ -221,6 +221,18 @@ static void run_test(void) { fd = fileno(file); + /* Test Regions - this one must fail */ + region.offset = 0x401; + region.size = 0x200; + status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_SET_REGION, ®ion); + rtems_test_assert(status); + + /* Test Regions - this one must fail */ + region.offset = 0x400; + region.size = 0xFF; + status = ioctl(fd, RTEMS_FLASHDEV_IOCTL_SET_REGION, ®ion); + rtems_test_assert(status); + /* Test Regions */ region.offset = 0x400; region.size = 0x200; -- 2.34.1 _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel