mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Scally <djrscally@gmail.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	"open list:ACPI COMPONENT ARCHITECTURE (ACPICA)"
	<devel@acpica.org>, "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <lenb@kernel.org>, Yong Zhi <yong.zhi@intel.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Bingbu Cao <bingbu.cao@intel.com>,
	Tianshu Qiu <tian.shu.qiu@intel.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Robert Moore <robert.moore@intel.com>,
	Erik Kaneda <erik.kaneda@intel.com>
Subject: Re: [PATCH v1 1/1] ACPI: utils: Fix reference counting in for_each_acpi_dev_match()
Date: Tue, 25 May 2021 23:29:25 +0100	[thread overview]
Message-ID: <50903d09-96f8-0dc9-a1f7-21bf1543b15a@gmail.com> (raw)
In-Reply-To: <CAJZ5v0hsDpGtLHPQvcnof3c1LBnhoZSwWyHJdj1mOov9gV_W8A@mail.gmail.com>

Hi Rafael, Andy

On 20/05/2021 20:40, Rafael J. Wysocki wrote:
> On Thu, May 20, 2021 at 9:13 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>> On Wed, May 19, 2021 at 11:19 PM Andy Shevchenko
>> <andy.shevchenko@gmail.com> wrote:
>>> Currently it's possible to iterate over the dangling pointer in case the device
>>> suddenly disappears. This may happen becase callers put it at the end of a loop.
>>>
>>> Instead, let's move that call inside acpi_dev_get_next_match_dev().
>> Not really.
> OK, I see what you want to achieve and the macro is actually buggy,
> because it leaves unbalanced references behind.


Yeah; I guess the originally intended use (which was "get all these
devices") doesn't really tally with the naming or with the operation of
similar functions in the kernel like the fwnode_handle ops; sorry about
that. Anyway; I think Andy's fix is the right way to do it, so the
calling code's responsible for holding onto a reference if it wants to
keep it.

>
>>> Fixes: 803abec64ef9 ("media: ipu3-cio2: Add cio2-bridge to ipu3-cio2 driver")
>>> Fixes: bf263f64e804 ("media: ACPI / bus: Add acpi_dev_get_next_match_dev() and helper macro")
>>> Cc: Daniel Scally <djrscally@gmail.com>
>>> Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
>>> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
>>> ---
>>>  drivers/acpi/utils.c                       | 5 +----
>>>  drivers/media/pci/intel/ipu3/cio2-bridge.c | 8 +++-----
>>>  include/acpi/acpi_bus.h                    | 5 -----
>>>  3 files changed, 4 insertions(+), 14 deletions(-)
>>>
>>> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
>>> index 3b54b8fd7396..ccfc484dbffd 100644
>>> --- a/drivers/acpi/utils.c
>>> +++ b/drivers/acpi/utils.c
>>> @@ -846,10 +846,6 @@ EXPORT_SYMBOL(acpi_dev_present);
>>>   * Return the next match of ACPI device if another matching device was present
>>>   * at the moment of invocation, or NULL otherwise.
>>>   *
>>> - * FIXME: The function does not tolerate the sudden disappearance of @adev, e.g.
>>> - * in the case of a hotplug event. That said, the caller should ensure that
>>> - * this will never happen.
>>> - *
>>>   * The caller is responsible for invoking acpi_dev_put() on the returned device.
>>>   *
>>>   * See additional information in acpi_dev_present() as well.
> But the kerneldoc really needs to say that the caller is required to
> obtain a reference on adev before passing it here, because that
> reference will be dropped and the object pointed to by adev may not be
> present any more after this returns.
>
>>> @@ -866,6 +862,7 @@ acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const cha
>>>         match.hrv = hrv;
>>>
>>>         dev = bus_find_device(&acpi_bus_type, start, &match, acpi_dev_match_cb);
>>> +       acpi_dev_put(adev);

  reply	other threads:[~2021-05-25 22:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-19 21:02 Andy Shevchenko
2021-05-20 19:13 ` Rafael J. Wysocki
2021-05-20 19:40   ` Rafael J. Wysocki
2021-05-25 22:29     ` Daniel Scally [this message]
2021-05-26  8:35       ` Andy Shevchenko

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=50903d09-96f8-0dc9-a1f7-21bf1543b15a@gmail.com \
    --to=djrscally@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bingbu.cao@intel.com \
    --cc=devel@acpica.org \
    --cc=erik.kaneda@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=robert.moore@intel.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tian.shu.qiu@intel.com \
    --cc=yong.zhi@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®