All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Jiasheng Jiang <jiashengjiangcool@gmail.com>
Cc: richard@nod.at,  vigneshr@ti.com,  gmpy.liaowx@gmail.com,
	kees@kernel.org,  linux-mtd@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd: Add check for kcalloc()
Date: Mon, 03 Feb 2025 09:32:15 +0100	[thread overview]
Message-ID: <87tt9bxwc0.fsf@bootlin.com> (raw)
In-Reply-To: <20250202205456.40790-1-jiashengjiangcool@gmail.com> (Jiasheng Jiang's message of "Sun, 2 Feb 2025 20:54:56 +0000")

On 02/02/2025 at 20:54:56 GMT, Jiasheng Jiang <jiashengjiangcool@gmail.com> wrote:

> Add a check for kcalloc() and print an error message if it fails.

Checking, yes, but logging, no. IIRC the core does it already if required.

> Fixes: 78c08247b9d3 ("mtd: Support kmsg dumper based on pstore/blk")

Cc: stable is missing

> Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
> ---
>  drivers/mtd/mtdpstore.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/mtd/mtdpstore.c b/drivers/mtd/mtdpstore.c
> index 7ac8ac901306..368997155c07 100644
> --- a/drivers/mtd/mtdpstore.c
> +++ b/drivers/mtd/mtdpstore.c
> @@ -423,6 +423,11 @@ static void mtdpstore_notify_add(struct mtd_info *mtd)
>  	longcnt = BITS_TO_LONGS(div_u64(mtd->size, mtd->erasesize));
>  	cxt->badmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
>  
> +	if (!cxt->rmmap || !cxt->usedmap || !cxt->badmap) {
> +		dev_err(&mtd->dev, "failed to allocate memory for map\n");
> +		return;
> +	}
> +
>  	/* just support dmesg right now */
>  	cxt->dev.flags = PSTORE_FLAGS_DMESG;
>  	cxt->dev.zone.read = mtdpstore_read;

What if register_pstore_device() fails? Your only partially fixing the
problem if you don't handle the free()s there as well.

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

WARNING: multiple messages have this Message-ID (diff)
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Jiasheng Jiang <jiashengjiangcool@gmail.com>
Cc: richard@nod.at,  vigneshr@ti.com,  gmpy.liaowx@gmail.com,
	kees@kernel.org,  linux-mtd@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd: Add check for kcalloc()
Date: Mon, 03 Feb 2025 09:32:15 +0100	[thread overview]
Message-ID: <87tt9bxwc0.fsf@bootlin.com> (raw)
In-Reply-To: <20250202205456.40790-1-jiashengjiangcool@gmail.com> (Jiasheng Jiang's message of "Sun, 2 Feb 2025 20:54:56 +0000")

On 02/02/2025 at 20:54:56 GMT, Jiasheng Jiang <jiashengjiangcool@gmail.com> wrote:

> Add a check for kcalloc() and print an error message if it fails.

Checking, yes, but logging, no. IIRC the core does it already if required.

> Fixes: 78c08247b9d3 ("mtd: Support kmsg dumper based on pstore/blk")

Cc: stable is missing

> Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
> ---
>  drivers/mtd/mtdpstore.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/mtd/mtdpstore.c b/drivers/mtd/mtdpstore.c
> index 7ac8ac901306..368997155c07 100644
> --- a/drivers/mtd/mtdpstore.c
> +++ b/drivers/mtd/mtdpstore.c
> @@ -423,6 +423,11 @@ static void mtdpstore_notify_add(struct mtd_info *mtd)
>  	longcnt = BITS_TO_LONGS(div_u64(mtd->size, mtd->erasesize));
>  	cxt->badmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
>  
> +	if (!cxt->rmmap || !cxt->usedmap || !cxt->badmap) {
> +		dev_err(&mtd->dev, "failed to allocate memory for map\n");
> +		return;
> +	}
> +
>  	/* just support dmesg right now */
>  	cxt->dev.flags = PSTORE_FLAGS_DMESG;
>  	cxt->dev.zone.read = mtdpstore_read;

What if register_pstore_device() fails? Your only partially fixing the
problem if you don't handle the free()s there as well.

Thanks,
Miquèl

  reply	other threads:[~2025-02-03  8:33 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-02 20:54 [PATCH] mtd: Add check for kcalloc() Jiasheng Jiang
2025-02-02 20:54 ` Jiasheng Jiang
2025-02-03  8:32 ` Miquel Raynal [this message]
2025-02-03  8:32   ` Miquel Raynal
2025-02-03 18:04   ` Christophe JAILLET
2025-02-03 18:04     ` Christophe JAILLET
2025-02-04  2:33     ` [PATCH v2] mtd: Add check and kfree() " Jiasheng Jiang
2025-02-04  2:33       ` Jiasheng Jiang
2025-02-04  6:17       ` Christophe JAILLET
2025-02-04  6:17         ` Christophe JAILLET
2025-02-04  6:36         ` Jiri Slaby
2025-02-04  6:36           ` Jiri Slaby
2025-02-04 20:50           ` Christophe JAILLET
2025-02-04 20:50             ` Christophe JAILLET
2025-02-05  2:31             ` [PATCH v3 1/2] mtd: Replace kcalloc() with devm_kcalloc() Jiasheng Jiang
2025-02-05  2:31               ` Jiasheng Jiang
2025-02-05  2:31               ` [PATCH v3 2/2] mtd: Add check for devm_kcalloc() Jiasheng Jiang
2025-02-05  2:31                 ` Jiasheng Jiang
2025-02-07 14:46               ` [PATCH v3 1/2] mtd: Replace kcalloc() with devm_kcalloc() Miquel Raynal
2025-02-07 14:46                 ` Miquel Raynal
2025-02-05  2:35             ` [PATCH v2] mtd: Add check and kfree() for kcalloc() Jiasheng Jiang
2025-02-05  2:35               ` Jiasheng Jiang
2025-02-04  6:32       ` Jiri Slaby
2025-02-04  6:32         ` Jiri Slaby
2025-02-04  9:17       ` Miquel Raynal
2025-02-04  9:17         ` Miquel Raynal
2025-02-04  2:37     ` [PATCH] mtd: Add check " Jiasheng Jiang
2025-02-04  2:37       ` Jiasheng Jiang
2025-02-04  2:34   ` Jiasheng Jiang
2025-02-04  2:34     ` Jiasheng Jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tt9bxwc0.fsf@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=gmpy.liaowx@gmail.com \
    --cc=jiashengjiangcool@gmail.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.