@@ -121,8 +121,8 @@ static int nfPartition_CheckDataRange(whNvmFlashContext* context,
121121 uint32_t byte_offset ,
122122 uint32_t byte_count );
123123
124- static uint32_t nfObject_Offset (whNvmFlashContext * context , int partition ,
125- int object_index );
124+ static int nfObject_Offset (whNvmFlashContext * context , int partition ,
125+ int object_index , uint32_t * out_object_offset );
126126static int nfObject_ProgramBegin (whNvmFlashContext * context , int partition ,
127127 int object_index , uint32_t epoch , uint32_t start , whNvmMetadata * meta );
128128static int nfObject_ProgramDataBytes (whNvmFlashContext * context , int partition ,
@@ -512,16 +512,19 @@ static int nfPartition_CheckDataRange(whNvmFlashContext* context,
512512 return WH_ERROR_OK ;
513513}
514514
515- static uint32_t nfObject_Offset (whNvmFlashContext * context , int partition ,
516- int object_index )
515+ static int nfObject_Offset (whNvmFlashContext * context , int partition ,
516+ int object_index , uint32_t * out_object_offset )
517517{
518- if (context == NULL ) {
518+ if (context == NULL || out_object_offset == NULL ) {
519519 return WH_ERROR_BADARGS ;
520520 }
521521
522- return nfPartition_Offset (context ,partition ) +
523- NF_PARTITION_DIRECTORY_OFFSET +
524- NF_DIRECTORY_OBJECT_OFFSET (object_index );
522+
523+ * out_object_offset = nfPartition_Offset (context ,partition ) +
524+ NF_PARTITION_DIRECTORY_OFFSET +
525+ NF_DIRECTORY_OBJECT_OFFSET (object_index );
526+
527+ return WH_ERROR_OK ;
525528}
526529
527530static int nfObject_ProgramBegin (whNvmFlashContext * context , int partition ,
@@ -539,7 +542,10 @@ static int nfObject_ProgramBegin(whNvmFlashContext* context, int partition,
539542 return WH_ERROR_BADARGS ;
540543 }
541544
542- object_offset = nfObject_Offset (context , partition , object_index );
545+ rc = nfObject_Offset (context , partition , object_index , & object_offset );
546+ if (rc != WH_ERROR_OK ) {
547+ return rc ;
548+ }
543549
544550 /* Program the object epoch */
545551 rc = wh_FlashUnit_Program (
@@ -601,14 +607,18 @@ static int nfObject_ProgramDataBytes(whNvmFlashContext* context, int partition,
601607static int nfObject_ProgramFinish (whNvmFlashContext * context , int partition ,
602608 int object_index , uint32_t byte_count )
603609{
610+ int rc ;
604611 uint32_t object_offset = 0 ;
605612 whFlashUnit state_count = BASE_STATE | WHFU_BYTES2UNITS (byte_count );
606613
607614 if ((context == NULL ) || (context -> cb == NULL )) {
608615 return WH_ERROR_BADARGS ;
609616 }
610617
611- object_offset = nfObject_Offset (context , partition , object_index );
618+ rc = nfObject_Offset (context , partition , object_index , & object_offset );
619+ if (rc != WH_ERROR_OK ) {
620+ return rc ;
621+ }
612622
613623 /* Program the object flag->state_count */
614624 return wh_FlashUnit_Program (
0 commit comments