From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 389C2244664; Tue, 29 Apr 2025 17:44:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745948683; cv=none; b=PsIJlzop/HQChQjcINdxZlauyVSRjfBZUZwENULk3+oLgCUBbUuFLz9YOy7WlJQmO9rzEWJlZY4sWKvBEUrVaeuRjcu2ugxZYPKs8nqEFFuBZ+C5wpkW1hBgbYHwmVT2j6G40+zhtdmxoS2OHgL/Jc5sbU6wFmXhHEzRBsewnV4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745948683; c=relaxed/simple; bh=yxtTjFTxiyuGajZa8DtkxSIPRB3lbF/Mty4P/CpwbOg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U8trYSIwYuo0MxHIRjWh0YknfmodXA4IoQ81xLZBoOZ8N2EVNCDF8aYeNiLghz3bDaxPa+5aHs3bxKcu2nqonv4HFR7M/rtE85wxx+iW7zsZEVyp59Qr3jovYt+KsyrYqIlaZotcQGkL35vPv7xLUD9jNinbOQPQ5MTpiO2bFwo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=oS0vRdcN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="oS0vRdcN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9E70C4CEE3; Tue, 29 Apr 2025 17:44:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745948683; bh=yxtTjFTxiyuGajZa8DtkxSIPRB3lbF/Mty4P/CpwbOg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oS0vRdcNsDJFGGcaoJ4Ucf2XYcfq+A1BVKuSluHC61Jz9hTNWd3JBsS0x4JDQobR0 lsiFb4uoTJc/6vFrq6Y7Fq/KWxDyl9tFBLLKL22yeqXA0DKAMNzGT9qOG4gqd0rnk4 Ascf55j5mYmgJrxsg1rATC7O4in3QMMn0OfFbvLE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jiasheng Jiang , Miquel Raynal Subject: [PATCH 5.15 080/373] mtd: Replace kcalloc() with devm_kcalloc() Date: Tue, 29 Apr 2025 18:39:17 +0200 Message-ID: <20250429161126.444020024@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161123.119104857@linuxfoundation.org> References: <20250429161123.119104857@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiasheng Jiang commit 1b61a59876f0eafc19b23007c522ee407f55dbec upstream. Replace kcalloc() with devm_kcalloc() to prevent memory leaks in case of errors. Fixes: 78c08247b9d3 ("mtd: Support kmsg dumper based on pstore/blk") Cc: stable@vger.kernel.org # v5.10+ Signed-off-by: Jiasheng Jiang Signed-off-by: Miquel Raynal Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/mtdpstore.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) --- a/drivers/mtd/mtdpstore.c +++ b/drivers/mtd/mtdpstore.c @@ -417,11 +417,11 @@ static void mtdpstore_notify_add(struct } longcnt = BITS_TO_LONGS(div_u64(mtd->size, info->kmsg_size)); - cxt->rmmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL); - cxt->usedmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL); + cxt->rmmap = devm_kcalloc(&mtd->dev, longcnt, sizeof(long), GFP_KERNEL); + cxt->usedmap = devm_kcalloc(&mtd->dev, longcnt, sizeof(long), GFP_KERNEL); longcnt = BITS_TO_LONGS(div_u64(mtd->size, mtd->erasesize)); - cxt->badmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL); + cxt->badmap = devm_kcalloc(&mtd->dev, longcnt, sizeof(long), GFP_KERNEL); if (!cxt->rmmap || !cxt->usedmap || !cxt->badmap) return; @@ -530,9 +530,6 @@ static void mtdpstore_notify_remove(stru mtdpstore_flush_removed(cxt); unregister_pstore_device(&cxt->dev); - kfree(cxt->badmap); - kfree(cxt->usedmap); - kfree(cxt->rmmap); cxt->mtd = NULL; cxt->index = -1; }