From patchwork Mon Jul 22 08:17:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738521 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 8606C160873 for ; Mon, 22 Jul 2024 08:17: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=1721636275; cv=none; b=gz6qG0R0I5egZGIoxLpA+I0hQIQTysong4jFA6YgFqU8/gaI2phBm1aeBZpBuIS+ofssyU9LBM04n0mFrkx2lqHDVsliw8m23Irck4BbVQOWC2ttU8Hv/m0sTYHzz+2VOZOwKgSMesTH0q1euaHhVNGeb7mwOxFR4KAkaVtaT8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636275; c=relaxed/simple; bh=WBdulrMBQlmpN1KmD3HXkX31L3n9xCYEMzvlwB3JXQs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VNEvlKX5jrib8N3uCyl1K+svpQ6rsN3I2CV066O4blLbK7NaM0efgNrOHFJPrxbc4JNiitVkHuQP25m9IHbQxAhhU7ZXxJW9fDD3oNGGqIzCdIUwhJ3HvD7Oakd1GC3gq4iji2APXYcDtT0HHv5ZKlVJ0nDJwvSNiLhmfKkWH+c= 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=ZYqWRRAR; 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="ZYqWRRAR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636272; 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=ZYqWRRARVgGu9D5kKFWibPHZxalco32Kitbv3hhpf5x6vwwfXrUu5Eq5xqtJtbLNr/iiPK DbvJD6cF3Oi/nL8rX2vzsQnV62z4kki50v304mfXUMv4ygfD4r7tpodBJYHOeI6fqg/Jm2 Eu5MGVgc73KfXrajzF/zqR225a+mycw= 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-317-iJccxKEbP6CkAHRzTJ9F5w-1; Mon, 22 Jul 2024 04:17:46 -0400 X-MC-Unique: iJccxKEbP6CkAHRzTJ9F5w-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 1AA0F1945114; Mon, 22 Jul 2024 08:17:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5DD731955D45; Mon, 22 Jul 2024 08:17:42 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 1/3] mdadm/Grow: fix coverity issue CHECKED_RETURN Date: Mon, 22 Jul 2024 16:17:23 +0800 Message-Id: <20240722081736.20439-2-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 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 Mon Jul 22 08:17:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738523 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 AB2E24204F for ; Mon, 22 Jul 2024 08:17:58 +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=1721636280; cv=none; b=Jc5sv24BTwxWwSWzzkwuwRgRQcy5qZzt5Ny21qoKbhUiFQ2XTOIrJMfvX91fqsrqYXkEKXlSqmNy4DV4LneoBwiamCU+KaWDvdcIrp+CLoDZIsD2EbjbrgCpK+O/kvz2bBqrhHhroJbaXgjdiUT+vWgPBj5iojTJngVrsfhjshc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636280; c=relaxed/simple; bh=dab4UZj9EhfIrKWM7PHgxyx4xLjjKVIQhdtLV9KGKdw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PT3xB9BqFFXHTG12YiM9avi03lk3pLheNQj0i3QSf2qcA9uiWOBs+hqHL5NQCozipnn/+i0m3qTIWy9GuDnB7H+5SnCq9YOkhlqoug3056A2ksWcR+qLqNUTFe9sjFQm5bNMx6HC/HXYesZ2wql7dE8G9YWiC7tBnBkIwULsN9c= 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=XVd8I6Gh; 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="XVd8I6Gh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636277; 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=rMnW/hpm/YJyX2mpZvtHmEP7cBXJQfZHyKfn0fXTZe8=; b=XVd8I6GhiFyYBGuI0NTsLmw1a5fy3ZCZp2D0/FHTjlh7GkGlUsbQriHsOfluQjKbzZ84Tz s8WLt5/6hFUZbW75yZ5p9zjpjyXvKB0Q/ZYRG8llDH/Gw+V9CChyOGyuhq6q2qmiK30yfY Td5JKGQkiSH9smLGsJ7dKVraKt28Tek= 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-684-Ip4LMsN8N4eewg8ej5vR9A-1; Mon, 22 Jul 2024 04:17:51 -0400 X-MC-Unique: Ip4LMsN8N4eewg8ej5vR9A-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 9E36A1955D42; Mon, 22 Jul 2024 08:17:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 16FFD1955D4E; Mon, 22 Jul 2024 08:17:46 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 2/3] mdadm/Grow: fix coverity issue RESOURCE_LEAK Date: Mon, 22 Jul 2024 16:17:24 +0800 Message-Id: <20240722081736.20439-3-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 Fix some resource leak problems. Signed-off-by: Xiao Ni --- Grow.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/Grow.c b/Grow.c index 7ae967bda067..e18f1db00a57 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,8 @@ started: fd, sra, &reshape, st, blocks, fdlist, offsets, d - odisks, fdlist + odisks, offsets + odisks); + if (fd >= 0) + close_fd(&fd); free(fdlist); free(offsets); @@ -3701,6 +3706,8 @@ out: exit(0); release: + if (located_backup) + free(backup_file); free(fdlist); free(offsets); if (orig_level != UnSet && sra) { @@ -3839,6 +3846,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 +4725,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 +4741,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); } + if (is_fd_valid(backup_fd)) + close_fd(&backup_fd); return 0; } + + if (is_fd_valid(backup_fd)) + close_fd(&backup_fd); + /* Didn't find any backup data, try to see if any * was needed. */ From patchwork Mon Jul 22 08:17:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738522 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 DF5A25464A for ; Mon, 22 Jul 2024 08:17:58 +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=1721636280; cv=none; b=cxxKM3ap+/UFi7PXotPQSssEzHaI7jffos59eGB7a1HLlx4/jjUywR7gERdEpxMY8KZ+i02KYKbMBsqmUn6iHLeqLXWhlQRTZiOTpnDIIzy3zlKaN/XVjyYsL7UWFk7bxg4naZSgx5dahonyRs4zbR1M1qApFw1JaGaXZtpQFN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636280; c=relaxed/simple; bh=c36vCTbwrF9rX4plDMGJn3X+5791M4h1noRCP4aecIs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cWjaPb73B3r9NDZP9BZanOAuVUbqLTVR9kTfWIqstXY32+TV7Pz+qMuw9Sh6FC0O7Vm2UtU01N8xX9EwFmMZV0ru8a2wrTF5rjnds5iGc+VFHf63WBEGqPiRtZb/bpe66IOHXAdTc01M5HlS6lyxWNuD1qeKZe4mTYT89sX4YKM= 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=PAI57SpT; 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="PAI57SpT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636277; 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=2cAOKzuiAcBzhJEfbkuSCYA+q7l23ZLHLZ0psMBndc0=; b=PAI57SpTC/FbJ6sI5XA77W8CjcDVheXHLMVSQebo+yXbTd0aqx8bPJuo+1R6JDWly6KkWT tzTK9+gLkJtdKT62OzfCoCT7Wdh7Pw3D4GVvD7N7ioz4DUjrfcUM5KKZZWyyd8m7IJTvPY uVCnDUqR+mzT6OtjAVdJbT5UBC46f70= 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-519-PBNqvudZNraonCd7FI_mKg-1; Mon, 22 Jul 2024 04:17:55 -0400 X-MC-Unique: PBNqvudZNraonCd7FI_mKg-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 BC8DA1955BF1; Mon, 22 Jul 2024 08:17:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 62B00195605A; Mon, 22 Jul 2024 08:17:50 +0000 (UTC) From: Xiao Ni To: mariusz.tkaczyk@linux.intel.com Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org Subject: [PATCH 3/3] mdadm/Grow: fix coverity issue STRING_OVERFLOW Date: Mon, 22 Jul 2024 16:17:25 +0800 Message-Id: <20240722081736.20439-4-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 Fix string overflow problems in Grow.c Signed-off-by: Xiao Ni --- Grow.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Grow.c b/Grow.c index e18f1db00a57..953251561cf8 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)) + pr_err("%s length is bigger than destination", ls); strcat(strcpy(layout, ls), "-6"); l = map_name(r6layout, layout); if (l == UnSet) From patchwork Mon Jul 22 08:17:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738524 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 88DD34204F for ; Mon, 22 Jul 2024 08:18:01 +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=1721636283; cv=none; b=rjKCXCvLH7nK8QCyDYL7/c/b5niUCtvCHbaNErB5G6aNjsq4EeSDi6bOztiLwzU9Si1BnGs/QiYm9PRz8kCRRrgcw+HM13jLr0fniXMTLNE1CFKym26NxLL5LAgQzJO6SLqnv6ag8mlN1xtBj+PZ/7vOh8vvw/lwtx8GSYZcnrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636283; c=relaxed/simple; bh=v5prk+i6MRoyrNFAPDfj2la4ZWsDGRocypupzvhpynU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O5AQoAAfBHUTfRLIOXKMprW53UeSGs5FN7PU9nUF4Bl+EZI64NbSy1keshNBI75I+iRvorfhkx3jiUshlLU15B+8uoRO8rpmN/oS1HhCMdw+pCFB3mXSPUCUV8lEJKXmdrsA9siffbx0JSJFGcm1EGB/Mop221ZXCQZyHvj9MqE= 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=RkSiUNME; 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="RkSiUNME" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636280; 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=RZlY+mMta2A3oiEx4NM3RORDbNJbQCIjh4ce7SJj4WE=; b=RkSiUNME06nrlwrexf2gPXZsjxGjaBA21jMbD1itMh4UhvabQWYrLUkMVppUOqHW8+3KLZ PNJ9abQkVqO7GzDap7JxzxUWRY7JukwLF/QkZY2KDiCbJqt86K+v+v8KLxszF3d6I1stvm rhg5NR3o1L8zeX9KL/XRvZed4Y73DUo= 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-646-q-wh690aPm-9VsGDupQ6sw-1; Mon, 22 Jul 2024 04:17:58 -0400 X-MC-Unique: q-wh690aPm-9VsGDupQ6sw-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 E0E821955D47; Mon, 22 Jul 2024 08:17:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7AE11195605A; Mon, 22 Jul 2024 08:17:55 +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: Mon, 22 Jul 2024 16:17:26 +0800 Message-Id: <20240722081736.20439-5-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 83db0712..508e2c7c 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 22 08:17:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738525 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 B6295125BA for ; Mon, 22 Jul 2024 08:18:13 +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=1721636295; cv=none; b=Z8VjwPDoqt/MMIuaVFoG0kpB4w6wwaL8x+vRpqYi+QDhlTe+cvDY/BX4Y7QEfj7iVfVI2V6oWohduhUCjVyJeHuCIsWKj9mSwqSfvj7GvOix+PBAQNOrG+i5O65wtQr+jGUntrRq35kzKiKfbYFCanTimzIfEjRaqJyCxtvkGSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636295; c=relaxed/simple; bh=8TJlGUxB1Q0rMDAuGXF9KIOUDFuQYhf9x/h9eFWI5NM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CKhqVuPpREAgpVHIc/+wZtDK19DX23k/YBv8dLyHphO4WxNR7y/qfw2yqSLkIn79xB9vDZ2HlHReSGYZ4MQTbiHBp5H5T8UtWk9V2KgkiHne5aGTjK+JZ0bvJo1cqHfmA4VFGD30zEKEBnOJL56w2S8HEi+2zyEPCsokZkJCqPI= 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=B48+5jtU; 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="B48+5jtU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636292; 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=hiaJCI+haqroRgJVkzSkJZ7HOBNJPa2z9XZrY7zkrr8=; b=B48+5jtUcdBm2Rly4xg7Z04L+QnWUWcCABktlj3KrZb+t0CTqWsJFlYZ8JF0KHCYp1Pr6p QhWkDS3EEmeQSpSYm7lGmv6xRfnfjgfJ3WzwprpjBY+nA8LEAijzeB8IE0HjKe81iqbQIo 3hVBdU3yr6tqlPZC/iuQjbwPKhCGnsA= 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-452-Tx5R8zvKNRWDMhgR_OQOQw-1; Mon, 22 Jul 2024 04:18:02 -0400 X-MC-Unique: Tx5R8zvKNRWDMhgR_OQOQw-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 676CC1955F42; Mon, 22 Jul 2024 08:18:01 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F2D9E195605A; Mon, 22 Jul 2024 08:17:58 +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: Mon, 22 Jul 2024 16:17:27 +0800 Message-Id: <20240722081736.20439-6-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 It needs to check return values when functions have return value. Signed-off-by: Xiao Ni --- mdmon.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mdmon.c b/mdmon.c index 5fdb5cdb..b6fe302e 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_fd(&sfd); + return -1; + } return sfd; } From patchwork Mon Jul 22 08:17:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738526 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 0108E4204F for ; Mon, 22 Jul 2024 08:18: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=1721636295; cv=none; b=md1oQ0uXLDiP0F0zVay+T0mZPXHavKonnWaAFicgpgmoIxO6Kqu4k9mkBajuioBN1HzRnMifQw8b4QXxY1mbQ2k3zlDiXtsqfJ3H53rOzqJLDilZpUnVmuw2nZS5W1Ova6SP+YrRlpRbQqCRMrzcyRZRncOQBym5RrOOK9BYCEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636295; c=relaxed/simple; bh=nyQb8sSls3t9h1bjfoCHwqKY+xs2YTimd4XfC+3a4zs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cv4XRUnhWB/ActV20BA9/13bh0DvW3FRz4hKayzsBingwT6KdD0/DFSH1dEv6geuo0BLb1Wzf06dAHx8XETuEAoOrkPwo9xJNTa5QFwPROREt7wg6Y/78ONsN5eIEHJ4LFCfnbKnEXNHVszstjqI5aTV8Q+pFfhHvvoL5xwwKsM= 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=XqhGA8MK; 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="XqhGA8MK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636292; 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=fJ2i4vtQrConEVfiH/q51wUDvEeO64dNaRgUf3S1ldA=; b=XqhGA8MK4ZXhIHLJdLQEPvP7i0G7MKt9JC5u10vHPdHrf5d1nB0Zelp1LbN82Hr9lvDf5U Cgt8TjOcbuYQJR+2wAk23gLAiVkuecOqGao2W5O9xhskMBvj6F0p0PqGZRGm5jhMP1CZi+ pqBqLOzoLpc263y0gBA1uPRyE2djNoM= 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-693-HD5rotsdNSC0D_MlAbQkvg-1; Mon, 22 Jul 2024 04:18:05 -0400 X-MC-Unique: HD5rotsdNSC0D_MlAbQkvg-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 A8AA21955D42; Mon, 22 Jul 2024 08:18:04 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 311461955D45; Mon, 22 Jul 2024 08:18:01 +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: Mon, 22 Jul 2024 16:17:28 +0800 Message-Id: <20240722081736.20439-7-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 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 b6fe302e..a498c9bd 100644 --- a/mdmon.c +++ b/mdmon.c @@ -455,22 +455,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 Mon Jul 22 08:17:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738527 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 53ABE5464A for ; Mon, 22 Jul 2024 08:18:14 +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=1721636295; cv=none; b=B6ir9RQ6DDcDUnmbe1Sq4SLYzZH5+4PzhLH51D0dStumoNf9+WvPFMXzMfsKIKk+hNYYHUmyb2nFAHHvgnDF6Tb3jDR7Ea1weAa6cWDaKOpJypAd8yAtv29vuC7Cc8kiuYJuMT93hzbUjBx5wY4H7oXRdy84hr0GXYUuRMxQhQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636295; c=relaxed/simple; bh=Jk7ZsvCeQ5MQ89Riiz01HqNwHR4eFmj+N78+/1RPmgU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hn3HFhPKAL2QrAoPEgd6LEp0ivdcA7URrIlEgSnT0eKK3nof3RlITwp07OZ6txjbwonW+A2Netlbqg/Kn6C4qKVr4dL58KSZrGcvlrT9JT+aS3dvyx2RLIpYPhn60smYsgrRgVYRHiLw1c7SEp12uklhWvkNuEuObHCnCs7WJ/s= 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=KrsjGH65; 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="KrsjGH65" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636293; 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=6sbZKSWufDYPLpk+yo7avJJz4TOBRKFyQkUzgILprRo=; b=KrsjGH65Z1E5LAaNrNF/IWyB1eAblxougBpK/VdpO+3aIpz5/dTLFQt19zLz8rRDBZ4SzY ynQB9E6wuiPp5L1rYAUZyqtH1H/0OciUOz4bBTrSYXkbXjMMIzATga1biQO7KPfc1gSMhR jNQKe7JlnFXz+f8fJgEM2uN6eMhB7to= 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-392-mgRAFYuAPnuyBG5WfzIjaA-1; Mon, 22 Jul 2024 04:18:09 -0400 X-MC-Unique: mgRAFYuAPnuyBG5WfzIjaA-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 085AB1955BFA; Mon, 22 Jul 2024 08:18:09 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8B44F1955D45; Mon, 22 Jul 2024 08:18:05 +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: Mon, 22 Jul 2024 16:17:29 +0800 Message-Id: <20240722081736.20439-8-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 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 eaa59b59..c9fda131 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 22 08:17:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738528 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 B6A8F5464A for ; Mon, 22 Jul 2024 08:18:18 +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=1721636300; cv=none; b=RPfvuLGw4BA28dLs5ibMRyRIKyZmBmPfMQZqg5ksj0L2OK+zixizwjGaD/VRlVKVP6feqSbbzwkXG/Rm4fz9w712slmruycMEOX1SRwWZEI2xHgpA7K191Ybq9pjaOKBmKta6qTfJZGy5EwaWdzP0rjgC1c1mkKcITHWLKPK9B8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636300; c=relaxed/simple; bh=feNmwDnOngEX9cIQZwHWNMuJvo7OjUwCqXnqTVgvEmM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Kg92z/i+Hi8ZahFjmTxgmYSejAOtjMPViKiVW2VR2nRFhQwEtSjsYMLb+mR8OzZZJJxXrAGC3G82ndlS0SuzUizOh0GPJMP9ceGuYfPzKOdwD4O5uN1tmVusXSJxhQdzlhcWn/hkTrLlFKX1gq3CnusGhJhzNRZoVSFKn/0QMkU= 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=DbjH9uuu; 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="DbjH9uuu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636297; 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=37WkEh/FzLz86HdFGxI6+jRgekZCywNdxbzVtsFm8ig=; b=DbjH9uuuPQvL/wbcQUmZO/ax+AI++usfiRDoQaxhoUUqtNpRyyxjikwwb61wJnjttbz62H VAiCULXJE8dE9Y9kA/hNBf3WLWj/3+/I6LehM8OVa5cy6PkIotYOPg1rUN2Xrw+LayraDJ Fw7WcXNOnUID/13GPBpkRWlWgDZaMMA= 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-561-pNkBWzEcOaqFRmBOPNJo0Q-1; Mon, 22 Jul 2024 04:18:13 -0400 X-MC-Unique: pNkBWzEcOaqFRmBOPNJo0Q-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 218B21955F06; Mon, 22 Jul 2024 08:18:13 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CC458195605A; Mon, 22 Jul 2024 08:18:09 +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: Mon, 22 Jul 2024 16:17:30 +0800 Message-Id: <20240722081736.20439-9-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 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 c9fda131..e49defb6 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 22 08:17:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738529 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 B9E09166313 for ; Mon, 22 Jul 2024 08:18:20 +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=1721636302; cv=none; b=MCH4ulaipw+emMW1mhI5ao5/M83kW+/2fThGmc27OOjq3Kn+MpEGq96TDhy165mIKwxQafJ3AXzwSNFT+KNGSp9XaQfies6xzHp+binc4Ja+udbHDBUOlDNmdNgWC89YoGn3fcj4qAvlIOuADsdQ7tneVUea4J5VOj7kUMzPOks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636302; c=relaxed/simple; bh=s8yhPIOsJ7MBDVxGDKOneteJRCZ7ar8nENdMkmhXoRk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oC84bcR8sEHBrI6WTs49Nm3E8XwPQZ+lP+WSsOxCrdzEgg3ayW8CiU3xXVc8UemR2FSTq3RwdZIWhTlegaWwjNeNJDGMFSXNno8u6aHqUiDftv/VVVcb70eO264sg3FnEYt5LAaKhbVjTpmhyjEddOr/oWXCwlRaPwDaHbc2j+M= 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=F4lwH4mf; 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="F4lwH4mf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636299; 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=pcDI4MsQ1XT0n6+itwy/cymJYUc8vhlmcLwV1nxeYyg=; b=F4lwH4mfbaCGqibJ+61U9p2j67Ez07vHUD93Aho0ZizsEYbMLXaE+RM0zwGdNR3PXOEP5g YDzIUQPUrJK49PEo4sx8bq/CTdApD+SCmb0KWBiQuDs8PlQdkj9d33bT15AT0jV4d6cB9d XrFtchdaA24vr4wmCPtx+BFLvoO1218= 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-509-9FGmQBolPcW9Zbh66hwaiA-1; Mon, 22 Jul 2024 04:18:17 -0400 X-MC-Unique: 9FGmQBolPcW9Zbh66hwaiA-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 2F1EA1955BEF; Mon, 22 Jul 2024 08:18:16 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D75391955D47; Mon, 22 Jul 2024 08:18:13 +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: Mon, 22 Jul 2024 16:17:31 +0800 Message-Id: <20240722081736.20439-10-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 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 e233f094..930d59ee 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 22 08:17:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738530 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 CE7AC1662EC for ; Mon, 22 Jul 2024 08:18:23 +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=1721636305; cv=none; b=qg4IUVrXro805ghICJ2tvglcBvMYU7Mco8rZhX16y1HQ21zuFRkq29wdP/smhw73Ye0i5nDfu+gmGzZkt/1ICsLoz5euVcHAXFfCPiZP522NDGOHDjdVeYdNe4/PNp0x3kZlRMD0BUDCx/1NNUrkIBj5LShiC8IcI3ozyQyXt6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636305; c=relaxed/simple; bh=PHl6l02ABj7mt0hEbMRamh20wSJFjJIyCLa6vXGpSVE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FahM0I7UFRQkOK3qdtCy7m0RncoQg7PMoqui3NV8vR2lSdUoEdI3RHcAqWW4c6TvyHifTZmqM5OQ0um7uj/opiFwXTxRvlP1v+BN7e5VklAf8ZMHjNunEGzwrIwUjxzFU0sLEHtqPZYg3Gmq+hH0YIHyikwlQGNBC07EJ2DGkoo= 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=fbJg9DMx; 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="fbJg9DMx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636302; 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=CNrZvbrlaGdhkfWfnA6qA8oPMRXN+NtsdO1M7c2A0sc=; b=fbJg9DMxus9jshiXDRQWUP73BDwfSS7i8oZTGY48nBKHrtygwK08fz1/sr6p29UpvXYnGT mR9uGjSO0o5qS7xRbtdMUwq35DukJpENQ2Aw4vykPNtbvtvBuT6HP0nIl/1ODlXCQN4DxI gXizGtnMlDQMZudkWgR5a/0jqM6dDNY= 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-642-tCclmFFRPYGXCRx9UO8NIw-1; Mon, 22 Jul 2024 04:18:20 -0400 X-MC-Unique: tCclmFFRPYGXCRx9UO8NIw-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 8D5FF1955D4A; Mon, 22 Jul 2024 08:18:19 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 122821955D45; Mon, 22 Jul 2024 08:18:16 +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: Mon, 22 Jul 2024 16:17:32 +0800 Message-Id: <20240722081736.20439-11-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 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 9b8a1bd6..6f43b167 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 22 08:17:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738531 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 072F5125BA for ; Mon, 22 Jul 2024 08:18:26 +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=1721636308; cv=none; b=ke7AT5cUzuiWmum6H3aAizELnAxlB+YUgwUAX0R/LDCjBBfkOEGbRLhLz8OoWel/D/+juqkwZ+xM0yyRZF51ixHf1Dom6QiqggTODdn0uR56P5+GpG3e3RHRj4WdEj322ASGwssAFvRfbAwHzpSKwWnwvR7pwVlAZrSb/UXHt4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636308; c=relaxed/simple; bh=71cgIz/lOVv/bACkTTf8AXuS29dZrBx6eveht24RqN4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=l+llZwt+uy6nlnd8AgGSOR11T/rkm/KVAXWsb2G1jQUQx2FybTNAdJro2i1gPcaoBRHvnFL1EjtWyxPVrwszrxBx8GVlG6E0T9/54OcPEAXZ91yzPtVAB2ti1TrJ82Y5ibe9x6xf5DiJYgDrmiiKLEAxuWaV13/i5x87UvQhHsE= 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=ONqSoenO; 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="ONqSoenO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636306; 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=+R0nRuutItaX6gGXrvCCzatdbIzRNRp+pi8DULEBJl0=; b=ONqSoenO9P/p7LG7ybg1Aqf72KiSHiIoAfipKolcW0YvjAAoo53vIJaxISX9ZSjPz1suU5 d3Lc/MsMgokd/wt3ekoUAIkDAKyzIRYm42eipHrxplgzhBVVQY0V5d6F56WGMKj7U9L3Pk Jl8Ay0ohPFYS97Ajs0EGllDN9BfpzXA= 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-492-yeIWe30xNEqueTIRlBwuMg-1; Mon, 22 Jul 2024 04:18:23 -0400 X-MC-Unique: yeIWe30xNEqueTIRlBwuMg-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 018901955D4A; Mon, 22 Jul 2024 08:18:23 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 50F1E195605A; Mon, 22 Jul 2024 08:18:19 +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: Mon, 22 Jul 2024 16:17:33 +0800 Message-Id: <20240722081736.20439-12-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 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 81d29a65..4e4c7bfd 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 22 08:17:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738532 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 B8FD316A38B for ; Mon, 22 Jul 2024 08:18: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=1721636313; cv=none; b=Bx6q91mBexfxhtxrdtL8FcyuvlvEvksnIefAYnHSoB18RC7lieXPCNNtYoECQ7eaQsAO106lHa11opVWhw9TFxzNCix+5F/tnPo3tnpggh6RnTZtGi94ix+bpqP3qiNJQ+6zGl82LajOpf0oqVVDcLoIa3seM5FY+CjfOLUm7Co= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636313; c=relaxed/simple; bh=+Gpbcoblu2LLOBZ7uPxh56hc3wjq37XPSQVTKpMohes=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GJsvIFKFgvrfoIbVrRgvv6dSL7MwgYHJ+n+jBfO8kJCh51Ch7zZreagAe1sNKhzgG07CYxhyZ2Bg6fVJ7IPw9k41E2essPlMlLxM3fdgRNqE/Tdhw5kQ3bW5nQZ4qKCjhV07Cw/HZGHw4OKIl9I2SPzjZx/rI3FReLJVK4AMxJM= 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=BICItHMf; 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="BICItHMf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636310; 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=Nf5NChEWcNeYOC6BMAgvpWlkiDxDM3s9rHFFm4FX7WY=; b=BICItHMfDC8lpa3Ehir9HEOP1ngTBEzIfd3bJbQ+g7p5GmM/zZ0xRBJ+Md9f0RFFTWSDvK 1bHqH9tVf+ix7aSl0cMiE5PPtusEug09Gljer3+zsOh6ZvEVppd/33funGqsO8GfRIfJ5t dtjYI5h/lH38/6PgkwY46DbqbevdQlg= 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-556-nf7zB8V4O8eZwEr_ipaPsg-1; Mon, 22 Jul 2024 04:18:27 -0400 X-MC-Unique: nf7zB8V4O8eZwEr_ipaPsg-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 2C3641955D4A; Mon, 22 Jul 2024 08:18:26 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B8501195605A; Mon, 22 Jul 2024 08:18:23 +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: Mon, 22 Jul 2024 16:17:34 +0800 Message-Id: <20240722081736.20439-13-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 4e4c7bfd..24bc1026 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 22 08:17:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738533 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 E80B8166301 for ; Mon, 22 Jul 2024 08:18:34 +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=1721636316; cv=none; b=gpAC/VGqAGKq0kAI5W9nD4wXjAq9/V/uRgBTaBdtpYmcA5qVigYhPUdd06uishpyCfFXahQdm6SA7H5/jme4LHVLGNZT69k0b/oZDcXZBcKgQ6QSl1pmNRAE8bOkdqoCyp53oJ8dY+3VPM8VcDrKfT2Vcb/8IHfWWkAXjUL1ntc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636316; c=relaxed/simple; bh=Kw88mGN1ylNewGbnNML6JayAGHOTLugYAGIkWDdqBk0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qwjPnOrEvBAFhU13u1ngYOix/2vmO9qaCQlKzVMCuom7s/CmyKxzO4EFFQka/FAMw8Ne7Q8axBa/CwzsmtfBmP84kuPpqamGKkWkaszzofIylpYp8WAiBTGnSKsCi1OTzWNNEcAYTHdfvBvGZNXgrBdEY2e3hylXN7DfGj04pn4= 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=ESPWB1/p; 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="ESPWB1/p" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636313; 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=RHTHi2Kr32WklCRfMoLDCM8IVMHwOL7YozXyt3+SOMU=; b=ESPWB1/pdo+q1w7j8LXRRvpMl4Y5JOXN9Zvc4821qdAzufOyuz7dTb2czPkTYqkcTXBA4i 4ozSIMPi6gm5Bz8NX4dSjNbr2pEJuCL0BzYROqeTn3SHRKc1sZg1jBT64lmHQu5RjtrviE YiQZrrJU82daq9j4eecw0HMmBuW25zI= 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-255-NhCdKdmEOrWyOMQZRvbtMA-1; Mon, 22 Jul 2024 04:18:30 -0400 X-MC-Unique: NhCdKdmEOrWyOMQZRvbtMA-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 5345C1955D48; Mon, 22 Jul 2024 08:18:29 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0CFCB195605F; Mon, 22 Jul 2024 08:18:26 +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: Mon, 22 Jul 2024 16:17:35 +0800 Message-Id: <20240722081736.20439-14-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 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 24bc1026..243eeb1a 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 22 08:17:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13738534 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 8C34B4204F for ; Mon, 22 Jul 2024 08:18:42 +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=1721636324; cv=none; b=cr+kuOJd7hB49PLRxm36ejJypi8TVBGwKfhv8R1tmbl9Mxxhqw1kGqwFUr6fbXgZNj9UK0sawPLuI5MKcMvYg08I1jArNKIGmqZIYYt9WMrMIo3Fxw0O2ZGQK7GTf7Gwfpgi0dNKpbE1fFvjFA6gPe/L8CjRu937Br80KIxRLBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721636324; c=relaxed/simple; bh=dJcl2i5i2pi5sf5Y91I4ams1vuSc+BZ9eq4FToo9RoY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MFzWYkKMEB3Cu/FXlxbkVVlJYzEXuqVZxcCXtGH4yw2loYyxpV00Pkr+LnCdYnqDV6HGY2Y56faKxqNUrdkSTFxi775JDa1AmGAzMBKF5RT2C+AqbOnPXSjC+RTU2Qqo3pRggsDtWXOxodmHXovUU2WJbxcb0SK5eCh6ygiOze0= 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=gfjtgd5i; 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="gfjtgd5i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721636321; 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=Nsjj+39nqEItGgE3TCdYcb1M8TKpAyzyPskLtoLwQrs=; b=gfjtgd5imiQovoMBJI8iKzKkhvALmpvIwh+53P20qtjIMfZYKBMUu4lrefN6cC48JKKvHO QCJV3dTLat5vcqQkuDgdNkK0Ni2ZRR6F6TYFOJVg76u3ezjzIbqmMwze/XtNnlQQUetDyO tiZFu83JBRuwDsLqWRNlpznxWUdfC5o= 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-118-_6XPLAe5Ngma2rh-Nvv0Zg-1; Mon, 22 Jul 2024 04:18:34 -0400 X-MC-Unique: _6XPLAe5Ngma2rh-Nvv0Zg-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 A99E61955D58; Mon, 22 Jul 2024 08:18:32 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 45167195605F; Mon, 22 Jul 2024 08:18:29 +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: Mon, 22 Jul 2024 16:17:36 +0800 Message-Id: <20240722081736.20439-15-xni@redhat.com> In-Reply-To: <20240722081736.20439-1-xni@redhat.com> References: <20240722081736.20439-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 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 243eeb1a..9c9c7dd1 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; }