From patchwork Tue Feb 20 10:56:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13563872 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 018EF6519D for ; Tue, 20 Feb 2024 11:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426804; cv=none; b=MyVczHgDAR92CIcEgICGIZzRiaEzCSxWvaHRrL8OlrQRt72oCTtr1PhCDAsBPqZCO2PqQvMQnt21vbTy4kDqrXkzMJUUgqCC0wAnBLyxwoYJUukZgILKGGdfVGOwqux22mEAnUH0LdNsi3nTMV9XVSOqyu2JL+ku0ooilkRPeWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426804; c=relaxed/simple; bh=x2KoYftDEHz0lbufDPCeiEQgtXN1BoQ0ClVX3Sq4w30=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GaoMBwiPxLx0y4w3yzUuizqr5pTaDg7e6fE/WqRTLuB4pvFYLPElkntyjWS0LAyQNWg+O6Tba7HEY4Hb3nIXOflbv3xdt/QB+gQOSUQtyjwUggyyMuFRPLmfFAYGuerwK1YmG1Qrir3/Lzhw2PkcrzkOTWBSdwYnLcriHzS6vHE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bZI/LDdv; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bZI/LDdv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708426802; x=1739962802; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=x2KoYftDEHz0lbufDPCeiEQgtXN1BoQ0ClVX3Sq4w30=; b=bZI/LDdvCLLgvlCGLuMLLsVqiXY6E2RCeKcPr673ljKBGQPj8xfAFYyJ jJ5/h9ELejhUmJLNPRB7gBHPvn91LEgqFCxyJmrSIefQw2Ai0MuItnXvC +NIYssiw4gAaj2A3jEMlxJJubn4+NyxlnPU3gpvaJuZNMGzL8K1ePjsiD BCaF/8FGtTVyxa4+CGguNM/ED4yGue7l3l5faw1q6adRSwq5uEnUoBvg5 ZRI74qr+5eL+mxAPdAC3F3bSzTAFqmlgyc7291+iOQORWOM3yfNZdw8Aj g8b0djSjzDAc/dFO6HW6CtcbRwGKNj6T05UxgCJc5c2pqfjeTVDm76cde A==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="13934349" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="13934349" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 03:00:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="4735117" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa010.fm.intel.com with ESMTP; 20 Feb 2024 03:00:00 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 1/6] Create: add_disk_to_super() fix resource leak Date: Tue, 20 Feb 2024 11:56:07 +0100 Message-Id: <20240220105612.31058-2-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240220105612.31058-1-mateusz.kusiak@intel.com> References: <20240220105612.31058-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fixes resource leak in add_disk_to_super(). Signed-off-by: Mateusz Kusiak --- Create.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Create.c b/Create.c index 8082f54a8fdc..7e9170b6a1ac 100644 --- a/Create.c +++ b/Create.c @@ -279,8 +279,10 @@ static int add_disk_to_super(int mdfd, struct shape *s, struct context *c, dv->devname); return 1; } - if (!fstat_is_blkdev(fd, dv->devname, &rdev)) + if (!fstat_is_blkdev(fd, dv->devname, &rdev)) { + close(fd); return 1; + } info->disk.major = major(rdev); info->disk.minor = minor(rdev); } @@ -289,6 +291,7 @@ static int add_disk_to_super(int mdfd, struct shape *s, struct context *c, if (st->ss->add_to_super(st, &info->disk, fd, dv->devname, dv->data_offset)) { ioctl(mdfd, STOP_ARRAY, NULL); + close(fd); return 1; } st->ss->getinfo_super(st, info, NULL); @@ -297,6 +300,7 @@ static int add_disk_to_super(int mdfd, struct shape *s, struct context *c, *zero_pid = write_zeroes_fork(fd, s, st, dv); if (*zero_pid <= 0) { ioctl(mdfd, STOP_ARRAY, NULL); + close(fd); return 1; } } From patchwork Tue Feb 20 10:56:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13563873 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 C673F604A9 for ; Tue, 20 Feb 2024 11:00:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426809; cv=none; b=YQmpteSurw0szUNUpQZmOadOtr0OahBL0aiLDWZQFV/9UvWh5+FEnEXBVCj7/Hu8rRwZ13+OHLoz/9ZeXd2xGKYKDjElygHQxRoTMJW+y1q+IUkXySskRahmbi8BTNsOh4QgaEb6uM9cjrcR73O8ABgamL/obuZRZZDDZThZTBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426809; c=relaxed/simple; bh=DbGNHeRxTgEqgUfwmC1IQ8ODWiln5LFjufasgHVt1aU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Se5UcPlpIDNNog0zGeR1aLHsXHZZ1xSC0qh4bVU2hHM6tQcHTPtfkRzZ+daV2kHncaJbIOqdGNO3FATE77uBKIhteqUUYgmbfdIh6K1X9LPGZxzEqL9e8Ss2jcr49xn6/ueggGWBx3o9nylXMz4Q8L3h4T5uq01og7iATL0LaP0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=AgFn+AuP; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AgFn+AuP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708426808; x=1739962808; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DbGNHeRxTgEqgUfwmC1IQ8ODWiln5LFjufasgHVt1aU=; b=AgFn+AuPGcPaZBJP+RPlQ1vg2492K3NYv0yaRLAxV+A5/dYsNSzOI1vq t2U7+m+nKWbIRr+EhyTCIKtOqWUA4D9mgGIgd6GzVk4W5a6PJ1b8hPBDw yUkS7olVe8ZgBzAJNTSlMr3apNeSbI30wt4ils74tsOZn1fqAX7izWihz qMr58EvRtOs9Z11njq73ifvsonluIala1aRqPOepPV1ZgadiJiaE5lc/x MgiUNC/OSFe16XPJvP+EJhWujVyQ76rTp300HtBdQTKtks3CPVx79qbAZ SIpJqW4U4ZcQf9slUaYP127nwZQ0XbYi2BeGIMcyUEDiBS2SRGnbsGEVC A==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="13934369" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="13934369" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 03:00:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="4735147" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa010.fm.intel.com with ESMTP; 20 Feb 2024 03:00:06 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 2/6] mdadm: signal_s() init variables Date: Tue, 20 Feb 2024 11:56:08 +0100 Message-Id: <20240220105612.31058-3-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240220105612.31058-1-mateusz.kusiak@intel.com> References: <20240220105612.31058-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Init sigaction structs in signal_s(). This approach might throw warnings for GCC 4.x and lower. Signed-off-by: Mateusz Kusiak --- mdadm.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mdadm.h b/mdadm.h index 1f28b3e754be..75c887e4c64c 100644 --- a/mdadm.h +++ b/mdadm.h @@ -1856,11 +1856,10 @@ static inline char *to_subarray(struct mdstat_ent *ent, char *container) */ static inline sighandler_t signal_s(int sig, sighandler_t handler) { - struct sigaction new_act; - struct sigaction old_act; + struct sigaction new_act = {0}; + struct sigaction old_act = {0}; new_act.sa_handler = handler; - new_act.sa_flags = 0; if (sigaction(sig, &new_act, &old_act) == 0) return old_act.sa_handler; From patchwork Tue Feb 20 10:56:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13563874 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 2948F64CF5 for ; Tue, 20 Feb 2024 11:00:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426816; cv=none; b=UmX2I2psM8iRNj7mQtm80FqSMy1TUC0ap+5ZWLkCrkfVc9DOmjih+B3Tuw/RlXZ7FoL/WGWDCQNfBqVwMoRS1p8X310mpAMrFvq4i2oFw6T3HsdzRKz+j7TLLTpcSHHGqQq3JlGShQb/Kqq0cpX3N7AGoytJQW6cvCY1IHN71Dg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426816; c=relaxed/simple; bh=TVIiAVMXFZ8QR3UltfsNMHwwwGfke4LeHTL9T2TmJGw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=B1JNzLxDYR34VLkCCaiSHkO7dZW5yjZjXtbN7jU7y3ZHQTXUPhTP514W26b2QbIxC0CZS/UeZ8f5P2nIjxwuSF47LJGHyllA3JTtI0FnuW5Z0vSJhj1uPrUAF37r0kLqNM2TDeQFoPQm6MWFH5K1Un1I9vui79yw8GU3PRbcBko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ArQTQG0k; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ArQTQG0k" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708426815; x=1739962815; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TVIiAVMXFZ8QR3UltfsNMHwwwGfke4LeHTL9T2TmJGw=; b=ArQTQG0kIQxEMqP2v9QMEfFczX0h2JhQ00X4uZdsz/vWe8tJzXJRTc0t VCpPO0K4Vrr3C/QkGjcJN0ew7trpp3YclYXfI+tlKvsXykbln8E3HkVB+ mLf5A/03jIFEZuPRVAQCJlc+v8AViehkB/Vl4EmP+uyluviqoAf2/6ncm kD1NEu424g1FKEkLeQpi8NfvHEMw7BHvEmRU9kVeVowVC9y7dk2gBlxde vTfgspIBioEtoyFKoV7WrjjBFjw6Inu2Ppt+6+hXLIkoAWrlyjMMV9f7b Y08Yz0cjgrqywrChRf9a4IOsx4fOaIyki4GX57YS7g/pOnP794emsDYWJ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="13934373" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="13934373" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 03:00:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="4735165" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa010.fm.intel.com with ESMTP; 20 Feb 2024 03:00:13 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 3/6] Monitor: open file before check in check_one_sharer() Date: Tue, 20 Feb 2024 11:56:09 +0100 Message-Id: <20240220105612.31058-4-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240220105612.31058-1-mateusz.kusiak@intel.com> References: <20240220105612.31058-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Open file before performing checks in check_one_sharer() to avoid file tampering. Remove redundant access check. Signed-off-by: Mateusz Kusiak --- Monitor.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Monitor.c b/Monitor.c index 824a69fc6b79..7cee95d4487a 100644 --- a/Monitor.c +++ b/Monitor.c @@ -451,20 +451,17 @@ static int check_one_sharer(int scan) return 2; } - if (access(AUTOREBUILD_PID_PATH, F_OK) != 0) - return 0; - - if (!is_file(AUTOREBUILD_PID_PATH)) { - pr_err("%s is not a regular file.\n", AUTOREBUILD_PID_PATH); - return 2; - } - fp = fopen(AUTOREBUILD_PID_PATH, "r"); if (!fp) { pr_err("Cannot open %s file.\n", AUTOREBUILD_PID_PATH); return 2; } + if (!is_file(AUTOREBUILD_PID_PATH)) { + pr_err("%s is not a regular file.\n", AUTOREBUILD_PID_PATH); + return 2; + } + if (fscanf(fp, "%d", &pid) != 1) { pr_err("Cannot read pid from %s file.\n", AUTOREBUILD_PID_PATH); fclose(fp); From patchwork Tue Feb 20 10:56:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13563875 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 155D0604A9 for ; Tue, 20 Feb 2024 11:00:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426822; cv=none; b=fRdTgiW/tONpXlZCRtvsk0gx8Ia+x32zt/GGHm3jhCiyuPPc97cPsyS0aEhlHnsuMavNKtbWFysPuZVs7vg9eXFHrbsubYzsF9seC13bcVLcet4HkxACmpr/X0mgs3eJtwoYWmrHriJETDKsYw7+M3nCnThqAL0dHe4/PiBYA0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426822; c=relaxed/simple; bh=VLHAm3B8oDXNldh/BoehL9lUhriSMItyFiQV7EYEbe0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R/RYcRePuZsOEDgNTyv7a5twKtuCb5NOGX0gdsql7xwVTnIQ5i0N4+kayyPpxb7/66uE3ZsZ8v2z/MgmTsFNUPluZyn07TmBRDO0TkpFA/fGSNIdFeqCb4Fw19BapMmfiJl5S9ZwNlSyPGdbWsE9SL2vDZZuoSPvJ3P6k249Y34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=b6iiPVUx; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="b6iiPVUx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708426821; x=1739962821; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VLHAm3B8oDXNldh/BoehL9lUhriSMItyFiQV7EYEbe0=; b=b6iiPVUxNdVS94iucVs4NqSOhBGMkfAemOpTCdcQoknROGXAMGwYuayb I4axKCQlgsRnMo/Bda5tYhw2M7g10FYkMRHViLweclVfmW06Xhvv+x8ED rBpm8cB0TdAwcgD+1GRt86okdjzdzlx9UyB3OCQoQo3GHn8tslTyskrMz fjuRaadm5b+7WImz5VPV4FoEsWjGJRM7rpP27fudOqR4aUblYTYUh49E6 NZ4rhKG3CcPv1P/wQrCeo5yHsxgdaXbL7PaPUe16+Pw5IXVBnSyhusAdU qGZauG7kcQ6A2HBv5xW3obyvIyAwEr3knnpZgiAaZaTAt4P1ub2ee09AQ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="13934376" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="13934376" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 03:00:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="4735204" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa010.fm.intel.com with ESMTP; 20 Feb 2024 03:00:19 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 4/6] Grow: remove dead condition in Grow_reshape() Date: Tue, 20 Feb 2024 11:56:10 +0100 Message-Id: <20240220105612.31058-5-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240220105612.31058-1-mateusz.kusiak@intel.com> References: <20240220105612.31058-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove dead "if" condition from Grow_reshape(). Sysfs read check is performed earlier in the code. Signed-off-by: Mateusz Kusiak --- Grow.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Grow.c b/Grow.c index f95dae82ef0d..dad7294dac32 100644 --- a/Grow.c +++ b/Grow.c @@ -2097,11 +2097,7 @@ int Grow_reshape(char *devname, int fd, /* got truncated to 32bit, write to * component_size instead */ - if (sra) - rv = sysfs_set_num(sra, NULL, - "component_size", s->size); - else - rv = -1; + rv = sysfs_set_num(sra, NULL, "component_size", s->size); } else { rv = md_set_array_info(fd, &array); From patchwork Tue Feb 20 10:56:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13563876 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 03BF164CF5 for ; Tue, 20 Feb 2024 11:00:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426828; cv=none; b=mj/L8pUABDfWdZ8Inir0y3JgUwKpaLk7bmkV10AsR4MyhsvEouUTGgqAPhMiIExEEjnt9R2ta/tBGbiYhu1vsW+v5Wqjrx5xsuf3LA4EsKNnC1zr0sS401dh3vs+pQPuzGAQUAEE+7qVNAm2eB0d1PibZCSkSyQXBq3p6DIm3Rg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426828; c=relaxed/simple; bh=vUFdPLdyi1OERlX10UiyC7l5o+OfqCTO3hq3rWuCthU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MX4v6D15Ef5T30/+qrnP40tk75OYOmJnTP0YDGBfx5azU69xyalJ+vvt31wO16R8CfuGK9ftnlWpsxz3aK28HvMZurwHEBGE8w/IBo1BF06eQruB7rBZLrDfOfn7oaHaJ1KaY4w3s9ZMXs0JeJRjEJzL37Hp7mz0gdprfUu/kZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Tg7ReYkP; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Tg7ReYkP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708426827; x=1739962827; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vUFdPLdyi1OERlX10UiyC7l5o+OfqCTO3hq3rWuCthU=; b=Tg7ReYkPp3p2WUcUUUnjqyQQhRvleluUugCW+kc3NQjCRjdkNep0LMbU aiYPJUU2eH/tDfX2dMUU9xOBZJ5IABaMN6pCZXCtnA+1zW1dnyUDd8J6Z jFt4hD3lKJ918MwKpUfBaoKYi1VZPmtHReh87KmBDyhv0su88DQ3xYX+G k44bv8OCu1rKu//zwaHSRDR5g2SAjDMAeUYULMZ44StUs05XteZbd2Hi2 dikXOt0zkAY1pqDOlV70AQ17KZEpb5I9iYd3eytvFGHNB4TYUkXobRuaD d8u/0VSXefjn/Trp7i/EWuZ1zQYIqqhToGfh74zaF8a7n8zXEyJd90+z3 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="13934381" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="13934381" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 03:00:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="4735214" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa010.fm.intel.com with ESMTP; 20 Feb 2024 03:00:25 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 5/6] super1: check fd before passing to get_dev_size() in add_to_super1() Date: Tue, 20 Feb 2024 11:56:11 +0100 Message-Id: <20240220105612.31058-6-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240220105612.31058-1-mateusz.kusiak@intel.com> References: <20240220105612.31058-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Check if file descriptor is valid before passing it to get_dev_size() in add_to_super(). Signed-off-by: Mateusz Kusiak --- super1.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/super1.c b/super1.c index 871d19f0398c..5439b7bb1240 100644 --- a/super1.c +++ b/super1.c @@ -1752,7 +1752,10 @@ static int add_to_super1(struct supertype *st, mdu_disk_info_t *dk, di->devname = devname; di->disk = *dk; di->data_offset = data_offset; - get_dev_size(fd, NULL, &di->dev_size); + + if (is_fd_valid(fd)) + get_dev_size(fd, NULL, &di->dev_size); + di->next = NULL; *dip = di; From patchwork Tue Feb 20 10:56:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13563877 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 3F5D9604A9 for ; Tue, 20 Feb 2024 11:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426834; cv=none; b=Hdn9C7T1RF5PGMYn8bnfVpb5261ziRh/Fd+H2HjcknZe3SESZiqIQTpWmDtfTPgi5gQfTxKSu04xsS8jUyWuoHDVD1cvozmVV378W/2goWgLV7t8hGN3X96Z2FsD3rfjAZUMr8A5EihfQ8tMlHMEEuMQJedHQNzpQskq/QcheJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708426834; c=relaxed/simple; bh=goeZTsVUWl8XpsWDbgsqdphIdZ2DWCpOirbPrvz3Iag=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MB2NtceVjs1BhAwcE8B2ycPgGRqRm3EXOVtfNGththq41rM3RRtVsvx2iX54DCtQtDorDR2iD+fwUEf+05z5jc31sunmoSMyY2wKaBQy+a22lPjceMFdSuhK6SxaxBrTiz2oSy17fzfTgv5lLuPcb+UEscLhLayXXtmVUAobEkA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bFVDkXEU; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bFVDkXEU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708426833; x=1739962833; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=goeZTsVUWl8XpsWDbgsqdphIdZ2DWCpOirbPrvz3Iag=; b=bFVDkXEUnczyVWrKCHokkSlkh1XWhFSGh5FpGkazMYMHT3dRYwKdoOfV yDvz3mrjJezpkD6mcXZVkGB4kIDOrEaMYUUr2TUjUsSL1kIkJkDEmvqka DoE3c2wYWV5DBWmZdMEEgw/q/jWNxyeu6ldCmGb7/z2P9jtvy2POgZTmK BJjTRygHqNaKCBEfpvfBQZouNUCZb9HHH/MQQiUaYoAc7McjwoH0oRcPO Dj3yQ3kKMhJWWTuUjwEjUVS2yoc2hGhHPudufaYLeZlZWhdOwS0diDNKF SmIJEuAmnZpGtT4FmS34adLwB9YYDEm3AJYtn/GgA1Z5Sh7E+s7/pXng0 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="13934389" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="13934389" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 03:00:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="4735223" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa010.fm.intel.com with ESMTP; 20 Feb 2024 03:00:31 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 6/6] mdmon: refactor md device name check in main() Date: Tue, 20 Feb 2024 11:56:12 +0100 Message-Id: <20240220105612.31058-7-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240220105612.31058-1-mateusz.kusiak@intel.com> References: <20240220105612.31058-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Refactor mdmon main function to verify if fd is valid prior to checking device name. This is due to static code analysis complaining after change b938519e7719 ("util: remove obsolete code from get_md_name"). Signed-off-by: Mateusz Kusiak --- mdmon.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mdmon.c b/mdmon.c index a2038fe6c35f..5fdb5cdb5a49 100644 --- a/mdmon.c +++ b/mdmon.c @@ -302,12 +302,12 @@ static int mdmon(char *devnm, int must_fork, int takeover); int main(int argc, char *argv[]) { char *container_name = NULL; - char *devnm = NULL; int status = 0; int opt; int all = 0; int takeover = 0; int dofork = 1; + int mdfd = -1; bool help = false; static struct option options[] = { {"all", 0, NULL, 'a'}, @@ -410,19 +410,20 @@ int main(int argc, char *argv[]) free_mdstat(mdstat); return status; - } else { - int mdfd = open_mddev(container_name, 0); - devnm = fd2devnm(mdfd); + } + + mdfd = open_mddev(container_name, 0); + if (is_fd_valid(mdfd)) { + char *devnm = fd2devnm(mdfd); close(mdfd); - } - if (!devnm) { - pr_err("%s is not a valid md device name\n", - container_name); - return 1; + if (devnm) + return mdmon(devnm, dofork && do_fork(), takeover); } - return mdmon(devnm, dofork && do_fork(), takeover); + + pr_err("%s is not a valid md device name\n", container_name); + return 1; } static int mdmon(char *devnm, int must_fork, int takeover)