Prakhar Kumar commented on a discussion on cpukit/libblock/src/flashdisk.c: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/912#note_140011

 >  
 >    return RTEMS_SUCCESSFUL;
 >  }
 > +
 > +static void rtems_fdisk_cleanup_helper (rtems_flashdisk *fd, bool 
 > *mutex_initialized)
 > +{
 > +  uint32_t device;
 > +
 > +  if(fd == NULL)
 > +    return;
 > +  
 > +  if((*mutex_initialized) == false) {
 > +    (*mutex_initialized) = true;
 > +  } else {
 > +    rtems_mutex_destroy(&fd->lock);

So i am tracking the mutex initialization with the boolean, setting it true if 
the error occurs after the initialization and false before the initialization. 
And the memory cleanup is done backwards i.e, from the current iteration to the 
backward so if error occurs in the current iteration before the mutex is 
initialized, It just need to skip the mutex destruction only for the current 
iteration and destroy for every previous iteration. 

I also thought of using " const char \*rtems_mutex_get_name( const rtems_mutex 
\*mutex ); " as a validator for mutex being initialized or not, like the mutex 
is being initialized like " rtems_mutex_init(&fd-\>lock, "Flash Disk") " so a 
name is set. 

So during the memory cleanup i can check if the name returned by get_name 
function is same as the name set during the initialization. By doing this, the 
logic will not rely on simply assuming that in the previous iterations the 
initialization was done, it will also check for each fds.

One thing is that the name can be set to null also. (i first need to test the 
logic).

I just need a review on my approach. @chris

-- 
View it on GitLab: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/912#note_140011
You're receiving this email because of your account on gitlab.rtems.org.


_______________________________________________
bugs mailing list
[email protected]
http://lists.rtems.org/mailman/listinfo/bugs

Reply via email to