From: Ira Weiny <ira.weiny@intel.com>
To: Ira Weiny <ira.weiny@intel.com>, Dinghao Liu <dinghao.liu@zju.edu.cn>
Cc: Dan Williams <dan.j.williams@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Dave Jiang <dave.jiang@intel.com>,
Ira Weiny <ira.weiny@intel.com>, <nvdimm@lists.linux.dev>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] [v2] nvdimm-btt: fix several memleaks
Date: Fri, 15 Dec 2023 08:45:10 -0800 [thread overview]
Message-ID: <657c82966e358_2947c22941a@iweiny-mobl.notmuch> (raw)
In-Reply-To: <657b9cb088175_27db80294d2@iweiny-mobl.notmuch>
Ira Weiny wrote:
> Dinghao Liu wrote:
[snip]
> >
> > -static int btt_maplocks_init(struct arena_info *arena)
> > +static int btt_maplocks_init(struct device *dev, struct arena_info *arena)
> > {
> > u32 i;
> >
> > - arena->map_locks = kcalloc(arena->nfree, sizeof(struct aligned_lock),
> > + arena->map_locks = devm_kcalloc(dev, arena->nfree, sizeof(struct aligned_lock),
> > GFP_KERNEL);
> > if (!arena->map_locks)
> > return -ENOMEM;
> > @@ -805,9 +805,6 @@ static void free_arenas(struct btt *btt)
> >
> > list_for_each_entry_safe(arena, next, &btt->arena_list, list) {
> > list_del(&arena->list);
> > - kfree(arena->rtt);
> > - kfree(arena->map_locks);
> > - kfree(arena->freelist);
>
> This does not quite work.
>
> free_arenas() is used in the error paths of create_arenas() and
> discover_arenas(). In those cases devm_kfree() is probably a better way
> to clean up this.
>
> However...
>
> > debugfs_remove_recursive(arena->debugfs_dir);
> > kfree(arena);
>
> Why can't arena be allocated with devm_*?
>
> We need to change this up a bit more to handle the error path vs regular
> device shutdown free (automatic devm frees).
We might want to look at using no_free_ptr() in this code. See this
patch[1] for an example of how to inhibit the cleanup and pass the pointer
on when the function succeeds.
[1] https://lore.kernel.org/all/170261791914.1714654.6447680285357545638.stgit@dwillia2-xfh.jf.intel.com/
Ira
next prev parent reply other threads:[~2023-12-15 16:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-10 8:58 [PATCH] [v2] nvdimm-btt: fix several memleaks Dinghao Liu
2023-12-15 0:24 ` Ira Weiny
2023-12-15 16:45 ` Ira Weiny [this message]
2023-12-18 9:21 ` dinghao.liu
2023-12-19 23:42 ` Ira Weiny
2023-12-20 7:52 ` dinghao.liu
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=657c82966e358_2947c22941a@iweiny-mobl.notmuch \
--to=ira.weiny@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dinghao.liu@zju.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
--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