ACPI: bus: Introduce acpi_dev_get() and reuse it in ACPI code
Subsystems (2)
PATCH 1/1 ACPI: bus: Introduce acpi_dev_get() and reuse it in ACPI code
Introduce acpi_dev_get() to have a symmetrical API with acpi_dev_put() and reuse both in ACPI code under drivers/acpi folder.
While at it, use acpi_bus_put_acpi_device() in one place rather than above.
--- drivers/acpi/device_sysfs.c | 4 ++-- drivers/acpi/glue.c | 8 ++++---- drivers/acpi/scan.c | 9 ++++----- include/acpi/acpi_bus.h | 6 ++++++ 4 files changed, 16 insertions(+), 11 deletions(-)
drivers/acpi/device_sysfs.c +2 -2
@@ -376,12 +376,12 @@ eject_store(struct device *d, struct device_attribute *attr,if (ACPI_FAILURE (status) || !acpi_device->flags.ejectable)return -ENODEV ; -get_device (&acpi_device->dev); +acpi_dev_get (acpi_device); status =acpi_hotplug_schedule (acpi_device,ACPI_OST_EC_OSPM_EJECT );if (ACPI_SUCCESS (status))return count; -put_device (&acpi_device->dev); +acpi_dev_put (acpi_device);acpi_evaluate_ost (acpi_device->handle,ACPI_OST_EC_OSPM_EJECT ,ACPI_OST_SC_NON_SPECIFIC_FAILURE ,NULL );return status ==AE_NO_MEMORY ? -ENOMEM : -EAGAIN ;
drivers/acpi/glue.c +4 -4
@@ -190,7 +190,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)if (!acpi_dev)return -EINVAL ; -get_device (&acpi_dev->dev); +acpi_dev_get (acpi_dev);get_device (dev); physical_node =kzalloc (sizeof (*physical_node),GFP_KERNEL );if (!physical_node) {
@@ -217,7 +217,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev) goto err;put_device (dev); -put_device (&acpi_dev->dev); +acpi_dev_put (acpi_dev);return 0 ; }if (pn->node_id == node_id) {
@@ -257,7 +257,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev) err:ACPI_COMPANION_SET (dev,NULL );put_device (dev); -put_device (&acpi_dev->dev); +acpi_dev_put (acpi_dev);return retval; }EXPORT_SYMBOL_GPL (acpi_bind_one);
@@ -285,7 +285,7 @@ int acpi_unbind_one(struct device *dev)ACPI_COMPANION_SET (dev,NULL );/* Drop references taken by acpi_bind_one(). */ put_device (dev); -put_device (&acpi_dev->dev); +acpi_dev_put (acpi_dev);kfree (entry);break ; }
drivers/acpi/scan.c +4 -5
@@ -530,7 +530,7 @@ static void acpi_device_del_work_fn(struct work_struct *work_not_used)* used by the device. */ acpi_power_transition (adev,ACPI_STATE_D3_COLD ); -put_device (&adev->dev); +acpi_dev_put (adev); } }
@@ -604,8 +604,7 @@ EXPORT_SYMBOL(acpi_bus_get_device);static void get_acpi_device (void *dev) { -if (dev) -get_device (&((struct acpi_device *)dev)->dev); +acpi_dev_get (dev); }struct acpi_device *acpi_bus_get_acpi_device (acpi_handle handle)
@@ -615,7 +614,7 @@ struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)void acpi_bus_put_acpi_device (struct acpi_device *adev) { -put_device (&adev->dev); +acpi_dev_put (adev); }static struct acpi_device_bus_id *acpi_device_bus_id_match (const char *dev_id)
@@ -2386,7 +2385,7 @@ int __init acpi_scan_init(void)acpi_detach_data (acpi_root->handle, acpi_scan_drop_device);acpi_device_del (acpi_root); -put_device (&acpi_root->dev); +acpi_bus_put_acpi_device (acpi_root); goto out; } }
include/acpi/acpi_bus.h +6 -0
@@ -707,6 +707,12 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);adev ; \ adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv)) +static inline void acpi_dev_get (struct acpi_device *adev) +{ +if (adev) +get_device (&adev->dev); +} +static inline void acpi_dev_put (struct acpi_device *adev) {put_device (&adev->dev);
Signature · 1 line
2.31.1
Rafael J. Wysocki
maintainerQuoted 87 lines · Andy Shevchenko
Introduce
acpi_dev_get()to have a symmetrical API withacpi_dev_put()and reuse both in ACPI code underdrivers/acpifolder.While at it, use
acpi_bus_put_acpi_device()in one place rather than above.Signed-off-by Andy Shevchenko <andy.shevchenko(a)gmail.com>--- drivers/acpi/device_sysfs.c | 4 ++-- drivers/acpi/glue.c | 8 ++++---- drivers/acpi/scan.c | 9 ++++----- include/acpi/acpi_bus.h | 6 ++++++ 4 files changed, 16 insertions(+), 11 deletions(-)drivers/acpi/device_sysfs.c +2
-2@@ -376,12 +376,12 @@ eject_store(struct device *d, struct device_attribute *attr,if (ACPI_FAILURE (status) || !acpi_device->flags.ejectable)return -ENODEV ; -get_device (&acpi_device->dev); +acpi_dev_get (acpi_device); status =acpi_hotplug_schedule (acpi_device,ACPI_OST_EC_OSPM_EJECT );if (ACPI_SUCCESS (status))return count; -put_device (&acpi_device->dev); +acpi_dev_put (acpi_device);acpi_evaluate_ost (acpi_device->handle,ACPI_OST_EC_OSPM_EJECT ,ACPI_OST_SC_NON_SPECIFIC_FAILURE ,NULL );return status ==AE_NO_MEMORY ? -ENOMEM : -EAGAIN ;drivers/acpi/glue.c +4
-4@@ -190,7 +190,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)if (!acpi_dev)return -EINVAL ; -get_device (&acpi_dev->dev); +acpi_dev_get (acpi_dev);get_device (dev); physical_node =kzalloc (sizeof (*physical_node),GFP_KERNEL );if (!physical_node) {@@ -217,7 +217,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev) goto err;put_device (dev); -put_device (&acpi_dev->dev); +acpi_dev_put (acpi_dev);return 0 ; }if (pn->node_id == node_id) {@@ -257,7 +257,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev) err:ACPI_COMPANION_SET (dev,NULL );put_device (dev); -put_device (&acpi_dev->dev); +acpi_dev_put (acpi_dev);return retval; }EXPORT_SYMBOL_GPL (acpi_bind_one);@@ -285,7 +285,7 @@ int acpi_unbind_one(struct device *dev)ACPI_COMPANION_SET (dev,NULL );/* Drop references taken by acpi_bind_one(). */ put_device (dev); -put_device (&acpi_dev->dev); +acpi_dev_put (acpi_dev);kfree (entry);break ; }drivers/acpi/scan.c +1
-1@@ -530,7 +530,7 @@ static void acpi_device_del_work_fn(struct work_struct *work_not_used)* used by the device. */ acpi_power_transition (adev,ACPI_STATE_D3_COLD ); -put_device (&adev->dev); +acpi_dev_put (adev); } }
drivers/acpi/scan.c EXPORT_SYMBOL(acpi_bus_get_device); · line 607
Quoted 6 lines
drivers/acpi/scan.c +1
-2@@ -604,8 +604,7 @@ EXPORT_SYMBOL(acpi_bus_get_device);static void get_acpi_device (void *dev) { -if (dev) -get_device (&((struct acpi_device *)dev)->dev); +acpi_dev_get (dev);
I would do
if (dev)
acpi_dev_get(dev);
here.
Quoted 26 lines
drivers/acpi/scan.c +2
-2}struct acpi_device *acpi_bus_get_acpi_device (acpi_handle handle)@@ -615,7 +614,7 @@ struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)void acpi_bus_put_acpi_device (struct acpi_device *adev) { -put_device (&adev->dev); +acpi_dev_put (adev); }static struct acpi_device_bus_id *acpi_device_bus_id_match (const char *dev_id)@@ -2386,7 +2385,7 @@ int __init acpi_scan_init(void)acpi_detach_data (acpi_root->handle, acpi_scan_drop_device);acpi_device_del (acpi_root); -put_device (&acpi_root->dev); +acpi_bus_put_acpi_device (acpi_root); goto out; } }include/acpi/acpi_bus.h +0
-0
include/acpi/acpi_bus.h acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv); · line 713
Quoted 7 lines
include/acpi/acpi_bus.h +4
-0@@ -707,6 +707,12 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);adev ; \ adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv)) +static inline void acpi_dev_get (struct acpi_device *adev) +{ +if (adev) +get_device (&adev->dev);
And I would drop the adev check from here (because the code calling it may be running with wrong assumptions if adev is NULL). Or it should return adev and the caller should be held responsible for checking it against NULL (if they care).
Quoted 6 lines
include/acpi/acpi_bus.h +2
-1+} +static inline void acpi_dev_put (struct acpi_device *adev) {put_device (&adev->dev); --
Quoted 2 lines · Rafael J. Wysocki
On Sat, Apr 10, 2021 at 3:47 PM Andy Shevchenko
<andy.shevchenko(a)gmail.com> wrote:
...
Quoted 6 lines
drivers/acpi/scan.c EXPORT_SYMBOL(acpi_bus_get_device); · line 607
Quoted 5 lines
static void
get_acpi_device(void *dev)
{drivers/acpi/scan.c +1
-2-if (dev) -get_device (&((struct acpi_device *)dev)->dev); +acpi_dev_get (dev);
Quoted 6 lines
I would do
if (dev)
acpi_dev_get(dev);here.
Hmm... I don't see a point. acpi_dev_get() guaranteed to perform this check.
Quoted 12 lines
include/acpi/acpi_bus.h acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv); · line 713
Quoted 7 lines
}
include/acpi/acpi_bus.h +4
-0+static inline void acpi_dev_get (struct acpi_device *adev) +{ +if (adev) +get_device (&adev->dev);And I would drop the adev check from here (because the code calling it may be running with wrong assumptions if adev is NULL). Or it should return adev and the caller should be held responsible for checking it against NULL (if they care).
But this follows the get_device() / put_device() logic. Personally I don't think this is a good idea to deviate. Note the acpi_bus_get_acpi_device() / acpi_bus_put_acpi_device() as well.
Quoted 1 line
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Rafael J. Wysocki
maintainerQuoted 35 lines · Andy Shevchenko
Quoted 2 lines · Rafael J. Wysocki
On Sat, Apr 10, 2021 at 3:47 PM Andy Shevchenko
<andy.shevchenko(a)gmail.com> wrote:...
Quoted 6 lines
drivers/acpi/scan.c EXPORT_SYMBOL(acpi_bus_get_device); · line 607
Quoted 5 lines
static void
get_acpi_device(void *dev)
{drivers/acpi/scan.c +1
-2-if (dev) -get_device (&((struct acpi_device *)dev)->dev); +acpi_dev_get (dev);Quoted 6 lines
I would do
if (dev)
acpi_dev_get(dev);here.
Hmm... I don't see a point.
acpi_dev_get()guaranteed to perform this check.Quoted 12 lines
include/acpi/acpi_bus.h acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv); · line 713
Quoted 7 lines
}
include/acpi/acpi_bus.h +4
-0+static inline void acpi_dev_get (struct acpi_device *adev) +{ +if (adev) +get_device (&adev->dev);And I would drop the adev check from here (because the code calling it may be running with wrong assumptions if adev is NULL). Or it should return adev and the caller should be held responsible for checking it against NULL (if they care).
Quoted 1 line
But this follows the
get_device()/put_device()logic.
Not really. get_device() returns a pointer.
Quoted 1 line
Personally I don't think this is a good idea to deviate.
Well, exactly. :-)
Quoted 1 line
Note the
acpi_bus_get_acpi_device()
This also returns a pointer.
Quoted 1 line
/
acpi_bus_put_acpi_device()as well.
Quoted 42 lines · Rafael J. Wysocki
Quoted 35 lines · Andy Shevchenko
Quoted 2 lines · Rafael J. Wysocki
On Sat, Apr 10, 2021 at 3:47 PM Andy Shevchenko
<andy.shevchenko(a)gmail.com> wrote:...
Quoted 6 lines
drivers/acpi/scan.c EXPORT_SYMBOL(acpi_bus_get_device); · line 607
Quoted 5 lines
static void
get_acpi_device(void *dev)
{drivers/acpi/scan.c +1
-2-if (dev) -get_device (&((struct acpi_device *)dev)->dev); +acpi_dev_get (dev);Quoted 6 lines
I would do
if (dev)
acpi_dev_get(dev);here.
Hmm... I don't see a point.
acpi_dev_get()guaranteed to perform this check.Quoted 12 lines
include/acpi/acpi_bus.h acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv); · line 713
Quoted 7 lines
}
include/acpi/acpi_bus.h +4
-0+static inline void acpi_dev_get (struct acpi_device *adev) +{ +if (adev) +get_device (&adev->dev);And I would drop the adev check from here (because the code calling it may be running with wrong assumptions if adev is NULL). Or it should return adev and the caller should be held responsible for checking it against NULL (if they care).
Quoted 1 line
But this follows the
get_device()/put_device()logic.Not really.
get_device()returns a pointer.
Quoted 7 lines
Quoted 1 line
Personally I don't think this is a good idea to deviate.
Well, exactly. :-)
Quoted 1 line
Note the
acpi_bus_get_acpi_device()This also returns a pointer.
Is it okay to return a pointer in acpi_dev_get() then?
I will do it that way if there are no objections.
Quoted 1 line
Quoted 1 line
/
acpi_bus_put_acpi_device()as well.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Rafael J. Wysocki
maintainerQuoted 46 lines · Andy Shevchenko
Quoted 44 lines · Rafael J. Wysocki
Quoted 35 lines · Andy Shevchenko
Quoted 2 lines · Rafael J. Wysocki
On Sat, Apr 10, 2021 at 3:47 PM Andy Shevchenko
<andy.shevchenko(a)gmail.com> wrote:...
Quoted 6 lines
drivers/acpi/scan.c EXPORT_SYMBOL(acpi_bus_get_device); · line 607
Quoted 5 lines
static void
get_acpi_device(void *dev)
{drivers/acpi/scan.c +1
-2-if (dev) -get_device (&((struct acpi_device *)dev)->dev); +acpi_dev_get (dev);Quoted 6 lines
I would do
if (dev)
acpi_dev_get(dev);here.
Hmm... I don't see a point.
acpi_dev_get()guaranteed to perform this check.Quoted 12 lines
include/acpi/acpi_bus.h acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv); · line 713
Quoted 7 lines
}
include/acpi/acpi_bus.h +4
-0+static inline void acpi_dev_get (struct acpi_device *adev) +{ +if (adev) +get_device (&adev->dev);And I would drop the adev check from here (because the code calling it may be running with wrong assumptions if adev is NULL). Or it should return adev and the caller should be held responsible for checking it against NULL (if they care).
Quoted 1 line
But this follows the
get_device()/put_device()logic.Not really.
get_device()returns a pointer.Quoted 1 line
Personally I don't think this is a good idea to deviate.
Quoted 7 lines
Quoted 5 lines
Well, exactly. :-)
Quoted 1 line
Note the
acpi_bus_get_acpi_device()This also returns a pointer.
Is it okay to return a pointer in
acpi_dev_get()then?
Yes, it is, as I've said already.