From patchwork Mon Jul 15 07:35:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733008 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 23D3422EF4 for ; Mon, 15 Jul 2024 07:36:17 +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=1721028979; cv=none; b=gXsIdGqV1kyNrrqJZxKJzBcEVdzrU3RMn6tBaGawgg/ryOHQCDgPmaMLBsj0vsTuwCWxMLjXEmPw3L8ljLOwQh9N10fwmUZdB3QC9F9iwcKjCL/F4cfcrFncGMP0JaL51vTimJDsPpxJcttrJzKCnC0Vw+dTOUdy1NgkHtQ1V6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028979; c=relaxed/simple; bh=3UH09IJZIt0YJhGaVPSj185aJTX/rGHSW6YWXY8TFLM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Rte81xd2kUHx25f8vmPk5nSwAZN02VHB/CUtCfSWCWbHA3pCLape6S87AZxCALu0adJ3CsFr4GtB+VS3SN1yLVHenOuF5dNVLN4wMMTBoO5CDzJFfKkwzM5c+pZgden+etuhXXEKYFO9ihkpv79r8O8yd2xwGt9BgkAzL6DPtVs= 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=StXVLD4r; 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="StXVLD4r" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721028977; 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=+IcMNcAjpCFqPXlK6Q+JdS+fawfLdatIbaOsSew9HKE=; b=StXVLD4rMsvSjWNvAsvYbJR2OGeU0k2mGXFCxZAO+fe8aS7oq8V4Ddt5Q9ojZWsmY/0Fzh C7BQ8slCeP/pUKZ2u+ck9WT3N3ftQZwDD+WOfNexvmZRwBRRUBiZ5IIOO14Q80ZAI4Xjtd X1gmfH5nt+FaNnxQ/ntos34ULqpsbOU= 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-503-uJ2WIK6INeyy4drFrgrIcQ-1; Mon, 15 Jul 2024 03:36:14 -0400 X-MC-Unique: uJ2WIK6INeyy4drFrgrIcQ-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 5ADC71955BF7; Mon, 15 Jul 2024 07:36:13 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B0F071955D44; Mon, 15 Jul 2024 07:36:10 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 01/15] mdadm/Manage: 01r1fail cases fails Date: Mon, 15 Jul 2024 15:35:50 +0800 Message-Id: <20240715073604.30307-2-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 This patch fixes a regression issue which is checked by 01r1fail case. Fixes: 1b4b73fd535a ('mdadm: Manage.c fix coverity issues') Signed-off-by: Xiao Ni --- Manage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Manage.c b/Manage.c index aa5e80b2805d..f0304e1e4d3d 100644 --- a/Manage.c +++ b/Manage.c @@ -1333,7 +1333,7 @@ bool is_remove_safe(mdu_array_info_t *array, const int fd, char *devname, const char *avail = xcalloc(array->raid_disks, sizeof(char)); - for (disk = mdi->devs; disk; disk = mdi->next) { + for (disk = mdi->devs; disk; disk = disk->next) { if (disk->disk.raid_disk < 0) continue; if (!(disk->disk.state & (1 << MD_DISK_SYNC))) From patchwork Mon Jul 15 07:35:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733009 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 B8DFE22EF4 for ; Mon, 15 Jul 2024 07:36:24 +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=1721028986; cv=none; b=jCq0HvuhbHWFe33qOk996Sc/j3OejKwj25e/NBP4scL9AmrEFaMUoX8bxnJdSB6vlt84c+cHltM2kfeZIb8POhe+HBgtqoQhB2yCQ3QaXusuQ2+PFLZ34Sv0jzmsQGIL+lt41gxadozzsYST5L0MvAYONOZEdhTh0Wx01UynvJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028986; c=relaxed/simple; bh=nlrmSKLWr1SyN8Sl8qyvVsgDkmwcac7qgoRWs/HQjhM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M67j5RPfj38ssLQ3tWhce+eQpU6APG5LzzFEDHctvLU107aKElMZ5kccPjoVtFylk5zCtL0gSZCnx/DflObhyI73LJkzWM0LVYzbQMc4lQa2eEuTT8qPbd5dfxeIv71Pcws6ragCjjKFgGkcHnecB8OTb4BtoMAhajXeJWjnXYc= 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=PvUsxFjf; 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="PvUsxFjf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721028983; 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=KRDUCZjDAzEW7/IayESWkRmLOJklcsR1oBMPDxBBPdc=; b=PvUsxFjffBsOe8gVCLWcmqO0PaMRj0HCt4+yypMOgYhQ4pVrPziVoSFjHsbZ9fm53oz5Ip 1uUCRiwEG47W/v9gHhTQ4MZefzKHjxsNvBT5qOvtkVGtoluR7CBrCTlu0VNpiwpcdYMqwB +BwRpOzAN+uk2cn2K8NYpPOLvFQmiSQ= 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-241-StsmyDBMMFiy9fC9boI_-A-1; Mon, 15 Jul 2024 03:36:17 -0400 X-MC-Unique: StsmyDBMMFiy9fC9boI_-A-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 73C8F1955D5E; Mon, 15 Jul 2024 07:36:16 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E7C581955D42; Mon, 15 Jul 2024 07:36:13 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 02/15] mdadm/Grow: fix coverity issue CHECKED_RETURN Date: Mon, 15 Jul 2024 15:35:51 +0800 Message-Id: <20240715073604.30307-3-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 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 Mon Jul 15 07:35:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733010 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 784CAB64E for ; Mon, 15 Jul 2024 07:36:25 +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=1721028987; cv=none; b=qbAPYSq/47wxh0YwbntaZB4dyMIDOV8d7bI5UPPknuUfUOGCX34JR2MVGklNJdBwmX3CMAdlayPWx4dlmvdOL2ClTwJYPCyi5wO37djqUliYtcT4vpx+o/+QTu3hZheXQ3ds/a1a7ExABMtLi638wZqVJwMT9+6E1Cs0j5z+WPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028987; c=relaxed/simple; bh=9VWZf5s+uzx4tafWyR1OuLWJzY0bKyrd/k+NfVXRGe0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nzCVvgiYmX2biIoBjz2jBjVG5KLvd56vGiFWgs5XYGOAGMx+dbYpK/YPc2oZVY/w1FO4PssPi9yA9XNrfLEfeZtq8+STzgRam+5IdsXB97hUWiY6yf3FIHqQ/g4h2dTFBzHiDkCCJSPOiMCN4EX0uh1zgJ3+IlYlKo3wiEDScN8= 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=HFwj1TKE; 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="HFwj1TKE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721028984; 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=O6G+MFvNfZqLS/3nuqoEbQHGFcrg04JPY59zile/8xU=; b=HFwj1TKEhR1AXWHwCt71EgdTUqPoNUs6dSY2yr7SZznNWN75Atc/xzwU0k4sDBHQX6xMRI C7RB68dcPzurMonRuX9gcaM5bGku3beSBXOtmp3gcwhi5CE8LJ5b/iW+3sIMMf1rxr2VWb 5T8U/XbG46Ytd8B9/GBBUh5U2LsdQCw= 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-78-kc3ezngrM--lKqhEzuNzMw-1; Mon, 15 Jul 2024 03:36:20 -0400 X-MC-Unique: kc3ezngrM--lKqhEzuNzMw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 E15451955D4A; Mon, 15 Jul 2024 07:36:19 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6EC511955D44; Mon, 15 Jul 2024 07:36:16 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 03/15] mdadm/Grow: fix coverity issue RESOURCE_LEAK Date: Mon, 15 Jul 2024 15:35:52 +0800 Message-Id: <20240715073604.30307-4-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 Signed-off-by: Xiao Ni --- Grow.c | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/Grow.c b/Grow.c index 7ae967bda067..632be7db8d38 100644 --- a/Grow.c +++ b/Grow.c @@ -485,6 +485,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s) int bitmap_fd; int d; int max_devs = st->max_devs; + int err = 0; /* try to load a superblock */ for (d = 0; d < max_devs; d++) { @@ -525,13 +526,14 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s) return 1; } if (ioctl(fd, SET_BITMAP_FILE, bitmap_fd) < 0) { - int err = errno; + err = errno; if (errno == EBUSY) 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)); - return 1; } + close(bitmap_fd); + return err; } 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,15 @@ 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); + else + fd = -1; if (st->ss->external) { /* metadata handler takes it from here */ done = st->ss->manage_reshape( @@ -3632,6 +3637,8 @@ started: fd, sra, &reshape, st, blocks, fdlist, offsets, d - odisks, fdlist + odisks, offsets + odisks); + if (fd >= 0) + close(fd); free(fdlist); free(offsets); @@ -3701,6 +3708,8 @@ out: exit(0); release: + if (located_backup) + free(backup_file); free(fdlist); free(offsets); if (orig_level != UnSet && sra) { @@ -3839,6 +3848,7 @@ int reshape_container(char *container, char *devname, pr_err("Unable to initialize sysfs for %s\n", mdstat->devnm); rv = 1; + close(fd); break; } @@ -4717,6 +4727,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 +4743,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 (backup_fd < 0) { + pr_err("Can't open backup file %s : %s\n", + backup_file, strerror(errno)); + return -EINVAL; + } + } + for (i=old_disks-(backup_file?1:0); i= 0) + close(backup_fd); return 1; } @@ -4923,6 +4942,8 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, pr_err("Error restoring second backup from %s\n", devname); free(offsets); + if (backup_fd >= 0) + close(backup_fd); return 1; } @@ -4984,8 +5005,14 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, st->ss->store_super(st, fdlist[j]); st->ss->free_super(st); } + if (backup_fd >= 0) + close(backup_fd); return 0; } + + if (backup_fd >= 0) + close(backup_fd); + /* Didn't find any backup data, try to see if any * was needed. */ From patchwork Mon Jul 15 07:35:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733011 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 2C3E8B64E for ; Mon, 15 Jul 2024 07:36:28 +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=1721028991; cv=none; b=bDrSw+arwjw+DZwooQb3URxXGFGBs/0XwU+Y3lj/DjyvNKlXKh7eMAZaluwG0mEDFwj2XW0hfbbnA7hWmJJKgTxenxiTrrWCwkt2BkN3/gB8cLhPJj+d8G34F+LzI3EuncCiHNxEyf+wSM9/JBPTfIMkX0NN03zwC6hiMUfS3CY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028991; c=relaxed/simple; bh=aRiZ0JTkgXvqyHitZ/WnqMEca+aIqmaagVVrGH2XbSQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SdVhDwQgJxTZoyDzbJ0NUkSiZg5f8k4jBko+O8Xshl+d5QyGLUwuH4jajbPfsnNokzkgbJdSHKcPLdw3suPzxSFpR24MHkYyIuX5/G2bEsArAAq0u+1Cn5nTjHG3iZIyK2yQ8sYo9k/wiP4pSXJ5SR1I42S7SHyX1GfwatjYqA8= 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=ONFZZ+Wd; 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="ONFZZ+Wd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721028988; 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=JIhtR+yxrMSFsbe07NAfDG1CFlJeCCCk+vt2hurQzTQ=; b=ONFZZ+Wdi70WcpOBUMvSlZHsN59V+2AkuigtdTAbNfuNw32oh2n0OOTm8p41nmqtBn7eO+ Ctm8JxrJsIg7GshH5f+3whwImxm8EqFVj7WE4nkCewoCXuy8nuKn74l1WmttVwdobfcUpv 4yW1lJBnmGvWX5BrVmuROqC9rTENrQ8= 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-616-PCDgpbN1PkWjP4Lf1Vk1pQ-1; Mon, 15 Jul 2024 03:36:24 -0400 X-MC-Unique: PCDgpbN1PkWjP4Lf1Vk1pQ-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 08DA91955D44; Mon, 15 Jul 2024 07:36:23 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AF8471955D42; Mon, 15 Jul 2024 07:36:20 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 04/15] mdadm/Grow: fix coverity issue STRING_OVERFLOW Date: Mon, 15 Jul 2024 15:35:53 +0800 Message-Id: <20240715073604.30307-5-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 Signed-off-by: Xiao Ni --- Grow.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Grow.c b/Grow.c index 632be7db8d38..24f8eb8d3dee 100644 --- a/Grow.c +++ b/Grow.c @@ -1694,6 +1694,8 @@ char *analyse_change(char *devname, struct mdinfo *info, struct reshape *re) /* Current RAID6 layout has a RAID5 * equivalent - good */ + if (strlen(ls) > (40-1)) + return "layout %s length is bigger than destination"; strcat(strcpy(layout, ls), "-6"); l = map_name(r6layout, layout); if (l == UnSet) From patchwork Mon Jul 15 07:35:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733012 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 A86B322EF4 for ; Mon, 15 Jul 2024 07:36:31 +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=1721028993; cv=none; b=iiULiBBhekg50rwmsksmea1ENpaNN/YHTyjqjS95r1GYekB5jl+D7rHGRwZr0KbvMc0BOJgjABgCPF3sTXqAtyOMPsYvfuD2zqa9nY+K33AV7Td7cueaHkiFPy5keLQ51aKoYmT3rVMgyZtl2uTfloxGkYgkez5/SKtpP8+losY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028993; c=relaxed/simple; bh=qhFr8EcITfHuMZVQloYqqYhdkb6X1ybNfRiG7ygHQ1E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DlL+f10Ne7PO4w7FsuplbMoD8jvVgRrjMFn2sdls6ojW6Gp2Dz1BPDzo3MObq61FvIVEocXM2dMLR8MZwcmWQ4RPfg6lKUapep0kwWimn9l/cNQaNnLbwLo9g/F3SzHZEtIHKvpGNztkrZgVBlphXeYVDL2MgB4mKQYVaDxf3lU= 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=T50kLkG/; 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="T50kLkG/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721028990; 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=fJQTcsoxT3CujHeeYR77nOcojWPqfZiUA6v0taVcftA=; b=T50kLkG/mHDiOkieiechl4pq9/eLRmFRJTK0HBPQ5ie2fhpvQ7im1G7goKsw4ekGIHi8TH y4FXRkoaLEVKkZYaGMfLL8M5JOk+vDsK7tup1gAjLh+3A3vAEwIiDooElEP9DWZvO6urcr 99p3ak9brJVr50MI55eX0bCqhN3O3Fo= 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-360-DRdyEv8BPuqXrUjVDyAG6g-1; Mon, 15 Jul 2024 03:36:27 -0400 X-MC-Unique: DRdyEv8BPuqXrUjVDyAG6g-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 5857E19560A3; Mon, 15 Jul 2024 07:36:26 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DD5031955D44; Mon, 15 Jul 2024 07:36:23 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 05/15] mdadm/Incremental: fix coverity issues. Date: Mon, 15 Jul 2024 15:35:54 +0800 Message-Id: <20240715073604.30307-6-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 There are two issues PW.PARAMETER_HIDDEN 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..508e2c7c9140 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_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_name, "/dev/disk/by-path/%s", de->d_name) != 1) { + dev_name = NULL; goto next; } - fd = open(devname, O_RDONLY); + fd = open(dev_name, O_RDONLY); if (fd < 0) goto next; - if (get_dev_size(fd, devname, &devsectors) == 0) + if (get_dev_size(fd, dev_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_name; + dev_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_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 Mon Jul 15 07:35:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733013 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 3EF2213A888 for ; Mon, 15 Jul 2024 07:36:32 +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=1721028994; cv=none; b=fVRY8KIC01l6yicvL++a1qd5X61yPVJP8vN72rtQsJTBSY22Ye94h6BYDct1YlRrHVFkkupgq3f4FydZHLKKpUsOKK99dCaR1x2CE7SZ/xUOl0E/xShNOlXAjZtXLdzhKY7JkVJH4nVt6QtOlooA97AOCkrbU2oFzZitAb9bnVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028994; c=relaxed/simple; bh=MH2qGCDwoJPmCWdF3xX+Q9Wxg4H/uzs6CMmNQCi4X80=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sWU2OHpNKjM5xhGcwS7f1m1BznlpBp4GqreCZt7ZBVaeWjnNA8ZkT5dfIi97MXrTbBVxH2Tq8p/4nKomlfQ6JnCSRyQGZcLfNNlAF2dlSBh8P0IWDyXyjYpW+zTdOEv7PZ9UabIM24Yoh+Cskad34XfW1BOZuGHHS9QBzN1V1DI= 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=eT6wK1jR; 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="eT6wK1jR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721028992; 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=uhqXtnzDcUhJ6UGlgJ1UyS2V5x5WmKX1gKs6L8gpqtw=; b=eT6wK1jR0SbDhGQG16djVihagE0f0u8c8cdb8aTsa/msScyrWPcJ/oC+cexPliTpTbUT5n P+jmpHY0vEtSHIEGc/9C7undXJHc5BGN9ngGiloTJDxwsVJV6UqNUbHn08OfOhLZyRS1d9 bpQzzP/kpm3vK/1QyOXGj1lAoOveXnI= 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-84-qZF35zQ3PN6F71VsXk-ETg-1; Mon, 15 Jul 2024 03:36:30 -0400 X-MC-Unique: qZF35zQ3PN6F71VsXk-ETg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 C29E41955BF2; Mon, 15 Jul 2024 07:36:29 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3ED111955D42; Mon, 15 Jul 2024 07:36:26 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 06/15] mdadm/mdmon: fix coverity issue CHECKED_RETURN Date: Mon, 15 Jul 2024 15:35:55 +0800 Message-Id: <20240715073604.30307-7-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 Signed-off-by: Xiao Ni --- mdmon.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mdmon.c b/mdmon.c index 5fdb5cdb5a49..b8f71e5db555 100644 --- a/mdmon.c +++ b/mdmon.c @@ -199,7 +199,8 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock) * clearing the non-blocking flag */ fl = fcntl(sock, F_GETFL, 0); 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 +250,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(sfd); + return -1; + } return sfd; } From patchwork Mon Jul 15 07:35:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733015 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 403F122EF4 for ; Mon, 15 Jul 2024 07:36:40 +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=1721029002; cv=none; b=odzTBYKbP3+zhZRPRQpFmX5gfMgzTgQDhQYCcPXH2Y1X65TuysMEtgXhKmwVgYxh/w2PCZ2JMArzTnJ+WXr83RFxc8Z3Z5Mosz/05ihd6axdGktlQY9brv//llq93GYw2gdSSDUPRycVkHoPIDuSlzokqWh11uX4L1j+LsdbQ5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721029002; c=relaxed/simple; bh=WRZHpgGascNfyOu1s2oA5wYP6OfbHIivnAJW8C4BI+E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=r4xU/SlN7gPVMSKROrhgr+7S23+xb7+ayHDK1CeMlMN6Ly+hZ/uenwg0lie+OGhQVF+E8rD4qSSNA+WVBDHGUZt3wfgdg8Fb33EhwvWI/YpdOUYhkcmke83ZBx48knkV/8gYsIybCor+P34oh7otkYmzDm5a9nRUJzq/LWLWJRg= 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=aUaOCFBM; 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="aUaOCFBM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721029000; 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=M2sG6ajFf5Fml1zBqqHC09LuKfrlzK4qH721KOacoQI=; b=aUaOCFBMoYGHqphJwu/BSu4YkUOsP2CKLTKmMBu46M/39Q38tAYglrvIBCNfMbDkDq4wGB e4c57dODCVTlH2QAolE3HfHY268SY57FjAmOMjEM2exPzNIhsc1Schn5MTCqJDa5onwNWd SCE8uDX6fgCBi4pbDoHWnrAuYnzFYh4= 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-645-A55nHAUDOZGjlDH5GHiNGA-1; Mon, 15 Jul 2024 03:36:34 -0400 X-MC-Unique: A55nHAUDOZGjlDH5GHiNGA-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 032791955BF6; Mon, 15 Jul 2024 07:36:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 905601955D48; Mon, 15 Jul 2024 07:36:30 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 07/15] mdadm/mdmon: fix coverity issue RESOURCE_LEAK Date: Mon, 15 Jul 2024 15:35:56 +0800 Message-Id: <20240715073604.30307-8-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 Signed-off-by: Xiao Ni --- mdmon.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mdmon.c b/mdmon.c index b8f71e5db555..f0e89924aef7 100644 --- a/mdmon.c +++ b/mdmon.c @@ -455,11 +455,13 @@ 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(mdfd); return 1; } switch(fork()) { case -1: pr_err("failed to fork: %s\n", strerror(errno)); + close(mdfd); return 1; case 0: /* child */ close(pfd[0]); @@ -471,6 +473,7 @@ static int mdmon(char *devnm, int must_fork, int takeover) status = WEXITSTATUS(status); } close(pfd[0]); + close(mdfd); return status; } } else From patchwork Mon Jul 15 07:35:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733014 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 DA1B5B64E for ; Mon, 15 Jul 2024 07:36:39 +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=1721029001; cv=none; b=JudlCiZr05dl8AcQhMOYdp3Op85CnTA2wAm3gDniOcorgXv6pgFEMHokhRL9ONPxqxhOa58UDuiVKJx6BzQMoJz6lV6oTaJy1utxDhR6aVevMwkxqcgy5/PN1mnvEURNMX4qzTrFkgn+5AX3mvrZ8Bq2heZQuuczdITZy8Ho1IY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721029001; c=relaxed/simple; bh=RXP23DtOGXK3+tSFqXY9Slz7KKDcP0oaZeOOZflPLmQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OPXhIzrmcyk0WqUxe8tjhv+OJqRXarZ0K/gKB8FD0cCUwh0zCUn6jbnKaCJrNv7YW3CRVh1AgnpbzTmm+tFsVOYrham6aNhyZnPVAsAWxQTjHJuw3ndVh1Vk7YBTYjyrJolCsUfYc2lBHOUCiDMEg2h1MP9IkV5zNj3+SC8j1OU= 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=QS8MR5vs; 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="QS8MR5vs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721028998; 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=gVW31/ozUUqNbCMMDDl8mTcttCzEnh444FPD7Xp2PMM=; b=QS8MR5vsmmZISAK0HabvvCCuP6Ckd+ObhmjIdp2jKIwcvb19ijSnXuGTaR4GeIgeV3zjUT zFcpd4VWtfGkhj5GNVuz8Q1szv7byrwgnrxXamMcbZqPmGqKawwXNb9h2ZaYebYyXcL/D0 XrsUrkFWnjBUqxE8GqXaKoV6uJ7yCoI= 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-456-dbvZPRtDM3-RN0c-7AM7dw-1; Mon, 15 Jul 2024 03:36:37 -0400 X-MC-Unique: dbvZPRtDM3-RN0c-7AM7dw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 66F5E195609F; Mon, 15 Jul 2024 07:36:36 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CAE891955D44; Mon, 15 Jul 2024 07:36:33 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 08/15] mdadm/mdopen: fix coverity issue CHECKED_RETURN Date: Mon, 15 Jul 2024 15:35:57 +0800 Message-Id: <20240715073604.30307-9-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 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 Mon Jul 15 07:35:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733017 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 F3C103D579 for ; Mon, 15 Jul 2024 07:36:47 +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=1721029009; cv=none; b=WQvr9bVXF+p7B7QngMyAA2xY+ReOUNlWXcYvuLSRO5YJdW8ZSRAbxv2r24Jg5DMu9dR0Jer5+U6LftdCGwXazZcE05fWiCGQCw1ChBYo6HHjYhIXAadJsvouPbXJ1ZpYfK/fogoTIFzPdSNcJcR1sawzPZQmhpbEurjJc5QaQ2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721029009; c=relaxed/simple; bh=NY2gFccxGmDQBws6L00dq0z+vNXbfrO5fLSZRc+aG10=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tQEq8i5HPd+ae5MGc0E6MJ2cOlyHRULFwMblKY2YJ7psTID92odfL0a82khoxAHFLI9a2wAeuGZ4nycMlJWGLCE1N4atqmZRXA73oxINTyVGPJrBpKBaYYnn3ukHlMJItK9eFHPr6HhjnlVK8A/MuaKx8rrujkQXB9RkH6qi3/Y= 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=du38VCqb; 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="du38VCqb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721029007; 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=hNmptmNx4kIIIyoO8S7S6Urxm/nRoCT6si1wgmuNzQw=; b=du38VCqbFcETmHB3+T9ttyn5x09M7df5Vhh+nRm2HNpvnC0ZZcfMKwIAVTTz1Ec0uRU/Cv xAWaaGntphgcg5NiH3pBpIzf4wMS2k6BJQOoGI2aClGYHs46PNqa+AwCyLEBXrjqj6ExFJ rUt7ZOCUY2NqxoZbVMPDDHynPjk+0bQ= 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-468-d5bh71foPgGeIUe58Q8oTg-1; Mon, 15 Jul 2024 03:36:40 -0400 X-MC-Unique: d5bh71foPgGeIUe58Q8oTg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 B1FDD1955D57; Mon, 15 Jul 2024 07:36:39 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 423331955D42; Mon, 15 Jul 2024 07:36:36 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 09/15] mdadm/mdopen: fix coverity issue STRING_OVERFLOW Date: Mon, 15 Jul 2024 15:35:58 +0800 Message-Id: <20240715073604.30307-10-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 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 Mon Jul 15 07:35:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733016 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 457B4B64E for ; Mon, 15 Jul 2024 07:36:45 +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=1721029007; cv=none; b=tQWcK7cPhUYDhqCQ+i469ioEgvnmRQ3omUWp23L+2BjCm64ZNdBWdp7sbzasWz+9gESBsDi7SAJLcAICnmnV7o3+cglPHUwS7/KnxXuqyk/2WGpmxIlIicBfrKmtNph4gNMUh/rFd//LvFq2EJtEfmNIwQtMXPktDUNC6XA4Pgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721029007; c=relaxed/simple; bh=BC9uO78ju5/oU6ArITKP89WXgNm5+WgprbKcHcaKisM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qMuBgILJxcdJtr7z75K7Do1ZhN/phLJv8It7YtWf5AMt3ZZzwGgDut94NPLrzfUEkFUmsfkMgjL2OGUyjqs+cGFThoTsODzh20HHX7REeaqSFCv7FORq8/Op4t4bAf/8xY0Lk64DPvCJ2ZsN2UdgNLdDMbJq7MLPUfKQ7wW26UI= 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=Ghio9aIZ; 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="Ghio9aIZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721029005; 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=rR6If9dMQ3lMrb/2DiEkvJQ2tN9q7qHigaBzYHs0zmw=; b=Ghio9aIZPoWlLqlixxDzh6y91x/blhCv0plDNlTBNju/hZ1ytOqiiamv2v9+uicv1iOo6f 19g7QWE/oQrwT9zjPJo7CL6zHMBwB21qMYhxSsDATfa0faCsuTb1JgOiKkLvIIrZk+hb/s ADqp9S70eEw9L1AHeTstVTD9GwFtpOA= 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-267-Q4OWXK3wM86RWDVjm9JeXw-1; Mon, 15 Jul 2024 03:36:43 -0400 X-MC-Unique: Q4OWXK3wM86RWDVjm9JeXw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 EFA3B195421B; Mon, 15 Jul 2024 07:36:42 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 674521955D42; Mon, 15 Jul 2024 07:36:39 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 10/15] mdadm/mdstat: fix coverity issue CHECKED_RETURN Date: Mon, 15 Jul 2024 15:35:59 +0800 Message-Id: <20240715073604.30307-11-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 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 Mon Jul 15 07:36:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733018 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 7942B3D579 for ; Mon, 15 Jul 2024 07:36:51 +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=1721029012; cv=none; b=bKacwTn2PD6q9ivV63bp77t7JMohNKkvyi8f49BvmZAwmQX9+R1+RBD3HlzxNvdywlht9aoEmOD2RYZToBDAQGPinZ2tcDtg7oMS9hnvOKwFGYfHpHFrZXZ0x62yjf+foBSbxun0zXhp6C0nSnm+YPCPMdYsz0UuQMRKDz9z4oQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721029012; c=relaxed/simple; bh=04RfBQoaqsZ/DtLO4SAiuUcnyHjXDmwzzZa0c0DariU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q9FIRTRvq+pfElJ9wR95raSXjyJJUAYmUjmniva+uiECQu7Kd989ff8wNMiLXD1rUCHuTAGvAJcdnEeqkD3S71SVCwR+cb2Wtr32UEPKhLNrUvTWz7Fom3kCPQFKBR4ABGwiR5JIpyu9R7K9UqYpJ6senSFYXcdkIIUlzT4bQBk= 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=V8hc+33R; 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="V8hc+33R" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721029010; 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=mhEwUJ8DZ7u+HZS56OwK7iZ5wgpEvxcNmmDX0SKWsO8=; b=V8hc+33R1NsdRZElmE/R2ms9HfhcOwvqu3ClxsnvHlkBZLZdzgMiPabFImDIp268FDhv+a qDi9QnK4bPFFA66WNwiNuKotEvJHw4UUGKyzIBexj0F+oWG7Dx2jwkVQChtPENDgwcUnTM fqp8qWVUTZLVZ3LgeNri6nIdZvXv8IU= 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-445-r98wFUQJMNifhfjC_LARTw-1; Mon, 15 Jul 2024 03:36:47 -0400 X-MC-Unique: r98wFUQJMNifhfjC_LARTw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 247591955BF1; Mon, 15 Jul 2024 07:36:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B6E2B1955D42; Mon, 15 Jul 2024 07:36:43 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 11/15] mdadm/super0: fix coverity issue CHECKED_RETURN and EVALUATION_ORDER Date: Mon, 15 Jul 2024 15:36:00 +0800 Message-Id: <20240715073604.30307-12-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 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 Mon Jul 15 07:36:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733019 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 D5CE0B64E for ; Mon, 15 Jul 2024 07:36: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=1721029016; cv=none; b=pMR/LkyM5LhQacvxwQ13+nZbmIU/27M0kkM8q3oaMRJXixkdOF4LgBwy5VECVpP+YHHu0gCrFuOrNKsXzEQQCN7ph/7aIq74OjYslCA+aNjm+MSAqInp0Uvd74wEpmCuckVXHiMmpHuCw5TzM9cAZSdYGGDUl0Vtbh891T3Lt2o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721029016; c=relaxed/simple; bh=LQa9di7kzLAhuIlm7z+xPowIoBzwBAcdFe42nYsVqXA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UZnvo1F++IfJf16lM+kflb9VB9y+YCHFesaSjKoSn3q4T63jNZJn4rNxLt6ZF1qXN2PZg1O4Hk+pZfMtA5GWNEkidsTIb9OjrP/5c0eU1ZfNsFmonw5oLAI/fraQoXES2gm5w9wc5pY5SqkN2sAzJ0iQYqZTsLRmqDLR8FsLFFE= 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=bffU4YO8; 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="bffU4YO8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721029013; 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=U2Qr+L4B1EiNvjohhXwl+5lJAApo5oTLfO46DtuWceg=; b=bffU4YO89IvDs1O4Ln2khytFs1GNPugFuKUlqx+5jqzrrGVyDbQ8zjVx3mvfEVs9aU0wYq 8qCTeCRsfu1+e7QOOs3sZWKe8f5jXv6fQxwKhx1a7ZHvgoabD7lYJDc/0iHVqcrv30AZEQ hL+3tgfRk0sOlvzCEJS/52SgNnBnphw= 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-490-nzpB5RVnO6a9B-kOSefmxA-1; Mon, 15 Jul 2024 03:36:50 -0400 X-MC-Unique: nzpB5RVnO6a9B-kOSefmxA-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 9475A1956095; Mon, 15 Jul 2024 07:36:49 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0B8CC1955D42; Mon, 15 Jul 2024 07:36:46 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 12/15] mdadm/super1: fix coverity issue CHECKED_RETURN Date: Mon, 15 Jul 2024 15:36:01 +0800 Message-Id: <20240715073604.30307-13-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 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 Mon Jul 15 07:36:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13733020 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 80F343EA98 for ; Mon, 15 Jul 2024 07:36: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=1721029017; cv=none; b=QKXS8JJ+6iFtiY/Or21eRYIbF+s6IxoAk/LAA4ez89Lj/L0vCvmH8PP/KQevmLt17yNaOT66FYPdJeLeC4fFyg5y89rqMgZ9dcOk9bksdOI6nDO5AsHmbQ5giaATTAQutlbc9Ir9wyQ6RiGJ3KDPv10F2ApVvvaPocWUwwdZGg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721029017; c=relaxed/simple; bh=Cvj3SZRkZWRMk2KNF6HndE2+4OaQ32KB0X0Y1vD/PkM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N0ol4yDVYIPwDqHiUdYhaWBBnymtLsxxtBwoQSk83v0sXPW3JQ9ir/Ed3Xns+RqOXjeh/QmOVV0x5Hq8+tgPcFPs2AZWelCEmw8CoMBj/hnjVF9ZgIuXIoclEmf7q3qeMVfeZ5VxmCMNjyi7i8CWhZmSVhlIGveXptoMM326JDs= 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=bJ6Lw7ho; 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="bJ6Lw7ho" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721029015; 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=bJ6Lw7ho2DcgtjgOHiUX8xnHdHJ3qZHV2Uy3aQs52Qm51v5p+5t9RRxdGZPAOpN0GI2S4Q mDOpO4bJyAfsWUxu99jWO5jKso1NamLoHp5JZwMHr6GuV8IOgh69DINXfKue026d3Yhu3M c5FOJ98GyYIBEkq6b4t1BcXybPyKOJY= 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-132-mzotbJfMN6iuJEc-nQKa-Q-1; Mon, 15 Jul 2024 03:36:53 -0400 X-MC-Unique: mzotbJfMN6iuJEc-nQKa-Q-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 B9A611955D50; Mon, 15 Jul 2024 07:36:52 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5607C1955D42; Mon, 15 Jul 2024 07:36:49 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 13/15] mdadm/super1: fix coverity issue DEADCODE Date: Mon, 15 Jul 2024 15:36:02 +0800 Message-Id: <20240715073604.30307-14-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 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 Mon Jul 15 07:36: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: 13733021 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 43C9122EF4 for ; Mon, 15 Jul 2024 07:37:01 +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=1721029022; cv=none; b=A7BSmEkRwn/FyapC72Olyh1QNGf02nNiNjqd7Rwba2nkSAHqMp5hBCTc3SEsQUuA3RIo9PhcoSEyR2tD2pqBNdNVSb/awOVani+HlAE5R216xIE8uoUMvQaEa43QHuos1IP0C+0qY54e/vC/Efukvlqe/jQmzib88UwHGz00RbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721029022; c=relaxed/simple; bh=2dvMmnYVsgc7V/o+A1wicsDxR56BX8gDkC6+atrz9Pw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rUEM6UMReHHnIOc0EsCiDV9LPwXflLixo8h+xJct/MNR1wI6sQrt01Cfo10DiR1yhQLHRAjogguphITsfWuPJQr0++b40BkEyb8/pLVYq39e1AEY7C+e2jUc2zMAjLGJrgU+O+U5Ap7pVHrtJHkLzs0TiyaWkASXIFJifDpwjT0= 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=UMX3K7fx; 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="UMX3K7fx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721029020; 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=9XpRITL1ijx18ONRTeDcPj+E+dubO+JwZ0gLGE/aa5A=; b=UMX3K7fximJhpvnhV5iTjirB/76NoeNHq+nw4jIHQa8CuzGPpkebGiDpeX3wjfC9ViI5W1 UKiEIlepIbgsFZgXLhUV6xsf+tfL1JWyn1urvBYHYe+FpT9Ykk7dZhoa4bBUq9QGb71oEd OqGGr9B4N86sQQfBvFgaQreHYlwphzk= 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-517-46igtOfBMK2xtoYrG1-1fQ-1; Mon, 15 Jul 2024 03:36:56 -0400 X-MC-Unique: 46igtOfBMK2xtoYrG1-1fQ-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 0746E1955BF9; Mon, 15 Jul 2024 07:36:56 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A4F0D1955D44; Mon, 15 Jul 2024 07:36:53 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 14/15] mdadm/super1: fix coverity issue EVALUATION_ORDER Date: Mon, 15 Jul 2024 15:36:03 +0800 Message-Id: <20240715073604.30307-15-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 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 Mon Jul 15 07:36: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: 13733022 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 832DD22EF4 for ; Mon, 15 Jul 2024 07:37:04 +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=1721029025; cv=none; b=WPbqsGBdaignpvz+FK9Xsm7M/39zs8U+I9qW3h6M6Gzx9RKjGv+Vo3sOI7jV8K1fR3fkZs257Cerx2lfmqRahW0KvQaZQTMEkx9DRx9d3nJ0XLCAMVoRrSCuo3kftT2g79jmh9dnJWBNttsI3j4rFRv+I+Izn9Om522psw/bcRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721029025; c=relaxed/simple; bh=k9C+qwxwT+8zmvvXeECuL6SM1MpukA+JKTkicTFibqk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=o7RHAL5dlakjBFoQeBHj00RGcP3iqKcepuw9lQeIFHyLrh3F3sAYY3U1sGmjBpmYPIYPZKJ6JQwlj9+hogqmlmSfnPlLcyyApi12xTfc5EcBkkRMnU5IT6lqiFgxbQzWBt+Evm+PO8FLrjFQr8cz15LsLZ6tntHsq2/4MADELHU= 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=Kvu1Dcak; 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="Kvu1Dcak" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721029023; 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=loCkOTgHVwH+LIqyvWVyzmSINYz0omLTflX14X4MP2s=; b=Kvu1DcakqJO+Ll+GnUHCgKzIOAv7atDKhaF4tU9ppV2omVMQbbbid9lmzVTcBIpp4Lml8q RTwNKS3eYYyFKk6Byam/bUNAKszFHHzH8ZqbRAoxSnQz2GkZZW5BYintDHy+MtjhP/9FAv w8bJOeqlbQvWyNk5UcIXJVQz0o2jhi0= 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-655-__Nsrfb8OrqldqXpzk6ljQ-1; Mon, 15 Jul 2024 03:37:00 -0400 X-MC-Unique: __Nsrfb8OrqldqXpzk6ljQ-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 73CF81955F40; Mon, 15 Jul 2024 07:36:59 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.27]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D7EB51955D42; Mon, 15 Jul 2024 07:36:56 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 15/15] mdadm/super1: fix coverity issue RESOURCE_LEAK Date: Mon, 15 Jul 2024 15:36:04 +0800 Message-Id: <20240715073604.30307-16-xni@redhat.com> In-Reply-To: <20240715073604.30307-1-xni@redhat.com> References: <20240715073604.30307-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.40 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; }