All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Vastargazing <vebohr@gmail.com>
Cc: linux-kernel@vger.kernel.org,  stable@vger.kernel.org,
	 Richard Weinberger <richard@nod.at>,
	 Vignesh Raghavendra <vigneshr@ti.com>,
	David Woodhouse <dwmw2@infradead.org>,
	 Lennert Buytenhek <buytenh@wantstofly.org>,
	 linux-mtd@lists.infradead.org
Subject: Re: [PATCH 3/5] mtd: maps: physmap: fix reference leak on failed device registration
Date: Mon, 04 May 2026 15:58:56 +0200	[thread overview]
Message-ID: <87a4ufs2cf.fsf@bootlin.com> (raw)
In-Reply-To: <6717e0b2a6244ee4e691dba03eb8c790c202e89e.1777889235.git.vebohr@gmail.com> (Vastargazing's message of "Mon, 4 May 2026 13:08:45 +0300")

On 04/05/2026 at 13:08:45 +03, Vastargazing <vebohr@gmail.com> wrote:

> When platform_device_register() fails in physmap_init(), the embedded
> struct device has already been initialized by device_initialize() inside
> platform_device_register(). The error path unregisters the driver but
> returns without dropping the device reference:
>
>   physmap_init()
>     -> platform_device_register(&physmap_flash)
>        -> device_initialize(&physmap_flash.dev)   /* kref = 1 */
>        -> platform_device_add(&physmap_flash)     /* fails */
>     <- platform_driver_unregister() called, but kref still 1
>
> Per platform_device_register() kernel-doc:
>
>   NOTE: _Never_ directly free @pdev after calling this function, even if
>   it returned an error! Always use platform_device_put() to give up the
>   reference initialised in this function instead.
>
> Fix this by calling platform_device_put() before unregistering the driver.
>
> Fixes: 73566edf9b91 ("[MTD] Convert physmap to platform driver")
> Cc: stable@vger.kernel.org
> Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
> Signed-off-by: Vastargazing <vebohr@gmail.com>

Somehow b4 applied another patch from that series, I'm not sure why. I
just dropped it. Please resend this patch alone.

Also, your SoB line seems to be incorrect, we need a proper name, please
have a loot at the DCO.

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: Vastargazing <vebohr@gmail.com>
Cc: linux-kernel@vger.kernel.org,  stable@vger.kernel.org,
	 Richard Weinberger <richard@nod.at>,
	 Vignesh Raghavendra <vigneshr@ti.com>,
	David Woodhouse <dwmw2@infradead.org>,
	 Lennert Buytenhek <buytenh@wantstofly.org>,
	 linux-mtd@lists.infradead.org
Subject: Re: [PATCH 3/5] mtd: maps: physmap: fix reference leak on failed device registration
Date: Mon, 04 May 2026 15:58:56 +0200	[thread overview]
Message-ID: <87a4ufs2cf.fsf@bootlin.com> (raw)
In-Reply-To: <6717e0b2a6244ee4e691dba03eb8c790c202e89e.1777889235.git.vebohr@gmail.com> (Vastargazing's message of "Mon, 4 May 2026 13:08:45 +0300")

On 04/05/2026 at 13:08:45 +03, Vastargazing <vebohr@gmail.com> wrote:

> When platform_device_register() fails in physmap_init(), the embedded
> struct device has already been initialized by device_initialize() inside
> platform_device_register(). The error path unregisters the driver but
> returns without dropping the device reference:
>
>   physmap_init()
>     -> platform_device_register(&physmap_flash)
>        -> device_initialize(&physmap_flash.dev)   /* kref = 1 */
>        -> platform_device_add(&physmap_flash)     /* fails */
>     <- platform_driver_unregister() called, but kref still 1
>
> Per platform_device_register() kernel-doc:
>
>   NOTE: _Never_ directly free @pdev after calling this function, even if
>   it returned an error! Always use platform_device_put() to give up the
>   reference initialised in this function instead.
>
> Fix this by calling platform_device_put() before unregistering the driver.
>
> Fixes: 73566edf9b91 ("[MTD] Convert physmap to platform driver")
> Cc: stable@vger.kernel.org
> Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
> Signed-off-by: Vastargazing <vebohr@gmail.com>

Somehow b4 applied another patch from that series, I'm not sure why. I
just dropped it. Please resend this patch alone.

Also, your SoB line seems to be incorrect, we need a proper name, please
have a loot at the DCO.

Thanks,
Miquèl

  reply	other threads:[~2026-05-04 13:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1777889235.git.vebohr@gmail.com>
2026-05-04 10:08 ` [PATCH 1/5] misc: eeprom: digsy_mtc: fix reference leak on failed device registration Vastargazing
2026-05-04 10:08   ` Vastargazing
2026-05-04 10:08 ` [PATCH 2/5] platform/chrome: cros_ec_lpc: " Vastargazing
2026-05-04 10:08   ` Vastargazing
2026-05-05  2:40   ` Tzung-Bi Shih
2026-05-04 10:08 ` [PATCH 3/5] mtd: maps: physmap: " Vastargazing
2026-05-04 10:08   ` Vastargazing
2026-05-04 13:58   ` Miquel Raynal [this message]
2026-05-04 13:58     ` Miquel Raynal
2026-05-04 10:08 ` [PATCH 4/5] perf: arm: pmu: " Vastargazing
2026-05-04 10:08   ` Vastargazing
2026-05-04 11:47   ` sashiko-bot
2026-05-05  8:50   ` Sudeep Holla
2026-05-04 10:08 ` [PATCH 5/5] mfd: sm501: " Vastargazing
2026-05-04 10:08   ` Vastargazing
2026-05-04 12:48   ` [PATCH v2] " Valery Borovsky
2026-05-04 13:52     ` Miquel Raynal
2026-05-05 15:00       ` Lee Jones
2026-05-05 15:12         ` Miquel Raynal
2026-05-06 15:40     ` [PATCH v3] " Valery Borovsky
2026-05-14 14:54       ` Lee Jones
2026-05-14 16:26       ` Valery Borovsky
2026-05-05 10:36 ` [PATCH 1/5] perf/arm_pmu_acpi: fix reference leak in arm_pmu_acpi_probe error path Valery Borovsky
2026-05-05 10:36   ` Valery Borovsky
2026-05-06 15:43 ` [PATCH 3/5] mtd: maps: physmap-core: fix reference leak on failed device registration Valery Borovsky
2026-05-06 15:43   ` Valery Borovsky

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=87a4ufs2cf.fsf@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=buytenh@wantstofly.org \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=stable@vger.kernel.org \
    --cc=vebohr@gmail.com \
    --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.