From: Michal Hocko <mhocko@suse.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Scott Cheloha <cheloha@linux.vnet.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Nathan Lynch <nathanl@linux.ibm.com>,
David Hildenbrand <david@redhat.com>,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] drivers/base/memory: Fix a reference counting issue in __add_memory_block()
Date: Fri, 22 Apr 2022 09:34:57 +0200 [thread overview]
Message-ID: <YmJaoSam6g95yToH@dhcp22.suse.cz> (raw)
In-Reply-To: <d44c63d78aafe844f920dc02ad6af25acc448fcf.1650611702.git.christophe.jaillet@wanadoo.fr>
On Fri 22-04-22 09:15:21, Christophe JAILLET wrote:
> There is no point in doing put_device()/device_unregister() on a
> device that has just been registered a few lines above. This will lead to
> a double reference decrement.
This is a bit confusing. I would rephrase.
"
__add_memory_block calls both put_device and device_unregister when
storing the memory block into the xarray. This is incorrect because
xarray doesn't take an additional reference and device_unregister
already calls put_device.
"
Btw. I do not think this failure path can be triggered, or is there a
way to hit it?
> I guess that this put_device()/device_unregister() is a cut'n'paste from
> remove_memory_block() (i.e. unregister_memory() at the time being) which
> does need it.
>
> Fixes: 4fb6eabf1037 ("drivers/base/memory.c: cache memory blocks in xarray to accelerate lookup")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Other than that looks good to me. With the changelog clarified,
especially the part that evaluates whether this is a real or a
theoretical problem, feel free to add
Acked-by: Michal Hocko <mhocko@suse.com>
Thanks!
> ---
> drivers/base/memory.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> index 7222ff9b5e05..084d67fd55cc 100644
> --- a/drivers/base/memory.c
> +++ b/drivers/base/memory.c
> @@ -636,10 +636,9 @@ static int __add_memory_block(struct memory_block *memory)
> }
> ret = xa_err(xa_store(&memory_blocks, memory->dev.id, memory,
> GFP_KERNEL));
> - if (ret) {
> - put_device(&memory->dev);
> + if (ret)
> device_unregister(&memory->dev);
> - }
> +
> return ret;
> }
>
> --
> 2.32.0
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2022-04-22 7:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-22 7:15 [PATCH] drivers/base/memory: Fix a reference counting issue in __add_memory_block() Christophe JAILLET
2022-04-22 7:34 ` Michal Hocko [this message]
2022-04-22 8:01 ` Christophe JAILLET
2022-04-22 7:39 ` David Hildenbrand
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=YmJaoSam6g95yToH@dhcp22.suse.cz \
--to=mhocko@suse.com \
--cc=akpm@linux-foundation.org \
--cc=cheloha@linux.vnet.ibm.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=david@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathanl@linux.ibm.com \
--cc=rafael@kernel.org \
/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