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.

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