From patchwork Thu Aug 25 21:02:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 9299959 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 81266607D8 for ; Thu, 25 Aug 2016 21:02:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7076B293AE for ; Thu, 25 Aug 2016 21:02:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 651B5293B9; Thu, 25 Aug 2016 21:02:36 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from oss.sgi.com (oss.sgi.com [192.48.182.195]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A6222293AE for ; Thu, 25 Aug 2016 21:02:35 +0000 (UTC) Received: from oss.sgi.com (localhost [IPv6:::1]) by oss.sgi.com (Postfix) with ESMTP id 8F0F27CA1; Thu, 25 Aug 2016 16:02:33 -0500 (CDT) X-Original-To: xfs@oss.sgi.com Delivered-To: xfs@oss.sgi.com Received: from relay.sgi.com (relay1.corp.sgi.com [137.38.102.111]) by oss.sgi.com (Postfix) with ESMTP id 506F57CA0 for ; Thu, 25 Aug 2016 16:02:31 -0500 (CDT) Received: from cuda.sgi.com (cuda2.sgi.com [192.48.176.25]) by relay1.corp.sgi.com (Postfix) with ESMTP id 205328F8033 for ; Thu, 25 Aug 2016 14:02:27 -0700 (PDT) X-ASG-Debug-ID: 1472158941-0bf57b5313205de0001-NocioJ Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69]) by cuda.sgi.com with ESMTP id hMXev8sui6A6Iyjm (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 25 Aug 2016 14:02:22 -0700 (PDT) X-Barracuda-Envelope-From: darrick.wong@oracle.com X-Barracuda-Effective-Source-IP: aserp1040.oracle.com[141.146.126.69] X-Barracuda-Apparent-Source-IP: 141.146.126.69 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u7PL2J8e023547 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Aug 2016 21:02:20 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u7PL2JA4024435 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Aug 2016 21:02:19 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u7PL2Iaq014612; Thu, 25 Aug 2016 21:02:18 GMT Received: from localhost (/10.145.178.207) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 25 Aug 2016 14:02:18 -0700 Date: Thu, 25 Aug 2016 14:02:16 -0700 From: "Darrick J. Wong" To: david@fromorbit.com Subject: [PATCH v2 5/7] misc: fix Coverity errors Message-ID: <20160825210216.GB22760@birch.djwong.org> X-ASG-Orig-Subj: [PATCH v2 5/7] misc: fix Coverity errors References: <147200546481.15538.12724000421579716885.stgit@birch.djwong.org> <147200549633.15538.18051281375686885659.stgit@birch.djwong.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <147200549633.15538.18051281375686885659.stgit@birch.djwong.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-Source-IP: userv0021.oracle.com [156.151.31.71] X-Barracuda-Connect: aserp1040.oracle.com[141.146.126.69] X-Barracuda-Start-Time: 1472158942 X-Barracuda-Encrypted: ECDHE-RSA-AES256-GCM-SHA384 X-Barracuda-URL: https://192.48.176.25:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 4325 X-Virus-Scanned: by bsmtpd at sgi.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using per-user scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=2.7 tests=BSF_SC0_MISMATCH_TO, UNPARSEABLE_RELAY X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.32325 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 BSF_SC0_MISMATCH_TO Envelope rcpt doesn't match header 0.00 UNPARSEABLE_RELAY Informational: message has unparseable relay lines Cc: linux-xfs@vger.kernel.org, xfs@oss.sgi.com X-BeenThere: xfs@oss.sgi.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: XFS Filesystem from SGI List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: xfs-bounces@oss.sgi.com Sender: xfs-bounces@oss.sgi.com X-Virus-Scanned: ClamAV using ClamSMTP Fix various code sloppinesses pointed out by Coverity, and fix an incorrect comment/debug message. Coverity-id: 1371628 - 1371638 Signed-off-by: Darrick J. Wong --- db/fsmap.c | 7 ++----- repair/phase5.c | 17 +++++++++-------- repair/rmap.c | 4 ++-- repair/scan.c | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/db/fsmap.c b/db/fsmap.c index b2ba55d..61ccce0 100644 --- a/db/fsmap.c +++ b/db/fsmap.c @@ -57,8 +57,8 @@ fsmap( xfs_agnumber_t end_ag; xfs_agnumber_t agno; xfs_daddr_t eofs; - struct xfs_rmap_irec low; - struct xfs_rmap_irec high; + struct xfs_rmap_irec low = {0}; + struct xfs_rmap_irec high = {0}; struct xfs_btree_cur *bt_cur; struct xfs_buf *agbp; int error; @@ -68,9 +68,6 @@ fsmap( end_fsb = XFS_DADDR_TO_FSB(mp, eofs - 1); low.rm_startblock = XFS_FSB_TO_AGBNO(mp, start_fsb); - low.rm_owner = 0; - low.rm_offset = 0; - low.rm_flags = 0; high.rm_startblock = -1U; high.rm_owner = ULLONG_MAX; high.rm_offset = ULLONG_MAX; diff --git a/repair/phase5.c b/repair/phase5.c index e583879..27141cc 100644 --- a/repair/phase5.c +++ b/repair/phase5.c @@ -1464,7 +1464,7 @@ prop_rmap_cursor( * and set the rightsib pointer of current block */ #ifdef XR_BLD_INO_TRACE - fprintf(stderr, " ino prop agbno %d ", lptr->prev_agbno); + fprintf(stderr, " rmap prop agbno %d ", lptr->prev_agbno); #endif if (lptr->prev_agbno != NULLAGBLOCK) { ASSERT(lptr->prev_buf_p != NULL); @@ -1502,7 +1502,7 @@ prop_rmap_cursor( prop_rmap_cursor(mp, agno, btree_curs, rm_rec, level); } /* - * add inode info to current block + * add rmap info to current block */ be16_add_cpu(&bt_hdr->bb_numrecs, 1); @@ -1529,13 +1529,12 @@ prop_rmap_highkey( struct xfs_btree_block *bt_hdr; struct xfs_rmap_key *bt_key; struct bt_stat_level *lptr; - struct xfs_rmap_irec key; + struct xfs_rmap_irec key = {0}; struct xfs_rmap_irec high_key; int level; int i; int numrecs; - key.rm_flags = 0; high_key = *rm_highkey; for (level = 1; level < btree_curs->num_levels; level++) { lptr = &btree_curs->level[level]; @@ -1575,8 +1574,8 @@ build_rmap_tree( struct xfs_rmap_irec *rm_rec; struct xfs_slab_cursor *rmap_cur; struct xfs_rmap_rec *bt_rec; - struct xfs_rmap_irec highest_key; - struct xfs_rmap_irec hi_key; + struct xfs_rmap_irec highest_key = {0}; + struct xfs_rmap_irec hi_key = {0}; struct bt_stat_level *lptr; int level = btree_curs->num_levels; int error; @@ -1621,7 +1620,7 @@ _("Insufficient memory to construct reverse-map cursor.")); rm_rec = pop_slab_cursor(rmap_cur); lptr = &btree_curs->level[0]; - for (i = 0; i < lptr->num_blocks; i++) { + for (i = 0; i < lptr->num_blocks && rm_rec != NULL; i++) { /* * block initialization, lay in block header */ @@ -1639,8 +1638,10 @@ _("Insufficient memory to construct reverse-map cursor.")); if (lptr->modulo > 0) lptr->modulo--; - if (lptr->num_recs_pb > 0) + if (lptr->num_recs_pb > 0) { + ASSERT(rm_rec != NULL); prop_rmap_cursor(mp, agno, btree_curs, rm_rec, 0); + } bt_rec = (struct xfs_rmap_rec *) ((char *)bt_hdr + XFS_RMAP_BLOCK_LEN); diff --git a/repair/rmap.c b/repair/rmap.c index f22f4f0..cdd5c3a 100644 --- a/repair/rmap.c +++ b/repair/rmap.c @@ -316,7 +316,7 @@ fold_raw_rmaps( struct xfs_slab_cursor *cur = NULL; struct xfs_rmap_irec *prev, *rec; size_t old_sz; - int error; + int error = 0; old_sz = slab_count(ag_rmaps[agno].ar_rmaps); if (slab_count(ag_rmaps[agno].ar_raw_rmaps) == 0) @@ -329,7 +329,7 @@ fold_raw_rmaps( prev = pop_slab_cursor(cur); rec = pop_slab_cursor(cur); - while (rec) { + while (prev && rec) { if (mergeable_rmaps(prev, rec)) { prev->rm_blockcount += rec->rm_blockcount; rec = pop_slab_cursor(cur); diff --git a/repair/scan.c b/repair/scan.c index 9a46dd0..0ef1123 100644 --- a/repair/scan.c +++ b/repair/scan.c @@ -898,7 +898,7 @@ scan_rmapbt( int state; xfs_agblock_t lastblock = 0; struct xfs_rmap_key *kp; - struct xfs_rmap_irec key; + struct xfs_rmap_irec key = {0}; if (magic != XFS_RMAP_CRC_MAGIC) { name = "(unknown)";