]> www.infradead.org Git - mtd-utils.git/commitdiff
[MTD] UBI Utils: Fix pfiflash
authorFrank Haverkamp <haver@vnet.ibm.com>
Mon, 11 Dec 2006 13:34:23 +0000 (14:34 +0100)
committerFrank Haverkamp <haver@vnet.ibm.com>
Mon, 11 Dec 2006 13:34:23 +0000 (14:34 +0100)
Various little fixes including some whitespace fixups.

Signed-off-by: Frank Haverkamp <haver@vnet.ibm.com>
ubi-utils/src/libpfiflash.c
ubi-utils/src/pfiflash.c

index dd552030cd015a75c654d6394a7446766d2cb75b..0be1f2cbd20bcbd7acf1dacae83fa623da72356f 100644 (file)
@@ -593,6 +593,8 @@ process_raw_volumes(FILE* pfi, list_t pfi_raws, const char* rawdev,
 
        rc = 0;
 
+       pfi_data = NULL;
+
        log_msg("[ rawupdate dev=%s", rawdev);
 
        crc = UBI_CRC32_INIT;
@@ -603,6 +605,8 @@ process_raw_volumes(FILE* pfi, list_t pfi_raws, const char* rawdev,
                pfi_raw_t r = (pfi_raw_t)i;
 
                /* read in pfi data */
+               if (pfi_data != NULL)
+                       free(pfi_data);
                pfi_data = malloc(r->data_size * sizeof(char));
                for (j = 0; j < r->data_size; j++) {
                        int c = fgetc(pfi);
@@ -629,7 +633,7 @@ process_raw_volumes(FILE* pfi, list_t pfi_raws, const char* rawdev,
                /* open device */
                mtd = fopen(rawdev, "r+");
                if (mtd == NULL) {
-                       rc = PFIFLASH_ERR_MTD_OPEN;
+                       rc = -PFIFLASH_ERR_MTD_OPEN;
                        EBUF(PFIFLASH_ERRSTR[-rc], rawdev);
                        goto err;
                }
@@ -642,11 +646,12 @@ process_raw_volumes(FILE* pfi, list_t pfi_raws, const char* rawdev,
                                        fclose(mtd);
                                        rc = -PFIFLASH_ERR_EOF;
                                        EBUF(PFIFLASH_ERRSTR[-rc]);
-                                       return rc;
+                                       goto err;
                                }
                                if ((char)c != pfi_data[k]) {
                                        fclose(mtd);
-                                       return -1;
+                                       rc = -1;
+                                       goto err;
                                }
                        }
                }
@@ -659,6 +664,8 @@ process_raw_volumes(FILE* pfi, list_t pfi_raws, const char* rawdev,
        }
 
  err:
+       if (pfi_data != NULL)
+               free(pfi_data);
        return rc;
 }
 
@@ -692,7 +699,7 @@ erase_unmapped_ubi_volumes(int devno, list_t pfi_ubis,
        foreach(u, ptr, pfi_ubis) {
                /* iterate over each vol_id */
                for(i = 0; i < u->ids_size; i++) {
-                       if (u->ids[i] > PFI_UBI_MAX_VOLUMES) {
+                       if (u->ids[i] >= PFI_UBI_MAX_VOLUMES) {
                                rc = -PFIFLASH_ERR_UBI_VID_OOB;
                                EBUF(PFIFLASH_ERRSTR[-rc], u->ids[i]);
                                goto err;
index c654be970e769ba3cdc68533d80c0f1acd43af89..259a647449f81703058005392ee0c744faf67652 100644 (file)
@@ -23,6 +23,8 @@
  * update using PFI files.
  *
  * 1.1 fixed output to stderr and stdout in logfile mode.
+ * 1.2 updated.
+ * 1.3 removed argp parsing to be able to use uClib.
  */
 
 #include <unistd.h>
@@ -39,7 +41,7 @@
 #include "error.h"
 #include "config.h"
 
-#define PROGRAM_VERSION  "1.2"
+#define PROGRAM_VERSION  "1.3"
 
 extern char *optarg;
 extern int optind;
@@ -141,7 +143,8 @@ parse_opt(int argc, char **argv, myargs *args)
        while (1) {
                int key;
 
-               key = getopt_long(argc, argv, "cl:vCp:r:s:?V", long_options, NULL);
+               key = getopt_long(argc, argv, "cl:vCp:r:s:?V",
+                                 long_options, NULL);
                if (key == -1)
                        break;
 
@@ -165,15 +168,17 @@ parse_opt(int argc, char **argv, myargs *args)
                                args->pdd_handling = get_pdd_handling(optarg);
                                if ((int)args->pdd_handling < 0) {
                                        err_quit("Unknown PDD handling: %s.\n"
-                                                       "Please use either 'keep', 'merge' or"
-                                                       "'overwrite'.\n'");
+                                                "Please use either "
+                                                "'keep', 'merge' or"
+                                                "'overwrite'.\n'");
                                }
                                break;
                        case 's':
                                args->seqnum = get_update_seqnum(optarg);
                                if (args->seqnum < 0) {
                                        err_quit("Unsupported side: %s.\n"
-                                                       "Supported sides are '0' and '1'\n", optarg);
+                                                "Supported sides are '0' "
+                                                "and '1'\n", optarg);
                                }
                                break;
                        case 'r':
@@ -183,7 +188,8 @@ parse_opt(int argc, char **argv, myargs *args)
                                err_msg("Usage: pfiflash [OPTION...] [pfifile]");
                                err_msg("%s", doc);
                                err_msg("%s", optionsstr);
-                               err_msg("\nReport bugs to %s\n", PACKAGE_BUGREPORT);
+                               err_msg("\nReport bugs to %s\n",
+                                       PACKAGE_BUGREPORT);
                                exit(0);
                                break;
                        case 'V':
@@ -200,7 +206,8 @@ parse_opt(int argc, char **argv, myargs *args)
        if (optind < argc) {
                args->fp_in = fopen(argv[optind++], "r");
                if ((args->fp_in) == NULL) {
-                       err_sys("Cannot open PFI file %s for input", argv[optind]);
+                       err_sys("Cannot open PFI file %s for input",
+                               argv[optind]);
                }
        }