Re: [PATCH mmc-utils] Various fixes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



+ Avri

On Tue, 15 Jan 2019 at 15:06, Stephane Fillod <f8cfe@xxxxxxx> wrote:
>
> These warnings were mainly found using cppcheck.
>
> Signed-off-by: Stephane Fillod <f8cfe@xxxxxxx>

Applied to git.kernel.org/pub/scm/utils/mmc/mmc-utils.git master, thanks!

Kind regards
Uffe


> ---
>
> Basically, these are signdness warnings about printf format
> (mainly on 32 bits arch), a few fd leaks (harmless if the programs
> ends afterwards) and 2 typos.
>
>   cppcheck -q $(CPPFLAGS) $(AM_CFLAGS) --enable=warning,style,performance,portability,information --suppress=variableScope: .
>
> diff --git a/lsmmc.c b/lsmmc.c
> index 9737b37..98c0c4d 100644
> --- a/lsmmc.c
> +++ b/lsmmc.c
> @@ -512,9 +544,9 @@ void print_sd_cid(struct config *config, char *cid)
>                 printf("\tOID: %s\n", oid);
>                 printf("\tPNM: %s\n", pnm);
>                 printf("\tPRV: 0x%01x%01x ", prv_major, prv_minor);
> -               printf("(%d.%d)\n", prv_major, prv_minor);
> +               printf("(%u.%u)\n", prv_major, prv_minor);
>                 printf("\tPSN: 0x%08x\n", psn);
> -               printf("\tMDT: 0x%02x%01x %d %s\n", mdt_year, mdt_month,
> +               printf("\tMDT: 0x%02x%01x %u %s\n", mdt_year, mdt_month,
>                        2000 + mdt_year, months[mdt_month]);
>                 printf("\tCRC: 0x%02x\n", crc);
>         } else {
> @@ -524,9 +556,9 @@ void print_sd_cid(struct config *config, char *cid)
>                 else
>                         printf("manufacturer: 'Unlisted' '%s'\n", oid);
>
> -               printf("product: '%s' %d.%d\n", pnm, prv_major, prv_minor);
> +               printf("product: '%s' %u.%u\n", pnm, prv_major, prv_minor);
>                 printf("serial: 0x%08x\n", psn);
> -               printf("manfacturing date: %d %s\n", 2000 + mdt_year,
> +               printf("manufacturing date: %u %s\n", 2000 + mdt_year,
>                        months[mdt_month]);
>         }
>  }
> @@ -583,9 +615,9 @@ void print_mmc_cid(struct config *config, char *cid)
>                 printf("\tOID: 0x%01x\n", oid);
>                 printf("\tPNM: %s\n", pnm);
>                 printf("\tPRV: 0x%01x%01x ", prv_major, prv_minor);
> -               printf("(%d.%d)\n", prv_major, prv_minor);
> +               printf("(%u.%u)\n", prv_major, prv_minor);
>                 printf("\tPSN: 0x%08x\n", psn);
> -               printf("\tMDT: 0x%01x%01x %d %s\n", mdt_month, mdt_year,
> +               printf("\tMDT: 0x%01x%01x %u %s\n", mdt_month, mdt_year,
>                        1997 + mdt_year, months[mdt_month]);
>                 printf("\tCRC: 0x%02x\n", crc);
>         } else {
> @@ -595,9 +627,9 @@ void print_mmc_cid(struct config *config, char *cid)
>                 else
>                         printf("manufacturer: 'Unlisted' '%c'\n", oid);
>
> -               printf("product: '%s' %d.%d\n", pnm, prv_major, prv_minor);
> +               printf("product: '%s' %u.%u\n", pnm, prv_major, prv_minor);
>                 printf("serial: 0x%08x\n", psn);
> -               printf("manfacturing date: %d %s\n", 1997 + mdt_year,
> +               printf("manufacturing date: %u %s\n", 1997 + mdt_year,
>                        months[mdt_month]);
>         }
>  }
> @@ -687,7 +719,7 @@ void print_sd_csd(struct config *config, char *csd)
>
>                 printf("======SD/CSD======\n");
>
> -               printf("\tCSD_STRUCTURE: %d\n", csd_structure);
> +               printf("\tCSD_STRUCTURE: %u\n", csd_structure);
>                 printf("\tTAAC: 0x%02x (", taac);
>
>                 switch (taac_timevalue) {
> @@ -774,7 +806,7 @@ void print_sd_csd(struct config *config, char *csd)
>                 if (csd_structure == 1 && taac != 0x0e)
>                         printf("Warn: Invalid TAAC (should be 0x0e)\n");
>
> -               printf("\tNSAC: %d clocks\n", nsac);
> +               printf("\tNSAC: %u clocks\n", nsac);
>                 if (csd_structure == 1 && nsac != 0x00)
>                         printf("Warn: Invalid NSAC (should be 0x00)\n");
>
> @@ -1061,12 +1093,12 @@ void print_sd_csd(struct config *config, char *csd)
>                         if (erase_blk_en != 0x01)
>                                 printf("Warn: Invalid ERASE_BLK_EN (should be 0x01)\n");
>
> -                       printf("\tSECTOR_SIZE: 0x%02x (Erasable sector: %d blocks)\n",
> +                       printf("\tSECTOR_SIZE: 0x%02x (Erasable sector: %u blocks)\n",
>                                sector_size, sector_size + 1);
>                         if (sector_size != 0x7f)
>                                 printf("Warn: Invalid SECTOR_SIZE (should be 0x7f)\n");
>
> -                       printf("\tWP_GRP_SIZE: 0x%02x (Write protect group: %d blocks)\n",
> +                       printf("\tWP_GRP_SIZE: 0x%02x (Write protect group: %u blocks)\n",
>                                wp_grp_size, wp_grp_size + 1);
>                         if (wp_grp_size != 0x00)
>                                 printf("Warn: Invalid WP_GRP_SIZE (should be 0x00)\n");
> @@ -1075,7 +1107,7 @@ void print_sd_csd(struct config *config, char *csd)
>                         if (wp_grp_enable != 0x00)
>                                 printf("Warn: Invalid WP_GRP_ENABLE (should be 0x00)\n");
>
> -                       printf("\tR2W_FACTOR: 0x%01x (Write %d times read)\n",
> +                       printf("\tR2W_FACTOR: 0x%01x (Write %u times read)\n",
>                                r2w_factor, r2w_factor);
>                         if (r2w_factor != 0x02)
>                                 printf("Warn: Invalid R2W_FACTOR (should be 0x02)\n");
> @@ -1157,7 +1189,7 @@ void print_sd_csd(struct config *config, char *csd)
>                 else
>                         printf("%.2fbyte", memory_capacity * 1.0);
>
> -               printf(" (%lld bytes, %lld sectors, %d bytes each)\n",
> +               printf(" (%llu bytes, %llu sectors, %d bytes each)\n",
>                        memory_capacity, blocks, block_size);
>         } else {
>                 unsigned long long blocks = 0;
> @@ -1220,7 +1252,7 @@ void print_sd_csd(struct config *config, char *csd)
>                 else
>                         printf("%.2fbyte", memory_capacity * 1.0);
>
> -               printf(" (%lld bytes, %lld sectors, %d bytes each)\n",
> +               printf(" (%llu bytes, %llu sectors, %d bytes each)\n",
>                        memory_capacity, blocks, block_size);
>         }
>  }
> @@ -1414,7 +1446,7 @@ void print_mmc_csd(struct config *config, char *csd)
>                         break;
>                 }
>
> -               printf("\tNSAC: %d clocks\n", nsac);
> +               printf("\tNSAC: %u clocks\n", nsac);
>                 printf("\tTRAN_SPEED: 0x%02x (", tran_speed);
>                 switch (tran_speed_timevalue) {
>                 case 0x0:
> @@ -1722,10 +1754,10 @@ void print_mmc_csd(struct config *config, char *csd)
>
>                 printf("\tC_SIZE_MULT: 0x%01x\n", c_size_mult);
>                 printf("\tERASE_GRP_SIZE: 0x%02x\n", erase_grp_size);
> -               printf("\tERASE_GRP_MULT: 0x%02x (%d write blocks/erase group)\n",
> +               printf("\tERASE_GRP_MULT: 0x%02x (%u write blocks/erase group)\n",
>                        erase_grp_mult, (erase_grp_size + 1) *
>                        (erase_grp_mult + 1));
> -               printf("\tWP_GRP_SIZE: 0x%02x (%d blocks/write protect group)\n",
> +               printf("\tWP_GRP_SIZE: 0x%02x (%u blocks/write protect group)\n",
>                        wp_grp_size, wp_grp_size + 1);
>                 printf("\tWP_GRP_ENABLE: 0x%01x\n", wp_grp_enable);
>
> @@ -1742,7 +1774,7 @@ void print_mmc_csd(struct config *config, char *csd)
>                         break;
>                 }
>
> -               printf("\tR2W_FACTOR: 0x%01x (Write %d times read)\n",
> +               printf("\tR2W_FACTOR: 0x%01x (Write %u times read)\n",
>                        r2w_factor, r2w_factor);
>
>                 printf("\tWRITE_BL_LEN: 0x%01x (", write_bl_len);
> @@ -1872,7 +1904,7 @@ void print_mmc_csd(struct config *config, char *csd)
>                 else
>                         printf("%.2fbyte", memory_capacity * 1.0);
>
> -               printf(" (%lld bytes, %lld sectors, %d bytes each)\n",
> +               printf(" (%llu bytes, %llu sectors, %d bytes each)\n",
>                        memory_capacity, blocks, block_size);
>         } else {
>                 int mult;
> @@ -1949,7 +1981,7 @@ void print_mmc_csd(struct config *config, char *csd)
>                         printf("%.2fKbyte", memory_capacity / (1024.0));
>                 else
>                         printf("%.2fbyte", memory_capacity * 1.0);
> -               printf(" (%lld bytes, %lld sectors, %d bytes each)\n",
> +               printf(" (%llu bytes, %llu sectors, %d bytes each)\n",
>                        memory_capacity, blocks, block_size);
>         }
>  }
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index 19a9da1..9402112 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -252,6 +252,7 @@ int do_writeprotect_boot_get(int nargs, char **argv)
>
>         print_writeprotect_boot_status(ext_csd);
>
> +       close(fd);
>         return ret;
>  }
>
> @@ -290,6 +291,7 @@ int do_writeprotect_boot_set(int nargs, char **argv)
>                 exit(1);
>         }
>
> +       close(fd);
>         return ret;
>  }
>
> @@ -378,6 +380,7 @@ int do_writeprotect_user_get(int nargs, char **argv)
>         if (last_wpblk != (x + y - 1))
>                 print_wp_status(wp_sizeblks, last_wpblk, cnt - 1, last_prot);
>
> +       close(fd);
>         return ret;
>  }
>
> @@ -524,6 +527,7 @@ int do_disable_512B_emulation(int nargs, char **argv)
>                 printf("MMC does not support disabling 512B emulation mode.\n");
>         }
>
> +       close(fd);
>         return ret;
>  }
>
> @@ -595,6 +599,7 @@ int do_write_boot_en(int nargs, char **argv)
>                         value, EXT_CSD_PART_CONFIG, device);
>                 exit(1);
>         }
> +       close(fd);
>         return ret;
>  }
>
> @@ -716,6 +721,7 @@ int do_hwreset(int value, int nargs, char **argv)
>                 exit(1);
>         }
>
> +       close(fd);
>         return ret;
>  }
>
> @@ -766,6 +772,7 @@ int do_write_bkops_en(int nargs, char **argv)
>                 exit(1);
>         }
>
> +       close(fd);
>         return ret;
>  }
>
> @@ -796,6 +803,7 @@ int do_status_get(int nargs, char **argv)
>
>         printf("SEND_STATUS response: 0x%08x\n", response);
>
> +       close(fd);
>         return ret;
>  }
>
> @@ -1615,11 +1623,11 @@ int do_read_extcsd(int nargs, char **argv)
>                 printf("Write reliability setting register"
>                         " [WR_REL_SET]: 0x%02x\n", reg);
>
> -               printf(" user area: %s\n", reg & (1<<0) ? reliable : fast);
> +               printf(" user area: %s\n", (reg & (1<<0)) ? reliable : fast);
>                 int i;
>                 for (i = 1; i <= 4; i++) {
>                         printf(" partition %d: %s\n", i,
> -                               reg & (1<<i) ? reliable : fast);
> +                               (reg & (1<<i)) ? reliable : fast);
>                 }
>
>                 reg = ext_csd[EXT_CSD_WR_REL_PARAM];
> @@ -1805,6 +1813,7 @@ int do_sanitize(int nargs, char **argv)
>                 exit(1);
>         }
>
> +       close(fd);
>         return ret;
>
>  }
> @@ -2390,6 +2399,7 @@ int do_cache_ctrl(int value, int nargs, char **argv)
>                 exit(1);
>         }
>
> +       close(fd);
>         return ret;
>  }
>



[Index of Archives]     [Linux Memonry Technology]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux