mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Dan Williams" <djbw@fastmail.com>
To: "Guangshuo Li" <lgs201920130244@gmail.com>,
	"Dan J Williams" <dan.j.williams@intel.com>,
	"Vishal Verma" <vishal.l.verma@intel.com>,
	"Dave Jiang" <dave.jiang@intel.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: Re: [PATCH v3] device-dax: Fix refcount leak in __devm_create_dev_dax() error path
Date: Mon, 13 Apr 2026 08:36:55 -0700	[thread overview]
Message-ID: <adf2a8bc-ce1c-4b88-957b-5d5643810d19@app.fastmail.com> (raw)
In-Reply-To: <20260413135625.2890908-1-lgs201920130244@gmail.com>



On Mon, Apr 13, 2026, at 6:56 AM, Guangshuo Li wrote:
> After device_initialize(), the embedded struct device in dev_dax is
> expected to be released through the device core with put_device().
>
> In __devm_create_dev_dax(), several failure paths after
> device_initialize() free dev_dax directly instead of dropping the device
> reference, which bypasses the normal device core lifetime handling and
> leaks the reference held on the embedded struct device.

Like I said before please focus on the practical problem this causes. It is always the case that device setup will have some steps  that are handlded by direct kfree before switching to a put_device() model.

In this case the practical problem is that the memory allocation from dev_set_name() is leaked. Also the error return from dev_set_name() is ignored.

> The issue was identified by a static analysis tool I developed and
> confirmed by manual review.

If you are going to be doing more of these please make sure not to just rework code just to get all freeing done by put_device() when not strictly necessary.

One issue to avoid is early returns in the error goto path.

In this case I believe you can address this by moving the device_initialize() later in the function. Make it so that the switch from error unwind to put_device() is the last step of the setup.

It would be nice to fix the dev_set_name() error handling in a follow-on patch as well.

      parent reply	other threads:[~2026-04-13 15:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-13 13:56 Guangshuo Li
2026-04-13 15:11 ` Jonathan Cameron
2026-04-13 15:36 ` Dan Williams [this message]

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=adf2a8bc-ce1c-4b88-957b-5d5643810d19@app.fastmail.com \
    --to=djbw@fastmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=vishal.l.verma@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®