From patchwork Tue Jan 15 14:06:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephane Fillod X-Patchwork-Id: 10764567 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C0ADE6C5 for ; Tue, 15 Jan 2019 14:06:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AED8B2C112 for ; Tue, 15 Jan 2019 14:06:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2CF82C57A; Tue, 15 Jan 2019 14:06:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDDD92C5A5 for ; Tue, 15 Jan 2019 14:06:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730304AbfAOOGI (ORCPT ); Tue, 15 Jan 2019 09:06:08 -0500 Received: from smtp4-g21.free.fr ([212.27.42.4]:52986 "EHLO smtp4-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727060AbfAOOGI (ORCPT ); Tue, 15 Jan 2019 09:06:08 -0500 Received: from zimbra64-e11.priv.proxad.net (unknown [172.20.243.214]) by smtp4-g21.free.fr (Postfix) with ESMTP id CBB4119F576; Tue, 15 Jan 2019 15:06:03 +0100 (CET) Date: Tue, 15 Jan 2019 15:06:03 +0100 (CET) From: Stephane Fillod To: linux-mmc@vger.kernel.org Cc: chris@printf.net Message-ID: <1254580747.16828401.1547561163645.JavaMail.root@zimbra64-e11.priv.proxad.net> In-Reply-To: <136642161.16716225.1547560620820.JavaMail.root@zimbra64-e11.priv.proxad.net> Subject: [PATCH mmc-utils] Various fixes MIME-Version: 1.0 X-Originating-IP: [109.3.175.58] X-Mailer: Zimbra 7.2.0-GA2598 (ZimbraWebClient - FF3.0 (Win)/7.2.0-GA2598) X-Authenticated-User: f8cfe@free.fr Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP These warnings were mainly found using cppcheck. Signed-off-by: Stephane Fillod Reviewed-by: Michael Heimpold --- 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<