From: sashiko-bot@kernel.org
To: "Hemanth Selam" <hemanth.selam@gmail.com>
Cc: nvdimm@lists.linux.dev
Subject: Re: [PATCH v2] nvdimm/pmem: Release gendisk on probe failure
Date: Mon, 31 Aug 2026 04:45:07 +0000 [thread overview]
Message-ID: <20260831044508.520351F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831043459.1298059-1-hemanth.selam@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] NULL pointer dereference in sysfs attributes (write_cache) when alloc_dax() fails with -EOPNOTSUPP
--
commit b72cbfedec624805721d1461cccfb6dbba985b5b
Author: Hemanth Selam <hemanth.selam@gmail.com>
nvdimm/pmem: Release gendisk on probe failure
This commit fixes a memory leak in the pmem namespace probe by ensuring
the gendisk is properly released through the common cleanup path if
devm_init_badblocks() fails.
> diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
> index 30a51c365ce8b..648fc7d660639 100644
> --- a/drivers/nvdimm/pmem.c
> +++ b/drivers/nvdimm/pmem.c
> @@ -563,8 +563,10 @@ static int pmem_attach_disk(struct device *dev,
> nvdimm_namespace_disk_name(ndns, disk->disk_name);
> set_capacity(disk, (pmem->size - pmem->pfn_pad - pmem->data_offset)
> / 512);
> - if (devm_init_badblocks(dev, &pmem->bb))
> - return -ENOMEM;
> + if (devm_init_badblocks(dev, &pmem->bb)) {
> + rc = -ENOMEM;
> + goto out;
> + }
> nvdimm_badblocks_populate(nd_region, &pmem->bb, &bb_range);
> disk->bb = &pmem->bb;
[Severity: High]
This isn't a bug introduced by this patch, but I wanted to ask about the error
handling for alloc_dax() just below this code.
In pmem_attach_disk(), if alloc_dax() fails with -EOPNOTSUPP, the code
gracefully falls back and leaves pmem->dax_dev as NULL:
dax_dev = alloc_dax(pmem, &pmem_dax_ops);
if (IS_ERR(dax_dev)) {
rc = PTR_ERR(dax_dev);
if (rc != -EOPNOTSUPP)
goto out;
} else {
...
}
rc = device_add_disk(dev, disk, pmem_attribute_groups);
However, the write_cache sysfs attribute remains unconditionally visible as long
as CONFIG_ARCH_HAS_PMEM_API is enabled.
If a user reads this attribute, write_cache_show() will pass the NULL
pmem->dax_dev to dax_write_cache_enabled():
static ssize_t write_cache_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct pmem_device *pmem = dev_to_disk(dev)->private_data;
return sprintf(buf, "%d\n", !!dax_write_cache_enabled(pmem->dax_dev));
}
Similarly, write_cache_store() passes it to dax_write_cache():
static ssize_t write_cache_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
{
...
dax_write_cache(pmem->dax_dev, write_cache);
return len;
}
Since dax_write_cache_enabled() (in drivers/dax/super.c) and dax_write_cache()
blindly dereference the pointer, won't this cause a NULL pointer dereference
leading to a kernel panic if the attribute is accessed?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831043459.1298059-1-hemanth.selam@gmail.com?part=1
next prev parent reply other threads:[~2026-08-31 4:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 4:34 [PATCH v2] nvdimm/pmem: Release gendisk on probe failure Hemanth Selam
2026-08-31 4:45 ` sashiko-bot [this message]
2026-08-31 5:02 ` Hemanth Selam
-- strict thread matches above, loose matches on Subject: below --
2026-09-11 8:25 Hemanth Selam
2026-09-18 17:04 ` Dave Jiang
2026-10-02 1:40 ` Alison Schofield
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=20260831044508.520351F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=hemanth.selam@gmail.com \
--cc=nvdimm@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/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.