[En-Nut-Discussion] Fix in PhatVol

Krzysztof Sawicki krzysztof.sawicki at mobile.put.edu.pl
Mon Sep 15 12:25:55 CEST 2014


Hi!

In function PhatVolUnmount
we see:

int PhatVolUnmount(NUTDEVICE * dev)
{
     PHATVOL *vol = (PHATVOL *) dev->dev_dcb;

     if (vol) {
#if PHAT_SECTOR_BUFFERS
         int sbn;

         for (sbn = 0; sbn < PHAT_SECTOR_BUFFERS; sbn++) {
             if (vol->vol_buf[sbn].sect_data) {
                 free(vol->vol_buf[sbn].sect_data);
             }
         }
#endif
         free(vol);
         dev->dev_dcb = 0;
     }
     return 0;
}

at the beginning we check vol against zero, but we don't set it to zero after successful unmounting, thus I suggest the following patch (by the way, 2 
letter-fixes)

Index: nut/fs/phatvol.c
===================================================================
--- nut/fs/phatvol.c	(revision 5820)
+++ nut/fs/phatvol.c	(working copy)
@@ -126,7 +126,7 @@
      PHATVOL *vol = (PHATVOL *) dev->dev_dcb;

      if (vol->vol_type == 32) {
-        /* Use fast verion for FAT32. */
+        /* Use fast version for FAT32. */
          rc = Phat32FreeClusters(dev);
      } else if (vol->vol_type == 16) {
          while (i < vol->vol_last_clust) {
@@ -243,7 +243,7 @@

      /*
       * PHAT32 doesn't have a fixed root directory. At this point
-     * we reliably know wether we got PHAT32 or not. After having
+     * we reliably know whether we got PHAT32 or not. After having
       * determined the total number of clusters later, we can check
       * for PHAT12 or PHAT16.
       */
@@ -375,6 +375,7 @@
          }
  #endif
          free(vol);
+        dev->dev_dcb = 0;
      }
      return 0;
  }

-- 
Krzysztof Sawicki
Mobile Systems Research Labs, Poznan University of Technology


More information about the En-Nut-Discussion mailing list