On Friday 13 February 2009 20:29, Sebastian Andrzej Siewior wrote:
> +static struct jffs2_unknown_node cleanmarker;
> +int target_endian = __BYTE_ORDER;
> +static uint32_t *crc32_table;

It's best to eliminate global variables.

> +int flash_eraseall_main(int argc, char **argv);
> +int flash_eraseall_main(int argc, char **argv)
> +{
> +     int quiet;
> +     int jffs2;
> +     mtd_info_t meminfo;
> +     int fd, clmpos = 0, clmlen = 8;
> +     erase_info_t erase;
> +     struct stat st;
> +     int isNAND, bbtest = 1;
> +     unsigned int flags;
> +     char *mtd_name;
> +
> +     if (argc < 2) {
> +             bb_show_usage();
> +     }

This can be achieved with opt_complementary = "..."

> +     flags = getopt32(argv, "jq");
> +     jffs2 = flags & OPTION_J;
> +     quiet = flags & OPTION_Q;

What's the point? You can just use (flags & OPTION_J) instead of jffs2
in the code below?

> +     mtd_name = *(argv + optind);
> +
> +     xstat(mtd_name, &st);

SEGV. mtd_name can be NULL here.

> +     if (!S_ISCHR(st.st_mode)) {
> +             bb_error_msg_and_die("%s: not a char device", mtd_name);
> +     }
> +
> +     fd = xopen(mtd_name, O_RDWR);
> +
> +     xioctl(fd, MEMGETINFO, &meminfo);
> +
> +     erase.length = meminfo.erasesize;
> +     isNAND = meminfo.type == MTD_NANDFLASH ? 1 : 0;
> +
> +     if (jffs2) {
> +             crc32_table = crc32_filltable(NULL, 0);
> +
> +             cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
> +             cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
> +             if (!isNAND)
> +                     cleanmarker.totlen = cpu_to_je32 (sizeof (struct 
> jffs2_unknown_node));
> +             else {
> +                     struct nand_oobinfo oobinfo;
> +
> +                     xioctl(fd, MEMGETOOBSEL, &oobinfo);
> +
> +                     /* Check for autoplacement */
> +                     if (oobinfo.useecc == MTD_NANDECC_AUTOPLACE) {
> +                             /* Get the position of the free bytes */
> +                             if (!oobinfo.oobfree[0][1]) {
> +                                     fprintf (stderr, " Eeep. Autoplacement 
> selected and no empty space in oob\n");

We have bb_error_msg("...") for that.
" Eeep. " is bloat and should be dropped.

--
vda
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to