You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
8.6 KiB

  1. From dacd9d2950f5f6559cde1ceec3035ab77e9698ad Mon Sep 17 00:00:00 2001
  2. From: Stephane Fillod <f8cfe@free.fr>
  3. Date: Tue, 15 Jan 2019 15:06:03 +0100
  4. Subject: [PATCH] Various fixes
  5. These warnings were mainly found using cppcheck.
  6. Signed-off-by: Stephane Fillod <f8cfe@free.fr>
  7. Reviewed-by: Michael Heimpold <mhei@heimpold.de>
  8. ---
  9. lsmmc.c | 42 +++++++++++++++++++++---------------------
  10. mmc_cmds.c | 14 ++++++++++++--
  11. 2 files changed, 33 insertions(+), 23 deletions(-)
  12. diff --git a/lsmmc.c b/lsmmc.c
  13. index 63504d2..06cc0b8 100644
  14. --- a/lsmmc.c
  15. +++ b/lsmmc.c
  16. @@ -554,9 +554,9 @@ void print_sd_cid(struct config *config, char *cid)
  17. printf("\tOID: %s\n", oid);
  18. printf("\tPNM: %s\n", pnm);
  19. printf("\tPRV: 0x%01x%01x ", prv_major, prv_minor);
  20. - printf("(%d.%d)\n", prv_major, prv_minor);
  21. + printf("(%u.%u)\n", prv_major, prv_minor);
  22. printf("\tPSN: 0x%08x\n", psn);
  23. - printf("\tMDT: 0x%02x%01x %d %s\n", mdt_year, mdt_month,
  24. + printf("\tMDT: 0x%02x%01x %u %s\n", mdt_year, mdt_month,
  25. 2000 + mdt_year, months[mdt_month]);
  26. printf("\tCRC: 0x%02x\n", crc);
  27. } else {
  28. @@ -566,9 +566,9 @@ void print_sd_cid(struct config *config, char *cid)
  29. else
  30. printf("manufacturer: 'Unlisted' '%s'\n", oid);
  31. - printf("product: '%s' %d.%d\n", pnm, prv_major, prv_minor);
  32. + printf("product: '%s' %u.%u\n", pnm, prv_major, prv_minor);
  33. printf("serial: 0x%08x\n", psn);
  34. - printf("manfacturing date: %d %s\n", 2000 + mdt_year,
  35. + printf("manufacturing date: %u %s\n", 2000 + mdt_year,
  36. months[mdt_month]);
  37. }
  38. }
  39. @@ -625,9 +625,9 @@ void print_mmc_cid(struct config *config, char *cid)
  40. printf("\tOID: 0x%01x\n", oid);
  41. printf("\tPNM: %s\n", pnm);
  42. printf("\tPRV: 0x%01x%01x ", prv_major, prv_minor);
  43. - printf("(%d.%d)\n", prv_major, prv_minor);
  44. + printf("(%u.%u)\n", prv_major, prv_minor);
  45. printf("\tPSN: 0x%08x\n", psn);
  46. - printf("\tMDT: 0x%01x%01x %d %s\n", mdt_month, mdt_year,
  47. + printf("\tMDT: 0x%01x%01x %u %s\n", mdt_month, mdt_year,
  48. 1997 + mdt_year, months[mdt_month]);
  49. printf("\tCRC: 0x%02x\n", crc);
  50. } else {
  51. @@ -637,9 +637,9 @@ void print_mmc_cid(struct config *config, char *cid)
  52. else
  53. printf("manufacturer: 'Unlisted' '%c'\n", oid);
  54. - printf("product: '%s' %d.%d\n", pnm, prv_major, prv_minor);
  55. + printf("product: '%s' %u.%u\n", pnm, prv_major, prv_minor);
  56. printf("serial: 0x%08x\n", psn);
  57. - printf("manfacturing date: %d %s\n", 1997 + mdt_year,
  58. + printf("manufacturing date: %u %s\n", 1997 + mdt_year,
  59. months[mdt_month]);
  60. }
  61. }
  62. @@ -729,7 +729,7 @@ void print_sd_csd(struct config *config, char *csd)
  63. printf("======SD/CSD======\n");
  64. - printf("\tCSD_STRUCTURE: %d\n", csd_structure);
  65. + printf("\tCSD_STRUCTURE: %u\n", csd_structure);
  66. printf("\tTAAC: 0x%02x (", taac);
  67. switch (taac_timevalue) {
  68. @@ -816,7 +816,7 @@ void print_sd_csd(struct config *config, char *csd)
  69. if (csd_structure == 1 && taac != 0x0e)
  70. printf("Warn: Invalid TAAC (should be 0x0e)\n");
  71. - printf("\tNSAC: %d clocks\n", nsac);
  72. + printf("\tNSAC: %u clocks\n", nsac);
  73. if (csd_structure == 1 && nsac != 0x00)
  74. printf("Warn: Invalid NSAC (should be 0x00)\n");
  75. @@ -1103,12 +1103,12 @@ void print_sd_csd(struct config *config, char *csd)
  76. if (erase_blk_en != 0x01)
  77. printf("Warn: Invalid ERASE_BLK_EN (should be 0x01)\n");
  78. - printf("\tSECTOR_SIZE: 0x%02x (Erasable sector: %d blocks)\n",
  79. + printf("\tSECTOR_SIZE: 0x%02x (Erasable sector: %u blocks)\n",
  80. sector_size, sector_size + 1);
  81. if (sector_size != 0x7f)
  82. printf("Warn: Invalid SECTOR_SIZE (should be 0x7f)\n");
  83. - printf("\tWP_GRP_SIZE: 0x%02x (Write protect group: %d blocks)\n",
  84. + printf("\tWP_GRP_SIZE: 0x%02x (Write protect group: %u blocks)\n",
  85. wp_grp_size, wp_grp_size + 1);
  86. if (wp_grp_size != 0x00)
  87. printf("Warn: Invalid WP_GRP_SIZE (should be 0x00)\n");
  88. @@ -1117,7 +1117,7 @@ void print_sd_csd(struct config *config, char *csd)
  89. if (wp_grp_enable != 0x00)
  90. printf("Warn: Invalid WP_GRP_ENABLE (should be 0x00)\n");
  91. - printf("\tR2W_FACTOR: 0x%01x (Write %d times read)\n",
  92. + printf("\tR2W_FACTOR: 0x%01x (Write %u times read)\n",
  93. r2w_factor, r2w_factor);
  94. if (r2w_factor != 0x02)
  95. printf("Warn: Invalid R2W_FACTOR (should be 0x02)\n");
  96. @@ -1199,7 +1199,7 @@ void print_sd_csd(struct config *config, char *csd)
  97. else
  98. printf("%.2fbyte", memory_capacity * 1.0);
  99. - printf(" (%lld bytes, %lld sectors, %d bytes each)\n",
  100. + printf(" (%llu bytes, %llu sectors, %d bytes each)\n",
  101. memory_capacity, blocks, block_size);
  102. } else {
  103. unsigned long long blocks = 0;
  104. @@ -1262,7 +1262,7 @@ void print_sd_csd(struct config *config, char *csd)
  105. else
  106. printf("%.2fbyte", memory_capacity * 1.0);
  107. - printf(" (%lld bytes, %lld sectors, %d bytes each)\n",
  108. + printf(" (%llu bytes, %llu sectors, %d bytes each)\n",
  109. memory_capacity, blocks, block_size);
  110. }
  111. }
  112. @@ -1456,7 +1456,7 @@ void print_mmc_csd(struct config *config, char *csd)
  113. break;
  114. }
  115. - printf("\tNSAC: %d clocks\n", nsac);
  116. + printf("\tNSAC: %u clocks\n", nsac);
  117. printf("\tTRAN_SPEED: 0x%02x (", tran_speed);
  118. switch (tran_speed_timevalue) {
  119. case 0x0:
  120. @@ -1764,10 +1764,10 @@ void print_mmc_csd(struct config *config, char *csd)
  121. printf("\tC_SIZE_MULT: 0x%01x\n", c_size_mult);
  122. printf("\tERASE_GRP_SIZE: 0x%02x\n", erase_grp_size);
  123. - printf("\tERASE_GRP_MULT: 0x%02x (%d write blocks/erase group)\n",
  124. + printf("\tERASE_GRP_MULT: 0x%02x (%u write blocks/erase group)\n",
  125. erase_grp_mult, (erase_grp_size + 1) *
  126. (erase_grp_mult + 1));
  127. - printf("\tWP_GRP_SIZE: 0x%02x (%d blocks/write protect group)\n",
  128. + printf("\tWP_GRP_SIZE: 0x%02x (%u blocks/write protect group)\n",
  129. wp_grp_size, wp_grp_size + 1);
  130. printf("\tWP_GRP_ENABLE: 0x%01x\n", wp_grp_enable);
  131. @@ -1784,7 +1784,7 @@ void print_mmc_csd(struct config *config, char *csd)
  132. break;
  133. }
  134. - printf("\tR2W_FACTOR: 0x%01x (Write %d times read)\n",
  135. + printf("\tR2W_FACTOR: 0x%01x (Write %u times read)\n",
  136. r2w_factor, r2w_factor);
  137. printf("\tWRITE_BL_LEN: 0x%01x (", write_bl_len);
  138. @@ -1914,7 +1914,7 @@ void print_mmc_csd(struct config *config, char *csd)
  139. else
  140. printf("%.2fbyte", memory_capacity * 1.0);
  141. - printf(" (%lld bytes, %lld sectors, %d bytes each)\n",
  142. + printf(" (%llu bytes, %llu sectors, %d bytes each)\n",
  143. memory_capacity, blocks, block_size);
  144. } else {
  145. int mult;
  146. @@ -1991,7 +1991,7 @@ void print_mmc_csd(struct config *config, char *csd)
  147. printf("%.2fKbyte", memory_capacity / (1024.0));
  148. else
  149. printf("%.2fbyte", memory_capacity * 1.0);
  150. - printf(" (%lld bytes, %lld sectors, %d bytes each)\n",
  151. + printf(" (%llu bytes, %llu sectors, %d bytes each)\n",
  152. memory_capacity, blocks, block_size);
  153. }
  154. }
  155. diff --git a/mmc_cmds.c b/mmc_cmds.c
  156. index fb37189..8f4a476 100644
  157. --- a/mmc_cmds.c
  158. +++ b/mmc_cmds.c
  159. @@ -252,6 +252,7 @@ int do_writeprotect_boot_get(int nargs, char **argv)
  160. print_writeprotect_boot_status(ext_csd);
  161. + close(fd);
  162. return ret;
  163. }
  164. @@ -290,6 +291,7 @@ int do_writeprotect_boot_set(int nargs, char **argv)
  165. exit(1);
  166. }
  167. + close(fd);
  168. return ret;
  169. }
  170. @@ -378,6 +380,7 @@ int do_writeprotect_user_get(int nargs, char **argv)
  171. if (last_wpblk != (x + y - 1))
  172. print_wp_status(wp_sizeblks, last_wpblk, cnt - 1, last_prot);
  173. + close(fd);
  174. return ret;
  175. }
  176. @@ -524,6 +527,7 @@ int do_disable_512B_emulation(int nargs, char **argv)
  177. printf("MMC does not support disabling 512B emulation mode.\n");
  178. }
  179. + close(fd);
  180. return ret;
  181. }
  182. @@ -595,6 +599,7 @@ int do_write_boot_en(int nargs, char **argv)
  183. value, EXT_CSD_PART_CONFIG, device);
  184. exit(1);
  185. }
  186. + close(fd);
  187. return ret;
  188. }
  189. @@ -716,6 +721,7 @@ int do_hwreset(int value, int nargs, char **argv)
  190. exit(1);
  191. }
  192. + close(fd);
  193. return ret;
  194. }
  195. @@ -766,6 +772,7 @@ int do_write_bkops_en(int nargs, char **argv)
  196. exit(1);
  197. }
  198. + close(fd);
  199. return ret;
  200. }
  201. @@ -796,6 +803,7 @@ int do_status_get(int nargs, char **argv)
  202. printf("SEND_STATUS response: 0x%08x\n", response);
  203. + close(fd);
  204. return ret;
  205. }
  206. @@ -1615,11 +1623,11 @@ int do_read_extcsd(int nargs, char **argv)
  207. printf("Write reliability setting register"
  208. " [WR_REL_SET]: 0x%02x\n", reg);
  209. - printf(" user area: %s\n", reg & (1<<0) ? reliable : fast);
  210. + printf(" user area: %s\n", (reg & (1<<0)) ? reliable : fast);
  211. int i;
  212. for (i = 1; i <= 4; i++) {
  213. printf(" partition %d: %s\n", i,
  214. - reg & (1<<i) ? reliable : fast);
  215. + (reg & (1<<i)) ? reliable : fast);
  216. }
  217. reg = ext_csd[EXT_CSD_WR_REL_PARAM];
  218. @@ -1837,6 +1845,7 @@ int do_sanitize(int nargs, char **argv)
  219. exit(1);
  220. }
  221. + close(fd);
  222. return ret;
  223. }
  224. @@ -2422,6 +2431,7 @@ int do_cache_ctrl(int value, int nargs, char **argv)
  225. exit(1);
  226. }
  227. + close(fd);
  228. return ret;
  229. }
  230. --
  231. 2.17.1