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 A046828D82C; Wed, 23 Apr 2025 15:10:57 +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=1745421057; cv=none; b=a6v9d5H2aNl5FLqexbSw/33Lr4kV06piBGXJJapmSb4KWy5QbIzmhoYEQalbswlZX+FiEL4QJMjXXx5pvhBh4/UpMQG/cdIZ6JqCYXfKvTn0jL+VoHYCdlAFWR/GDMs3pnfmLpwwr/PBDaPjidFqOxkwzFmc4hQloNd+5cPU71I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745421057; c=relaxed/simple; bh=ddJFFBdC73TIlFqzshy3Sg0mSboX9GUsDG317hVhjis=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oFMLh7+jVuWAF+aVCNleSI3xK0CbLtqqSjAp0yP1j726bqW7L7r/AehgzyV2M5HnfW5v9AQUWq0vA7jPZPUIYZmPc0DXhc2uBOuxoeB+co4aTBSyGjPPorB8kvvzHNxOQ7V2we8urHWjoZq0SjeF/s9dALXANxgLb4ZhO/lIW0A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=GYLd24dR; 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="GYLd24dR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3273AC4CEE2; Wed, 23 Apr 2025 15:10:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745421057; bh=ddJFFBdC73TIlFqzshy3Sg0mSboX9GUsDG317hVhjis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GYLd24dRVgWioIqW27bJR+u5n6/7BrkG2sBrZ06wYiMApWxqbL0PD1fH70X2+oxIW +lxsW+V3RuMkmQBF7G3mwzOFuhrH4tACLvfRLdPHNhBZBXMa9ulv5rjBYHA6IuJeEC 71So6KM/OeoCxtIt4Adg/14iO5yN9ehlu//AWxwQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jiasheng Jiang , Miquel Raynal Subject: [PATCH 6.1 104/291] mtd: Replace kcalloc() with devm_kcalloc() Date: Wed, 23 Apr 2025 16:41:33 +0200 Message-ID: <20250423142628.602163020@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250423142624.409452181@linuxfoundation.org> References: <20250423142624.409452181@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 6.1-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; }