From patchwork Fri Jul 26 07:14:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742417 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D807225D7 for ; Fri, 26 Jul 2024 07:14:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978077; cv=none; b=PqoMvPJ72IECfLu6R+gosCbRR0WmYkj/ewMVq9b2DJ6Fnoitz0E4mkKCMkjJOmsDcv0YMDPiv3/+CDxqyKNcm3Ly3am5ZfbrMBM3xfN49EbSxVDAVhqNXScquJUuOOABO2uW9r2uf1ZXUhwmDzQVU3K+Y3g1Gx+GwKITqveEjBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978077; c=relaxed/simple; bh=WBdulrMBQlmpN1KmD3HXkX31L3n9xCYEMzvlwB3JXQs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dmz+I4dlSf9usCFNV7Mb9D1jAB4d7Uv8WJoGX0uJbGYYfQfosThg5Eojk5AjY0pZL6EbQc0f6bvUZfgBFCIS0Wbvb70Fl8KeVzBbdjdl3b7/eF1eElNuPOBju+/ltS46hj0J/+tKU64wOWmClfb4K4oI5hZIcE59xEuZXmr8aRM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PFxsY84F; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PFxsY84F" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cax6fCZlZEQqDOQOY2xd6Aq5ZvSyVomwdfsTuW8+2pk=; b=PFxsY84Fay0H78gptWE8Yk8Cy0ZIJ8tkhdB4L1f4wJQ0QYeJkJTy9Yj0nbrTla468eQ9Gi OL4v85BYsOEjPvtqwTXlUz0vYvO3njGP2LR4CSKd/BCzrIC6qnO71haQzQPc66J68Kyx19 Ai1S710kODmDmshyjC4uaaNjQ75A0tk= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-298-5gBICV48MfeN8q0staLDSg-1; Fri, 26 Jul 2024 03:14:26 -0400 X-MC-Unique: 5gBICV48MfeN8q0staLDSg-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B45331955D4A; Fri, 26 Jul 2024 07:14:25 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 39A8119560AE; Fri, 26 Jul 2024 07:14:22 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 01/14] mdadm/Grow: fix coverity issue CHECKED_RETURN Date: Fri, 26 Jul 2024 15:14:03 +0800 Message-Id: <20240726071416.36759-2-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 It needs to check return value when functions have return value. Signed-off-by: Xiao Ni --- Grow.c | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/Grow.c b/Grow.c index b135930d05b8..7ae967bda067 100644 --- a/Grow.c +++ b/Grow.c @@ -3261,7 +3261,12 @@ static int reshape_array(char *container, int fd, char *devname, /* This is a spare that wants to * be part of the array. */ - add_disk(fd, st, info2, d); + if (add_disk(fd, st, info2, d) < 0) { + pr_err("Can not add disk %s\n", + d->sys_name); + free(info2); + goto release; + } } } sysfs_free(info2); @@ -4413,7 +4418,10 @@ static void validate(int afd, int bfd, unsigned long long offset) */ if (afd < 0) return; - lseek64(bfd, offset - 4096, 0); + if (lseek64(bfd, offset - 4096, 0) < 0) { + pr_err("lseek64 fails %d:%s\n", errno, strerror(errno)); + return; + } if (read(bfd, &bsb2, 512) != 512) fail("cannot read bsb"); if (bsb2.sb_csum != bsb_csum((char*)&bsb2, @@ -4444,12 +4452,19 @@ static void validate(int afd, int bfd, unsigned long long offset) } } - lseek64(bfd, offset, 0); + if (lseek64(bfd, offset, 0) < 0) { + pr_err("lseek64 fails %d:%s\n", errno, strerror(errno)); + goto out; + } if ((unsigned long long)read(bfd, bbuf, len) != len) { //printf("len %llu\n", len); fail("read first backup failed"); } - lseek64(afd, __le64_to_cpu(bsb2.arraystart)*512, 0); + + if (lseek64(afd, __le64_to_cpu(bsb2.arraystart)*512, 0) < 0) { + pr_err("lseek64 fails %d:%s\n", errno, strerror(errno)); + goto out; + } if ((unsigned long long)read(afd, abuf, len) != len) fail("read first from array failed"); if (memcmp(bbuf, abuf, len) != 0) @@ -4466,15 +4481,25 @@ static void validate(int afd, int bfd, unsigned long long offset) bbuf = xmalloc(abuflen); } - lseek64(bfd, offset+__le64_to_cpu(bsb2.devstart2)*512, 0); + if (lseek64(bfd, offset+__le64_to_cpu(bsb2.devstart2)*512, 0) < 0) { + pr_err("lseek64 fails %d:%s\n", errno, strerror(errno)); + goto out; + } if ((unsigned long long)read(bfd, bbuf, len) != len) fail("read second backup failed"); - lseek64(afd, __le64_to_cpu(bsb2.arraystart2)*512, 0); + if (lseek64(afd, __le64_to_cpu(bsb2.arraystart2)*512, 0) < 0) { + pr_err("lseek64 fails %d:%s\n", errno, strerror(errno)); + goto out; + } if ((unsigned long long)read(afd, abuf, len) != len) fail("read second from array failed"); if (memcmp(bbuf, abuf, len) != 0) fail("data2 compare failed"); } +out: + free(abuf); + free(bbuf); + return; } int child_monitor(int afd, struct mdinfo *sra, struct reshape *reshape, @@ -5033,7 +5058,11 @@ int Grow_continue_command(char *devname, int fd, struct context *c) goto Grow_continue_command_exit; } content = &array; - sysfs_init(content, fd, NULL); + if (sysfs_init(content, fd, NULL) < 0) { + pr_err("sysfs_init fails\n"); + ret_val = 1; + goto Grow_continue_command_exit; + } /* Need to load a superblock. * FIXME we should really get what we need from * sysfs From patchwork Fri Jul 26 07:14:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742418 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8CD2176235 for ; Fri, 26 Jul 2024 07:14:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978077; cv=none; b=f633o5XuCh3qegxBbqwMsy30uhPPxTe0YASrpgmYCp+rUwBdDUrfVyM9PQbeIB9S7U2sLKwCjfsX1oqFjn8SU0mNAVAnbO9Os5m6XQ4VvtwgnWmoeCEf2Tf1c/6Uii0cYDYo8JEYMH/dVcBZUSEsiTyAhRDxUh16A8Mye1yRFcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978077; c=relaxed/simple; bh=cSOX5y1/l3UQBicevscDgtDNkzUyHEXhlcSiOUka1VA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kFFRdz/Ri4TuTyxeMlnRRDck4hIAok1CW/KJkIfF+Y4Zf72QNhvgZq3W8yUVbeLs/hZebpxJ64iUJcVM3EdJ5lYdSCGwaZOyFGYQ+1TlY/cwVh2hhAATntLl0H610VZenxHQG8x/qE5pcAmeV8G2/PoS7ryBOT98DViS+Uy9vU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=enV8m+Tz; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="enV8m+Tz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gZbZS+8U930KI0ROygojYwvXETsd6lrIE5jyhVbx7V4=; b=enV8m+TztChEBLMIErpbe9EZ+v5tBtKAri1y3SGYgv0q9ip98BtHiv6F7HJ1j33VKTgqDd vfZ6d32Uw/mYzs62WpfQFPB7dkPwPWZHcMMXgAc8rafZxBMrFT0fujSFy0tUsEhTtD5biU xMM4dQ/QpIVj1UruG9cafy+MTF6/IPU= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-542-g3OYB7N-NzewDikYpFDu_A-1; Fri, 26 Jul 2024 03:14:30 -0400 X-MC-Unique: g3OYB7N-NzewDikYpFDu_A-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F05C81955D44; Fri, 26 Jul 2024 07:14:28 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6634319560AE; Fri, 26 Jul 2024 07:14:25 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 02/14] mdadm/Grow: fix coverity issue RESOURCE_LEAK Date: Fri, 26 Jul 2024 15:14:04 +0800 Message-Id: <20240726071416.36759-3-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Fix some resource leak problems. Signed-off-by: Xiao Ni --- Grow.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/Grow.c b/Grow.c index 7ae967bda067..907a6e1b9e22 100644 --- a/Grow.c +++ b/Grow.c @@ -530,8 +530,10 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s) pr_err("Cannot add bitmap while array is resyncing or reshaping etc.\n"); pr_err("Cannot set bitmap file for %s: %s\n", devname, strerror(err)); + close_fd(&bitmap_fd); return 1; } + close_fd(&bitmap_fd); } return 0; @@ -3083,6 +3085,7 @@ static int reshape_array(char *container, int fd, char *devname, int done; struct mdinfo *sra = NULL; char buf[SYSFS_MAX_BUF_SIZE]; + bool located_backup = false; /* when reshaping a RAID0, the component_size might be zero. * So try to fix that up. @@ -3165,8 +3168,10 @@ static int reshape_array(char *container, int fd, char *devname, goto release; } - if (!backup_file) + if (!backup_file) { backup_file = locate_backup(sra->sys_name); + located_backup = true; + } goto started; } @@ -3612,15 +3617,13 @@ started: mdstat_wait(30 - (delayed-1) * 25); } while (delayed); mdstat_close(); - if (check_env("MDADM_GROW_VERIFY")) - fd = open(devname, O_RDONLY | O_DIRECT); - else - fd = -1; mlockall(MCL_FUTURE); if (signal_s(SIGTERM, catch_term) == SIG_ERR) goto release; + if (check_env("MDADM_GROW_VERIFY")) + fd = open(devname, O_RDONLY | O_DIRECT); if (st->ss->external) { /* metadata handler takes it from here */ done = st->ss->manage_reshape( @@ -3632,6 +3635,7 @@ started: fd, sra, &reshape, st, blocks, fdlist, offsets, d - odisks, fdlist + odisks, offsets + odisks); + close_fd(&fd); free(fdlist); free(offsets); @@ -3701,6 +3705,8 @@ out: exit(0); release: + if (located_backup) + free(backup_file); free(fdlist); free(offsets); if (orig_level != UnSet && sra) { @@ -3839,6 +3845,7 @@ int reshape_container(char *container, char *devname, pr_err("Unable to initialize sysfs for %s\n", mdstat->devnm); rv = 1; + close_fd(&fd); break; } @@ -4717,6 +4724,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, unsigned long long *offsets; unsigned long long nstripe, ostripe; int ndata, odata; + int fd, backup_fd = -1; odata = info->array.raid_disks - info->delta_disks - 1; if (info->array.level == 6) @@ -4732,9 +4740,18 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, * been used */ old_disks = cnt; + + if (backup_file) { + backup_fd = open(backup_file, O_RDONLY); + if (!is_fd_valid(backup_fd)) { + pr_err("Can't open backup file %s : %s\n", + backup_file, strerror(errno)); + return -EINVAL; + } + } + for (i=old_disks-(backup_file?1:0); iss->store_super(st, fdlist[j]); st->ss->free_super(st); } + close_fd(&backup_fd); return 0; } + + close_fd(&backup_fd); + /* Didn't find any backup data, try to see if any * was needed. */ From patchwork Fri Jul 26 07:14:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742419 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00378381BD for ; Fri, 26 Jul 2024 07:14:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978081; cv=none; b=HijU+aEcnR3H7xmP3FgP2dr0aTY3H7WpNkb12MKe95e++clPn3HbxgwFPSUHQ7UD1eglvNDWTnfEZohE1PP2PZ3UxUbBmk6l0f1J+Rc7/SAPT/hNIj5viLsFS3eFGmKsCBjeWSmdt7IEsrgcAMaHtJRMuXANv+CYxhS6LrqCM0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978081; c=relaxed/simple; bh=FM3hmkluz3hdPOUu86a4VYrfiGTj3HgCSuSLAc2t2a4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QZkHOjR7Nx0QO8rWMF9Yfz5itG7jCFqQBoVkot85JEbZarkDqBX/bq45DPjuGRKIIHNg/+q0UPNGtB3ErIXaBnlkGgfmrui8PyVur0Y1D3kdIHmthSb9+rgupoEw1Cfg3NjBWn+bFl+wy5DVqsDBVxcyG0weUtBCrupueLrQTSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=AoK3gK9B; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AoK3gK9B" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gNN1bEFABTG7pfP5oTfHubNICv4PVZVTAPfR2X9pdGc=; b=AoK3gK9BMNFde8XsbgerNOtQPCwdghHbMq8IHRzxD3ONud+mk3qBzvTOEltGRbCmZemuy2 u54F1m/tByGGct8pXIQSeQc0g70bdPhJ4GKjKykZqT+KWQLr+3qTE6CkiLSEKjIOORhks0 Us6i4nEzVZ+tQ+9M7Gf+pOw4Xe1ndDA= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-583-39gTjo8oMxOV4h5BxMg2Yg-1; Fri, 26 Jul 2024 03:14:34 -0400 X-MC-Unique: 39gTjo8oMxOV4h5BxMg2Yg-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6F00E19560BF; Fri, 26 Jul 2024 07:14:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BDD2719560AE; Fri, 26 Jul 2024 07:14:29 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 03/14] mdadm/Grow: fix coverity issue STRING_OVERFLOW Date: Fri, 26 Jul 2024 15:14:05 +0800 Message-Id: <20240726071416.36759-4-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Fix string overflow problems in Grow.c Signed-off-by: Xiao Ni --- Grow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Grow.c b/Grow.c index 907a6e1b9e22..a5f9027d93d8 100644 --- a/Grow.c +++ b/Grow.c @@ -1694,7 +1694,7 @@ char *analyse_change(char *devname, struct mdinfo *info, struct reshape *re) /* Current RAID6 layout has a RAID5 * equivalent - good */ - strcat(strcpy(layout, ls), "-6"); + snprintf(layout, 40, "%s-6", ls); l = map_name(r6layout, layout); if (l == UnSet) return "Cannot find RAID6 layout to convert to"; From patchwork Fri Jul 26 07:14:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742421 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DED23176255 for ; Fri, 26 Jul 2024 07:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978085; cv=none; b=f6SWPrdDUiwaLpHtNelxtQZGBeAsiKF4wr75hyObxPwgEesVos2/OwBfVWwFhe3K06xaJGKn4GyLAItB1X0zZc4uxXQmAC5qxcSXYa8IdhW5KlKdIdeNuFmwbeMcfbjtrlA3QxrBWMwHSov/A/enm00ffjLD0aQmC7WpO5CtyjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978085; c=relaxed/simple; bh=IlO+U7VohfoLf89LPR5XJ50biir8krIRhEaYnyuKfV4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nNaYjt/Bjgsm9dGi18BIt7oyIWuHTt65GNIb4fSTBKibS3yvb6sCS2XWaQPbiQ2wmMQLTalhYhCw9zuoDleOfPbm9udHOxsnquhZYzw19e/yi/SKhO2NATztNuSdy+6lp53xfvMyDenbIExZlMsQEKMVaGSqnuCHTxAvUVZIek4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EM2Kh1bS; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EM2Kh1bS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uavE+59TdFA2XJpXArYke+vPgatIoUtCCehLUla01BE=; b=EM2Kh1bS7M7vfiFzOcOQAJx0pyBliQO8pWRuyyrWX/fuRtz9lbSucwx1eu2F3fnpf837YX 4WNqV35XfpB2vrjzL16n19G7ghn0sFYOZKPEezCLZGzYz/wfxyY/4f9/dzoFHnv4VJhzOa CUs09H5+4XN5yUAv3+VCBKLo7GVQkco= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-246-kJ4V07_kP7SRe-Quaz1CuA-1; Fri, 26 Jul 2024 03:14:37 -0400 X-MC-Unique: kJ4V07_kP7SRe-Quaz1CuA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A8C071955D53; Fri, 26 Jul 2024 07:14:36 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2C14819560AE; Fri, 26 Jul 2024 07:14:33 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 04/14] mdadm/Incremental: fix coverity issues. Date: Fri, 26 Jul 2024 15:14:06 +0800 Message-Id: <20240726071416.36759-5-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 There are two issues PW.PARAMETER_HIDDEN (declaration hides parameter 'devname') and INTEGER_OVERFLOW. Signed-off-by: Xiao Ni --- Incremental.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Incremental.c b/Incremental.c index 83db071214ee..33e6814de9d0 100644 --- a/Incremental.c +++ b/Incremental.c @@ -770,7 +770,7 @@ static int count_active(struct supertype *st, struct mdinfo *sra, replcnt++; st->ss->free_super(st); } - if (max_journal_events >= max_events - 1) + if (max_events > 0 && max_journal_events >= max_events - 1) bestinfo->journal_clean = 1; if (!avail) @@ -1113,7 +1113,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol, int fd = -1; struct mdinfo info; struct supertype *st2 = NULL; - char *devname = NULL; + char *dev_path_name = NULL; unsigned long long devsectors; char *pathlist[2]; @@ -1142,14 +1142,14 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol, domain_free(domlist); domlist = NULL; - if (asprintf(&devname, "/dev/disk/by-path/%s", de->d_name) != 1) { - devname = NULL; + if (asprintf(&dev_path_name, "/dev/disk/by-path/%s", de->d_name) != 1) { + dev_path_name = NULL; goto next; } - fd = open(devname, O_RDONLY); + fd = open(dev_path_name, O_RDONLY); if (fd < 0) goto next; - if (get_dev_size(fd, devname, &devsectors) == 0) + if (get_dev_size(fd, dev_path_name, &devsectors) == 0) goto next; devsectors >>= 9; @@ -1188,8 +1188,8 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol, if (chosen == NULL || chosen_size < info.component_size) { chosen_size = info.component_size; free(chosen); - chosen = devname; - devname = NULL; + chosen = dev_path_name; + dev_path_name = NULL; if (chosen_st) { chosen_st->ss->free_super(chosen_st); free(chosen_st); @@ -1199,7 +1199,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol, } next: - free(devname); + free(dev_path_name); domain_free(domlist); dev_policy_free(pol2); if (st2) @@ -1246,7 +1246,7 @@ static int is_bare(int dfd) /* OK, first 4K appear blank, try the end. */ get_dev_size(dfd, NULL, &size); - if (lseek(dfd, size-4096, SEEK_SET) < 0 || + if ((size >= 4096 && lseek(dfd, size-4096, SEEK_SET) < 0) || read(dfd, buf, 4096) != 4096) return 0; From patchwork Fri Jul 26 07:14:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742420 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC177176241 for ; Fri, 26 Jul 2024 07:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978085; cv=none; b=TGdS35XymYLJgcRWhd7ejcD2nUHpRo/WuLZC8ElOxoOSJOd0ofuU/DRAUcAzVXCK6zqNvABiisuqgVrtz6FPFiSCobAUm3mG9yZ9adISyfcw2NpwydbSQDmqixZfxj8mDltI/YaMxLrzRt4Qqm9hBsFH7MrG35aNZYdy59EneCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978085; c=relaxed/simple; bh=zI9wMRvusPHofkN5TVzmpk73L1/hzgGs2nu/wirzi1M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oNfrH3sF+MQyBEqaqpkBBzSsHXP7kIdKQRqnHfZ+5Z/X3bX36z96gMN68yn1aXaMPAx4U1sT0CofJsO1krTy9ocpCzKTDKyW3DIX29NIOTd/PzJ1YQ6rq3Q4G31GjsRMfIiyLkLTOdKqQjfXYRgyGuG6UJy6hChGkngQ4GkeXhM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hy2pRO3C; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hy2pRO3C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CVR2H2Xz9gT4Gy/+sdhhnP3EvKU7h8HT1jwWhCVUnHg=; b=hy2pRO3C4z8FTjGiREE1nU1AY8fMG1E6dZHU9DUaJ5EPo9t37JoDAqvsKtG1DSq1xqxVRY JRG4HKIN6zumaWJv5quXTHOZCVuFaExzBKUP4X+yny1ZBuJM+dBdarTr6C85YJwINq7bPM OH1qO4cnONQ9hFTfcIgGvPqsegT+rLg= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-315-ULPVJBaoOQiuGLn30Q_KUA-1; Fri, 26 Jul 2024 03:14:40 -0400 X-MC-Unique: ULPVJBaoOQiuGLn30Q_KUA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 15B0B19560B0; Fri, 26 Jul 2024 07:14:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 70CED19560AE; Fri, 26 Jul 2024 07:14:36 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 05/14] mdadm/mdmon: fix coverity issue CHECKED_RETURN Date: Fri, 26 Jul 2024 15:14:07 +0800 Message-Id: <20240726071416.36759-6-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 It needs to check return values when functions have return value. Signed-off-by: Xiao Ni --- mdmon.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mdmon.c b/mdmon.c index 5fdb5cdb5a49..49921076a37d 100644 --- a/mdmon.c +++ b/mdmon.c @@ -198,8 +198,12 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock) /* Wait for monitor to exit by reading from the socket, after * clearing the non-blocking flag */ fl = fcntl(sock, F_GETFL, 0); + if (fl < 0) + return; + fl &= ~O_NONBLOCK; - fcntl(sock, F_SETFL, fl); + if (fcntl(sock, F_SETFL, fl) < 0) + return; n = read(sock, buf, 100); /* If there is I/O going on it might took some time to get to @@ -249,7 +253,10 @@ static int make_control_sock(char *devname) listen(sfd, 10); fl = fcntl(sfd, F_GETFL, 0); fl |= O_NONBLOCK; - fcntl(sfd, F_SETFL, fl); + if (fcntl(sfd, F_SETFL, fl) < 0) { + close_fd(&sfd); + return -1; + } return sfd; } From patchwork Fri Jul 26 07:14:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742422 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76D603F9D5 for ; Fri, 26 Jul 2024 07:14:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978090; cv=none; b=g3783mfzzm+bp8+8jgMqer+SwBYgKCKInF8LuB2kY53iLoVs+SCiUjJt1tiEFvVE5UnZr0dYTDZlFMPpWlPLSk92/pwGXkEZPFL/BMl6gE+UgW55PmPq+jTkDfQZH6smLwxGGMFfpkMRvJWlO6HWoXrDXxXtmqbCBXzde+Qx8GI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978090; c=relaxed/simple; bh=JagWU1VB7CB2JpugS6SKbsWU++iCjnszvNCZUQEzoUM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m2qZCv9NeEzHPiSZ5pR2uV5T46hLPJqOZgUsDIM0uOp5ceWVLxwKh5AKqM5If5K4AzhlITqS19CISrmJZF4OtRKfWuuDGjEUmpVuIkbEqnNcHjp1/MSbfmu9yV21kpK7cl2WpHcaRLTeCzzrzLuLhWd977uT5maw5FIsd1zikzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LUdl/JwK; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LUdl/JwK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978087; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MTExfhUcwdnko0yCc/fq+9jmtIOui91HP3sP81fWmx8=; b=LUdl/JwK0pezppp99iChy2mRpWyt4+5pk3ezHo095kWtvimlLMS+VbbK7okPuUHcFYby69 /5OMlFNtpEiOTE/osK3KSF42LjBLat+fDSRMdSmnWeO+neSkZ3RXC8VfcVWQrD2Wv4cOG/ kAE0d5KFHrkUvzwLOtxWCMjacMBjLd8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-Frmp2nTTPCq1gEfqq9ANnw-1; Fri, 26 Jul 2024 03:14:44 -0400 X-MC-Unique: Frmp2nTTPCq1gEfqq9ANnw-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 351FD1955D4A; Fri, 26 Jul 2024 07:14:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A773C19560AE; Fri, 26 Jul 2024 07:14:40 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 06/14] mdadm/mdmon: fix coverity issue RESOURCE_LEAK Date: Fri, 26 Jul 2024 15:14:08 +0800 Message-Id: <20240726071416.36759-7-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Fix resource leak problem in mdmon.c Signed-off-by: Xiao Ni --- mdmon.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mdmon.c b/mdmon.c index 49921076a37d..f64940d576b4 100644 --- a/mdmon.c +++ b/mdmon.c @@ -458,22 +458,25 @@ static int mdmon(char *devnm, int must_fork, int takeover) if (must_fork) { if (pipe(pfd) != 0) { pr_err("failed to create pipe\n"); + close_fd(&mdfd); return 1; } switch(fork()) { case -1: pr_err("failed to fork: %s\n", strerror(errno)); + close_fd(&mdfd); return 1; case 0: /* child */ - close(pfd[0]); + close_fd(&pfd[0]); break; default: /* parent */ - close(pfd[1]); + close_fd(&pfd[1]); if (read(pfd[0], &status, sizeof(status)) != sizeof(status)) { wait(&status); status = WEXITSTATUS(status); } - close(pfd[0]); + close_fd(&pfd[0]); + close_fd(&mdfd); return status; } } else From patchwork Fri Jul 26 07:14:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742423 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E5F9225D7 for ; Fri, 26 Jul 2024 07:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978095; cv=none; b=PlpXWCqUr8Vi+hR225froPhZtFPRQWAzmrApNf15jPxLnw0zr35Ou4dzOGmNmLkHiVL+vSK91LJEo9NxG6IGEbf7ir3gjDqDcoRxJrvK6ZG5tk9MVADHr0h7lq/Xydi5wVLLpODsux2iiAHzbODEJydJ0lho/+avCUSmIsm7awY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978095; c=relaxed/simple; bh=Xd7A33fZcGyggE1os5YxgaZK7tDMlReQ0gLkzsCDopM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q+ZbPr/R9lquqaUITuJlv5jhGO3hlxbUempSGy4XzgsIG0q1MWtK/40HF6xBp5o6NZPshYcR28A6WB0DTt3ZP6aTNGLQyr0euc2Na6lB1KS/a46sZRBN0cvocT78Wvt52c8vWcM3MK2aiG5GmVicmbknCMcSHhFvXTE9UB42UVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Xg1LNJSK; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Xg1LNJSK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978093; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=odmuhjorkDC7YxJmJ20uV0qDT33jqVqwezwfuRnNvAg=; b=Xg1LNJSKGo9hTzXnz3Jm3SEeJOe09Ne2j602uwX9L3NTalFlumwsIEOnu/WgBW5/uBWSez 5pX7EjdwG5x4L5i/rpawUTW7Szo6pQG676x+CZDn+cPRsD+keXDE7F56lV6zahFkgi9ir4 dSdtBHdJsJBjlYrNbKOD80w45e22BfQ= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-p14AROS_OuOHB77iRvP6_g-1; Fri, 26 Jul 2024 03:14:47 -0400 X-MC-Unique: p14AROS_OuOHB77iRvP6_g-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1B02219560B4; Fri, 26 Jul 2024 07:14:47 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D633119560AE; Fri, 26 Jul 2024 07:14:43 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 07/14] mdadm/mdopen: fix coverity issue CHECKED_RETURN Date: Fri, 26 Jul 2024 15:14:09 +0800 Message-Id: <20240726071416.36759-8-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 It needs to check return values when functions return value. Signed-off-by: Xiao Ni --- mdopen.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mdopen.c b/mdopen.c index eaa59b5925af..c9fda131558b 100644 --- a/mdopen.c +++ b/mdopen.c @@ -406,7 +406,11 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy, perror("chown"); if (chmod(devname, ci->mode)) perror("chmod"); - stat(devname, &stb); + if (stat(devname, &stb) < 0) { + pr_err("failed to stat %s\n", + devname); + return -1; + } add_dev(devname, &stb, 0, NULL); } if (use_mdp == 1) From patchwork Fri Jul 26 07:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742424 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 986B1548EE for ; Fri, 26 Jul 2024 07:14:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978096; cv=none; b=Pyx5/rEVG/BRyOVgu8pEPJV1zNYIn6THyKL4hykMwAftzhd0Ag2MeB3FMx1rWk4EiE1TUhxxSagK5eobngLVN+oxKzJWIlVp0gCVWmGDgigPGjbflWjekULNYGnuFpE+BvKe1U27LVoZ9svuylhQJ5VqCneI6aUsFeRjPs0SmYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978096; c=relaxed/simple; bh=TdbG+L1XiNh+GOoSzPeMdbuNbtzPGVQ7WHrluIb9r+I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dOToo8f9bRCscTfHtJp7PCzpEszzIIZ6oc+1WUpItnZbfv2Ar8uxD3HcIus5vb89At6YDWQJROvrtg8Fax6F6no6UYADHQPge2w0iH0bF6inEedYUmyl3wifEOHiUTA4KuK4qdMmMc3fO8f2N38nA3NM+HrfmzdX/J1bsZVyVVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hnOiRfxt; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hnOiRfxt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978093; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f1W9IJ0w4FAx5MI8mp/ixc9GmNEYxi0jW72ezbvkVVs=; b=hnOiRfxtoOuzJu0h15aPVH1cO8ZCMpjxr4OyoQJjkRfHq6QGBYF+E2xJESuhCSKRUkxNlA 6nJUK7Zzecso4pYHs5V3uh/LhmmYT2T6A5iGNGaiVEWtzKUB3WE3dJL2HOnbqUTvB4ZBQ3 cQs1DXmH54RT0WD34fqElQe6vYC9+Wc= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-YEC7l775M6aiVxysUFaupA-1; Fri, 26 Jul 2024 03:14:50 -0400 X-MC-Unique: YEC7l775M6aiVxysUFaupA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 03AF91955F0D; Fri, 26 Jul 2024 07:14:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9B40E19560AE; Fri, 26 Jul 2024 07:14:47 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 08/14] mdadm/mdopen: fix coverity issue STRING_OVERFLOW Date: Fri, 26 Jul 2024 15:14:10 +0800 Message-Id: <20240726071416.36759-9-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Fix string overflow problems in mdopen.c Signed-off-by: Xiao Ni --- mdopen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdopen.c b/mdopen.c index c9fda131558b..e49defb6744d 100644 --- a/mdopen.c +++ b/mdopen.c @@ -376,7 +376,7 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy, sprintf(devname, "/dev/%s", devnm); - if (dev && dev[0] == '/') + if (dev && dev[0] == '/' && strlen(dev) < 400) strcpy(chosen, dev); else if (cname[0] == 0) strcpy(chosen, devname); From patchwork Fri Jul 26 07:14:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742425 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17E0E176ABB for ; Fri, 26 Jul 2024 07:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978098; cv=none; b=nnDHx3+Cixpn9WP4pCk50r1Ykh6kqvla66oiuzWHPXxMlVQzw0jOL5AMdYBc1Ll5FpecEHoVmz6+hctUuoUb+uGTPFYIuGXhFsxbybVgizeoNFzDafV/fxYItBNtv3iQKEPAmZ5Zhk/5agNox0bnLXqEFNT6qZt9BVJjKmwK13w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978098; c=relaxed/simple; bh=Kxrb6KqAYDg1yd7xOWiuUwWg6DUJHLgBcoiY+IrYlkU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tUFAPRpFVjMFSurn9iwjApI7QZ67sxYGzlaLuAVC2AYoeFNxGipYMoTG7QTOkX83fN50Eg9D1+uWiRYXhmlEIraCjljejLoH2JgHVsYbv7PLXa/0OsDr2TBVS8oUWC2u9jm4qWEg2wOcujqnif/klvpbOca2lzm1yKFLoVIqtws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Y7V2cx04; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y7V2cx04" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cct98WuoLJcrROJAxKUTywOAdEjh6LOS/q6Vou7MqOk=; b=Y7V2cx04s807TUYjVnJVMOTrgyuNZFNHOABmkpIFA0TFs+p6D52kawBEKuv9K7wqXdX763 FzRKn7EgeTJpA69SsYyMYJyyQ/hYFuvhAEtl9jz9ymRLfv8JU5wzmjOxaauJe+9/9EDaSk aKdoMKTYIMN41X9DKRtvrHi6cpWpGw8= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-26-R4_AD3WrPDmog2KZhnOb6A-1; Fri, 26 Jul 2024 03:14:54 -0400 X-MC-Unique: R4_AD3WrPDmog2KZhnOb6A-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 22E4A19560B0; Fri, 26 Jul 2024 07:14:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A9A2419560AE; Fri, 26 Jul 2024 07:14:50 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 09/14] mdadm/mdstat: fix coverity issue CHECKED_RETURN Date: Fri, 26 Jul 2024 15:14:11 +0800 Message-Id: <20240726071416.36759-10-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 It needs to check return values when functions return value. Signed-off-by: Xiao Ni --- mdstat.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mdstat.c b/mdstat.c index e233f094c480..930d59ee2325 100644 --- a/mdstat.c +++ b/mdstat.c @@ -146,8 +146,11 @@ struct mdstat_ent *mdstat_read(int hold, int start) f = fopen("/proc/mdstat", "r"); if (f == NULL) return NULL; - else - fcntl(fileno(f), F_SETFD, FD_CLOEXEC); + + if (fcntl(fileno(f), F_SETFD, FD_CLOEXEC) < 0) { + fclose(f); + return NULL; + } all = NULL; end = &all; @@ -281,7 +284,10 @@ struct mdstat_ent *mdstat_read(int hold, int start) } if (hold && mdstat_fd == -1) { mdstat_fd = dup(fileno(f)); - fcntl(mdstat_fd, F_SETFD, FD_CLOEXEC); + if (fcntl(mdstat_fd, F_SETFD, FD_CLOEXEC) < 0) { + fclose(f); + return NULL; + } } fclose(f); From patchwork Fri Jul 26 07:14:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742426 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DD583F9D5 for ; Fri, 26 Jul 2024 07:15:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978101; cv=none; b=IOoAcTL86G1M8ZZDvLlZIOKWPi7CSrjhp+7/hFiWDCpTSAVdYoC2N24EuazNsG5BvnpFwZuVKT8bJcTI8sQ6NbImbRwSE6+rTv+bf9Td8+d0A7hcfot5qF7cQzfi/bb8wH7KLd6DH9V17nnT9JETmKN7jFKVuYMOrGiFw2eRm4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978101; c=relaxed/simple; bh=ydIJjrGCmaPAByC9U4Uiz0N1FToVrqqijBzsxuu9L+Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nXnV3RlUlSi6naPGy8mJO21iijXFtZUa9NL9WLEE1mpisEN7omb/NdAcJTsycjNVRTUi2WSq87Jt2AKNr2rQpFTBGA4WOQhit/kBC1umwQPQhQjSpP2zdie/yO2cogap0Eoum3GUkya2/OJt1KCeM6SqxBC//klsyQVV/rpfgk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=crwxTE0n; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="crwxTE0n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6q+XhkDsAU+nYwVFKnLFn5aJ6sPlVUKifAEy7t/7K/4=; b=crwxTE0neBVeouZEPQsBNfnnEsRnV9nPmyqqHDKg/c31RHxu0MFj97nktVfiTcUh3vfcAk 3gHoOYrtiXyHfOG9gghdfRbBEFSJ094ZCfriVPSjlAHODLR9rQSwN96Tf+kpqN3cjl1Huu WAZcxvLar6bEDJoJY8MRXVRYwzQ5Udg= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-p7l6QzJNNgW_qmktawFElw-1; Fri, 26 Jul 2024 03:14:57 -0400 X-MC-Unique: p7l6QzJNNgW_qmktawFElw-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5DE5E195608B; Fri, 26 Jul 2024 07:14:56 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F040219560AE; Fri, 26 Jul 2024 07:14:53 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 10/14] mdadm/super0: fix coverity issue CHECKED_RETURN and EVALUATION_ORDER Date: Fri, 26 Jul 2024 15:14:12 +0800 Message-Id: <20240726071416.36759-11-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Fix coverity problems in super0. It needs to check return value when functions return value. And fix EVALUATION_ORDER problems in super0.c Signed-off-by: Xiao Ni --- super0.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/super0.c b/super0.c index 9b8a1bd63bb7..6f43b1671d44 100644 --- a/super0.c +++ b/super0.c @@ -83,6 +83,9 @@ static void examine_super0(struct supertype *st, char *homehost) int d; int delta_extra = 0; char *c; + unsigned long expected_csum = 0; + + expected_csum = calc_sb0_csum(sb); printf(" Magic : %08x\n", sb->md_magic); printf(" Version : %d.%02d.%02d\n", @@ -187,11 +190,11 @@ static void examine_super0(struct supertype *st, char *homehost) printf("Working Devices : %d\n", sb->working_disks); printf(" Failed Devices : %d\n", sb->failed_disks); printf(" Spare Devices : %d\n", sb->spare_disks); - if (calc_sb0_csum(sb) == sb->sb_csum) + if (expected_csum == sb->sb_csum) printf(" Checksum : %x - correct\n", sb->sb_csum); else printf(" Checksum : %x - expected %lx\n", - sb->sb_csum, calc_sb0_csum(sb)); + sb->sb_csum, expected_csum); printf(" Events : %llu\n", ((unsigned long long)sb->events_hi << 32) + sb->events_lo); printf("\n"); @@ -1212,7 +1215,8 @@ static int locate_bitmap0(struct supertype *st, int fd, int node_num) offset += MD_SB_BYTES; - lseek64(fd, offset, 0); + if (lseek64(fd, offset, 0) < 0) + return -1; return 0; } From patchwork Fri Jul 26 07:14:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742427 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5392176AA6 for ; Fri, 26 Jul 2024 07:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978107; cv=none; b=hybkeiL+axQ5n3S96ci+sIJuXskark7eRn25NFpEpeY9DwSTpDApFEGUK29U1FjcMbyhWvUwLvEkgO1ku4b8TV+07H60iQWhJGA3D5puNuX14uaSoDHh6lpQsqXWcE5XdXhEH76w1b6Nr91H9UKPqnTDGFO4hbpTS8qlRzOWVhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978107; c=relaxed/simple; bh=j0wHeHb039elOZu9QyGFO448gAmLJa6sVM4nJuWZtAw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e26JRIvIPoW6DtZEbFPLuKsIG+aO40td9tGv2OGw48IuJIEgmShdbDz7sDVBc+c8ybIrJRJz/Mzen9F5XHiuKRE+YEA5Lff82V1OwJcfY8FjoWihr5e6b3lnkmkc9d4MATWdAnFo7vuPNLC0fKGzBgaohbt/I/9rcjVeR4NzEaQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Iw2HWom+; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Iw2HWom+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978104; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BxPl8nzF5V7PbJr8REGdGugpxR+mGh+huydJAmkEfWU=; b=Iw2HWom+av+uMA0gk8kkFc3vPc3ULXWcBQVOnVHofvf9CPSsfgMKGo2OwbsFO/Ss3/IqnM xp1gaoBHcUjBmf8GwhqM1RociZtjYCexMGulnQ9uGYCgnZqPTo0UVmCC6c9yiPBj2USbve UHo4TfMx2/h25aot+rzvE+DC2e2oyJE= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-694-Q1IY_YueOxOpIBwMrLYaYw-1; Fri, 26 Jul 2024 03:15:01 -0400 X-MC-Unique: Q1IY_YueOxOpIBwMrLYaYw-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B8891195609F; Fri, 26 Jul 2024 07:14:59 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3DE531955F6B; Fri, 26 Jul 2024 07:14:56 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 11/14] mdadm/super1: fix coverity issue CHECKED_RETURN Date: Fri, 26 Jul 2024 15:14:13 +0800 Message-Id: <20240726071416.36759-12-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 It needs to check return value when functions return value. Signed-off-by: Xiao Ni --- super1.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/super1.c b/super1.c index 81d29a652f36..4e4c7bfd15ae 100644 --- a/super1.c +++ b/super1.c @@ -260,7 +260,10 @@ static int aread(struct align_fd *afd, void *buf, int len) n = read(afd->fd, b, iosize); if (n <= 0) return n; - lseek(afd->fd, len - n, 1); + if (lseek(afd->fd, len - n, 1) < 0) { + pr_err("lseek fails\n"); + return -1; + } if (n > len) n = len; memcpy(buf, b, n); @@ -294,14 +297,20 @@ static int awrite(struct align_fd *afd, void *buf, int len) n = read(afd->fd, b, iosize); if (n <= 0) return n; - lseek(afd->fd, -n, 1); + if (lseek(afd->fd, -n, 1) < 0) { + pr_err("lseek fails\n"); + return -1; + } } memcpy(b, buf, len); n = write(afd->fd, b, iosize); if (n <= 0) return n; - lseek(afd->fd, len - n, 1); + if (lseek(afd->fd, len - n, 1) < 0) { + pr_err("lseek fails\n"); + return -1; + } return len; } @@ -2667,7 +2676,10 @@ static int locate_bitmap1(struct supertype *st, int fd, int node_num) } if (mustfree) free(sb); - lseek64(fd, offset<<9, 0); + if (lseek64(fd, offset<<9, 0) < 0) { + pr_err("lseek fails\n"); + ret = -1; + } return ret; } From patchwork Fri Jul 26 07:14:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742428 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA8A7176AAD for ; Fri, 26 Jul 2024 07:15:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978110; cv=none; b=Xb3c97XFhgggelueuxjNBZsvmZ66pJlVK4bDhpYemAaF5sGBvkC5Z2IgE6oSqNfcHsMrJlhH9jmgONRSz/FIVcdeAqxQwhlOINuIbqWEY8FWHMbUSaG7bR3ymZ04Xy3N6ryCl+Dy60oeZ/cJvXNdLjaxqI87aheopLPkIyUhUjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978110; c=relaxed/simple; bh=Cvj3SZRkZWRMk2KNF6HndE2+4OaQ32KB0X0Y1vD/PkM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iBxdlGyw8sbZYaqyQKIvxnDTWI48aRVDgywREz81F5rI/1CLee4RKgwhpUrIcTW5kUQB2KZ9xnGSBBRHDtvYBCeYaoo5EvG/11ELLT4Hp1p28uE2XzvlWI6DT5uIheYTFHIdaVbSrGmcfkpFHtJ/GvEwJ2KICMGH5/plQ1t1Jqc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SPrM53K2; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SPrM53K2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eZSXHtXZkTZMVa/stIcI/tq71/f1YuLWNTUXuCFojS8=; b=SPrM53K24wpIRTbrKPAT9JmUX1JPeto6moj8iZgnkYCjeXk79XoNgNYF+gbfpH2lAvGMQH jAscJ4ctCsPBcVDlmkq7uP6XqfuuVZKQQNN3otQvAdxeUPbJ/sLmnOfuLDT2MBZYzsDiZj C9i5Jy7qXQM68pxJrpp/DhRkgsRIXUI= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-171-B3pUK2goN_WxdAZZGXZRrw-1; Fri, 26 Jul 2024 03:15:04 -0400 X-MC-Unique: B3pUK2goN_WxdAZZGXZRrw-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3E2371955D4D; Fri, 26 Jul 2024 07:15:03 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8918519560AE; Fri, 26 Jul 2024 07:15:00 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 12/14] mdadm/super1: fix coverity issue DEADCODE Date: Fri, 26 Jul 2024 15:14:14 +0800 Message-Id: <20240726071416.36759-13-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 optimal_space is at most 2046. So space can't be larger than UINT16_MAX. Signed-off-by: Xiao Ni --- super1.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/super1.c b/super1.c index 4e4c7bfd15ae..24bc10269dbf 100644 --- a/super1.c +++ b/super1.c @@ -1466,8 +1466,6 @@ static int update_super1(struct supertype *st, struct mdinfo *info, __le32_to_cpu(sb->chunksize)); if (space > optimal_space) space = optimal_space; - if (space > UINT16_MAX) - space = UINT16_MAX; } sb->ppl.offset = __cpu_to_le16(offset); From patchwork Fri Jul 26 07:14:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742430 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF1EB176FA2 for ; Fri, 26 Jul 2024 07:15:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978115; cv=none; b=DIrIraNm+Vfp9ZcV+30PWYi4JBhluNRcCfNlOyrHajqHhX9T2SsziXkilrwDsCIVw5UqzBbNns2xylS+Byrb0m1ZhxE9Oy8v62GC59uPRFPR9QlZf/kqBx100TZ48pxN9fNQwkS6BnyEcj+dVI2w7iBHyyYE08tM5q9PVMqXBjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978115; c=relaxed/simple; bh=LmXPjAEBosm2hFuKsUW8PjdDpHSgdmohCm+M5cLgT3o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CBa9Tg0Dmr3SR9tQtcix+ivq0Uv6gk9Mvqi0ky8yRKsEYDj9l2ZtKuYKHn37ONGJjRRNLSaL/ZYNKA22yD0O/98jHyD/jXFCtKXFEQVYzFQW29bFL5rPuwq6eMenJZTTQQe0av2RgX2aLdLaSD4GlPw84AnFO8z1Q8cDnYWxrjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=b5nNATiK; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="b5nNATiK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KleBwO/LlmCNT7LsqpIvnrOHFBRJIfftyaNFqmaX4Hk=; b=b5nNATiKr5dTmQKcT0S7QMibovyy35DoeoLGEEC3QR1oLRtpNyxcX5V8Yqrj1d2wbyXTZ4 /nrmRF+IWr/bgNQO4evtnVXQHCG0uXAjrGXtF3fxuGNcDVevx92stAIcgLxK7FXk1dyEUt 6zRnFJXPQATcInOlHULRbFrQpptHm/g= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-353-cJgdoQFdNl-HwQ4vq9fWOg-1; Fri, 26 Jul 2024 03:15:07 -0400 X-MC-Unique: cJgdoQFdNl-HwQ4vq9fWOg-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 40CBF19560BF; Fri, 26 Jul 2024 07:15:06 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D88D119560AE; Fri, 26 Jul 2024 07:15:03 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 13/14] mdadm/super1: fix coverity issue EVALUATION_ORDER Date: Fri, 26 Jul 2024 15:14:15 +0800 Message-Id: <20240726071416.36759-14-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Fix evaluation order problems in super1.c Signed-off-by: Xiao Ni --- super1.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/super1.c b/super1.c index 24bc10269dbf..243eeb1a0174 100644 --- a/super1.c +++ b/super1.c @@ -340,6 +340,9 @@ static void examine_super1(struct supertype *st, char *homehost) unsigned long long sb_offset; struct mdinfo info; int inconsistent = 0; + unsigned int expected_csum = 0; + + expected_csum = calc_sb_1_csum(sb); printf(" Magic : %08x\n", __le32_to_cpu(sb->magic)); printf(" Version : 1"); @@ -507,13 +510,13 @@ static void examine_super1(struct supertype *st, char *homehost) printf("\n"); } - if (calc_sb_1_csum(sb) == sb->sb_csum) + if (expected_csum == sb->sb_csum) printf(" Checksum : %x - correct\n", __le32_to_cpu(sb->sb_csum)); else printf(" Checksum : %x - expected %x\n", __le32_to_cpu(sb->sb_csum), - __le32_to_cpu(calc_sb_1_csum(sb))); + __le32_to_cpu(expected_csum)); printf(" Events : %llu\n", (unsigned long long)__le64_to_cpu(sb->events)); printf("\n"); From patchwork Fri Jul 26 07:14:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13742429 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 064DF176AB6 for ; Fri, 26 Jul 2024 07:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978114; cv=none; b=BeY71uBWbg1/HgwLf6IbkrsBGDzyLVJbj4pOabtpggUcfdALu4+DdmRGTKGvglknr8r8/yFxSvLq29ou8NPHDSZbMwy5c8eKQFjgw8o0U8mGADt2dI2CZn/DoAct//2BGb+Y0C1G4v4RJYK3qQNzxEALJCjbD0fQx+mzKRjTqPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978114; c=relaxed/simple; bh=V+zXZbJgDyBPenD0c5qiKDpT+aQzBt7IfeoYwYBQxVQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n1nunyD0pTgo9ax+S+t+CJoOM/XHpCIr8IAx5ZFduSgG8sg2ZtZYSddkARl/sOkU+6mgE8q3HGiymy9IuXNNTbTIstswsMEC3PJ/W9XzbEdUFhun3+ePfA3dsFeITfwglkiqpwYNdsI7kO0xmfJFSVZaqlkXclTyQQ8d5K24G70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QV51+zqt; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QV51+zqt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721978112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Hv9jq78OuV0w889CMuzeafnKXeA/VUKWQvplB4JzTM8=; b=QV51+zqtZngMNsfXs0MMLdpbCzAIVCvDnAxxV2Fiqn9jgRhHw6X3q2fKNE7ulp9bzHJCiB u8/t3PO/xd8f2sfDdoMUEDz84/mvMoSRqdeo1VsNIc2ap3mBMU/+sSmFdmGuSWKH5CFK1I aaHU17mUlNnwG9y2jD8ehN1rGF9GhcM= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-438-94eXCbpsPf6Xkjz_NrC9nA-1; Fri, 26 Jul 2024 03:15:10 -0400 X-MC-Unique: 94eXCbpsPf6Xkjz_NrC9nA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 90E691955D50; Fri, 26 Jul 2024 07:15:09 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.28]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 172C019560AE; Fri, 26 Jul 2024 07:15:06 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 14/14] mdadm/super1: fix coverity issue RESOURCE_LEAK Date: Fri, 26 Jul 2024 15:14:16 +0800 Message-Id: <20240726071416.36759-15-xni@redhat.com> In-Reply-To: <20240726071416.36759-1-xni@redhat.com> References: <20240726071416.36759-1-xni@redhat.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Fix resource leak problems in super1.c Signed-off-by: Xiao Ni --- super1.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/super1.c b/super1.c index 243eeb1a0174..9c9c7dd14c15 100644 --- a/super1.c +++ b/super1.c @@ -923,10 +923,12 @@ static int examine_badblocks_super1(struct supertype *st, int fd, char *devname) offset <<= 9; if (lseek64(fd, offset, 0) < 0) { pr_err("Cannot seek to bad-blocks list\n"); + free(bbl); return 1; } if (read(fd, bbl, size) != size) { pr_err("Cannot read bad-blocks list\n"); + free(bbl); return 1; } /* 64bits per entry. 10 bits is block-count, 54 bits is block @@ -947,6 +949,7 @@ static int examine_badblocks_super1(struct supertype *st, int fd, char *devname) printf("%20llu for %d sectors\n", sector, count); } + free(bbl); return 0; }