alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	linux-acpi@vger.kernel.org,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Liam Girdwood <liam.r.girdwood@linux.intel.com>,
	Jie Yang <yang.jie@linux.intel.com>,
	Mark Brown <broonie@kernel.org>,
	alsa-devel@alsa-project.org, Hans de Goede <hdegoede@redhat.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v3 01/10] ACPI / utils: Introduce acpi_dev_get_first_match_dev() helper
Date: Thu, 28 Mar 2019 19:17:20 +0200	[thread overview]
Message-ID: <20190328171729.44002-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20190328171729.44002-1-andriy.shevchenko@linux.intel.com>

The acpi_dev_get_first_match_name() is missing put_device() call
and thus keeping reference counting unbalanced.

In order to fix the issue introduce a new helper to convert existing users
one-by-one to a better API. And then remove the old one.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/acpi/utils.c    | 24 ++++++++++++++++++++++--
 include/acpi/acpi_bus.h |  3 +++
 include/linux/acpi.h    |  6 ++++++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index c4b06cc075f9..5a2bae2b6c3a 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -739,6 +739,7 @@ EXPORT_SYMBOL(acpi_dev_found);
 
 struct acpi_dev_match_info {
 	const char *dev_name;
+	struct acpi_device *adev;
 	struct acpi_device_id hid[2];
 	const char *uid;
 	s64 hrv;
@@ -759,6 +760,7 @@ static int acpi_dev_match_cb(struct device *dev, void *data)
 		return 0;
 
 	match->dev_name = acpi_dev_name(adev);
+	match->adev = adev;
 
 	if (match->hrv == -1)
 		return 1;
@@ -806,16 +808,34 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
 EXPORT_SYMBOL(acpi_dev_present);
 
 /**
- * acpi_dev_get_first_match_name - Return name of first match of ACPI device
+ * acpi_dev_get_first_match_dev - Return the first match of ACPI device
  * @hid: Hardware ID of the device.
  * @uid: Unique ID of the device, pass NULL to not check _UID
  * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
  *
- * Return device name if a matching device was present
+ * Return the first match of ACPI device if a matching device was present
  * at the moment of invocation, or NULL otherwise.
  *
+ * The caller is responsible to call put_device() on the returned device.
+ *
  * See additional information in acpi_dev_present() as well.
  */
+struct acpi_device *
+acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
+{
+	struct acpi_dev_match_info match = {};
+	struct device *dev;
+
+	strlcpy(match.hid[0].id, hid, sizeof(match.hid[0].id));
+	match.uid = uid;
+	match.hrv = hrv;
+
+	dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);
+	return dev ? match.adev : NULL;
+}
+EXPORT_SYMBOL(acpi_dev_get_first_match_dev);
+
+/* DEPRECATED, use acpi_dev_get_first_match_dev() instead */
 const char *
 acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv)
 {
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 0300374101cd..2063e9e2f384 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -91,6 +91,9 @@ acpi_evaluate_dsm_typed(acpi_handle handle, const guid_t *guid, u64 rev,
 bool acpi_dev_found(const char *hid);
 bool acpi_dev_present(const char *hid, const char *uid, s64 hrv);
 
+struct acpi_device *
+acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
+
 const char *
 acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv);
 
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index d5dcebd7aad3..3e1d16b00513 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -669,6 +669,12 @@ static inline bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
 	return false;
 }
 
+static inline struct acpi_device *
+acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
+{
+	return NULL;
+}
+
 static inline const char *
 acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv)
 {
-- 
2.20.1

  reply	other threads:[~2019-03-28 17:17 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-28 17:17 [PATCH v3 00/10] ACPI / utils: Replace leaky function Andy Shevchenko
2019-03-28 17:17 ` Andy Shevchenko [this message]
2019-03-28 20:12   ` [PATCH v3 01/10] ACPI / utils: Introduce acpi_dev_get_first_match_dev() helper Rafael J. Wysocki
2019-03-28 21:38     ` Andy Shevchenko
2019-04-01  7:23   ` Mark Brown
2019-03-28 17:17 ` [PATCH v3 02/10] extcon: axp288: Convert to use acpi_dev_get_first_match_dev() Andy Shevchenko
2019-03-29  0:53   ` Chanwoo Choi
2019-03-29 22:58     ` Rafael J. Wysocki
2019-04-01  1:25       ` Chanwoo Choi
2019-03-28 17:17 ` [PATCH v3 03/10] gpio: merrifield: " Andy Shevchenko
2019-03-28 17:17 ` [PATCH v3 04/10] ASoC: Intel: bytcht_da7213: " Andy Shevchenko
2019-03-28 17:17 ` [PATCH v3 05/10] ASoC: Intel: bytcht_es8316: " Andy Shevchenko
2019-03-28 17:17 ` [PATCH v3 06/10] ASoC: Intel: bytcr_rt5640: " Andy Shevchenko
2019-03-28 17:17 ` [PATCH v3 07/10] ASoC: Intel: bytcr_rt5651: " Andy Shevchenko
2019-03-28 17:17 ` [PATCH v3 08/10] ASoC: Intel: cht_bsw_rt5645: " Andy Shevchenko
2019-03-28 17:17 ` [PATCH v3 09/10] ASoC: Intel: cht_bsw_rt5672: " Andy Shevchenko
2019-03-28 17:17 ` [PATCH v3 10/10] ACPI / utils: Remove deprecated function since no user left Andy Shevchenko
2019-03-28 18:31 ` [PATCH v3 00/10] ACPI / utils: Replace leaky function Pierre-Louis Bossart
2019-03-28 21:40   ` Andy Shevchenko
2019-03-28 23:33     ` Rafael J. Wysocki
2019-04-01  7:24       ` Mark Brown
2019-04-02  9:02         ` Rafael J. Wysocki
2019-03-28 22:29 ` Hans de Goede
2019-03-29  9:29 ` Mika Westerberg
2019-04-02  8:57 ` Rafael J. Wysocki
2019-04-02  9:17   ` Rafael J. Wysocki
2019-04-02 10:37     ` 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=20190328171729.44002-2-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=rjw@rjwysocki.net \
    --cc=yang.jie@linux.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;
as well as URLs for NNTP newsgroup(s).