From: Kurt Borja <kuurtb@gmail.com>
To: kuurtb@gmail.com
Cc: Dell.Client.Kernel@dell.com, hdegoede@redhat.com,
ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org,
mario.limonciello@amd.com, platform-driver-x86@vger.kernel.org,
w_armin@gmx.de
Subject: [PATCH v2 1/4] alienware-wmi: Migrate to device managed resources
Date: Wed, 20 Nov 2024 13:41:30 -0300 [thread overview]
Message-ID: <20241120164129.6893-2-kuurtb@gmail.com> (raw)
In-Reply-To: <20241120163834.6446-3-kuurtb@gmail.com>
These resources are tied to the platform device lifetime thus make them
make them device managed. Also propagate devm_led_classdev_register() in
case of failure.
This indirectly improves module exit error handling, as potentially not
registered led class or sysfs groups are unregistered.
Signed-off-by: Kurt Borja <kuurtb@gmail.com>
---
v2:
- led_classdev_register() is now device managed
- sysfs_create_group() is now device managed
- Removed alienware_zone_exit() because it's empty now
---
It seems even if the led class is not registered, led_classdev_unregister
fails safely. Same for the sysfs group. If I'm wrong and this is
actually a fix please point it out.
---
drivers/platform/x86/dell/alienware-wmi.c | 51 ++++++++---------------
1 file changed, 17 insertions(+), 34 deletions(-)
diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c
index 77465ed9b449..6760c7627f62 100644
--- a/drivers/platform/x86/dell/alienware-wmi.c
+++ b/drivers/platform/x86/dell/alienware-wmi.c
@@ -411,8 +411,6 @@ struct wmax_u32_args {
};
static struct platform_device *platform_device;
-static struct device_attribute *zone_dev_attrs;
-static struct attribute **zone_attrs;
static struct platform_zone *zone_data;
static struct platform_profile_handler pp_handler;
static enum wmax_thermal_mode supported_thermal_profiles[PLATFORM_PROFILE_LAST];
@@ -624,10 +622,13 @@ static ssize_t store_control_state(struct device *dev,
static DEVICE_ATTR(lighting_control_state, 0644, show_control_state,
store_control_state);
-static int alienware_zone_init(struct platform_device *dev)
+static int alienware_zone_init(struct platform_device *pdev)
{
u8 zone;
char *name;
+ struct device_attribute *zone_dev_attrs;
+ struct attribute **zone_attrs;
+ int ret;
if (interface == WMAX) {
lighting_control_state = WMAX_RUNNING;
@@ -644,28 +645,25 @@ static int alienware_zone_init(struct platform_device *dev)
* the lighting control + null terminated
* - zone_data num_zones is for the distinct zones
*/
- zone_dev_attrs =
- kcalloc(quirks->num_zones + 1, sizeof(struct device_attribute),
- GFP_KERNEL);
+ zone_dev_attrs = devm_kcalloc(&pdev->dev, quirks->num_zones + 1,
+ sizeof(struct device_attribute), GFP_KERNEL);
if (!zone_dev_attrs)
return -ENOMEM;
- zone_attrs =
- kcalloc(quirks->num_zones + 2, sizeof(struct attribute *),
- GFP_KERNEL);
+ zone_attrs = devm_kcalloc(&pdev->dev, quirks->num_zones + 2,
+ sizeof(struct attribute *), GFP_KERNEL);
if (!zone_attrs)
return -ENOMEM;
- zone_data =
- kcalloc(quirks->num_zones, sizeof(struct platform_zone),
- GFP_KERNEL);
+ zone_data = devm_kcalloc(&pdev->dev, quirks->num_zones,
+ sizeof(struct platform_zone), GFP_KERNEL);
if (!zone_data)
return -ENOMEM;
for (zone = 0; zone < quirks->num_zones; zone++) {
- name = kasprintf(GFP_KERNEL, "zone%02hhX", zone);
- if (name == NULL)
- return 1;
+ name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "zone%02hhX", zone);
+ if (!name)
+ return -ENOMEM;
sysfs_attr_init(&zone_dev_attrs[zone].attr);
zone_dev_attrs[zone].attr.name = name;
zone_dev_attrs[zone].attr.mode = 0644;
@@ -678,24 +676,11 @@ static int alienware_zone_init(struct platform_device *dev)
zone_attrs[quirks->num_zones] = &dev_attr_lighting_control_state.attr;
zone_attribute_group.attrs = zone_attrs;
- led_classdev_register(&dev->dev, &global_led);
-
- return sysfs_create_group(&dev->dev.kobj, &zone_attribute_group);
-}
-
-static void alienware_zone_exit(struct platform_device *dev)
-{
- u8 zone;
+ ret = devm_led_classdev_register(&pdev->dev, &global_led);
+ if (ret < 0)
+ return ret;
- sysfs_remove_group(&dev->dev.kobj, &zone_attribute_group);
- led_classdev_unregister(&global_led);
- if (zone_dev_attrs) {
- for (zone = 0; zone < quirks->num_zones; zone++)
- kfree(zone_dev_attrs[zone].attr.name);
- }
- kfree(zone_dev_attrs);
- kfree(zone_data);
- kfree(zone_attrs);
+ return devm_device_add_group(&pdev->dev, &zone_attribute_group);
}
static acpi_status alienware_wmax_command(void *in_args, size_t in_size,
@@ -1236,7 +1221,6 @@ static int __init alienware_wmi_init(void)
return 0;
fail_prep_zones:
- alienware_zone_exit(platform_device);
remove_thermal_profile();
fail_prep_thermal_profile:
fail_prep_deepsleep:
@@ -1256,7 +1240,6 @@ module_init(alienware_wmi_init);
static void __exit alienware_wmi_exit(void)
{
if (platform_device) {
- alienware_zone_exit(platform_device);
remove_hdmi(platform_device);
remove_thermal_profile();
platform_device_unregister(platform_device);
--
2.47.0
next prev parent reply other threads:[~2024-11-20 16:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-20 16:38 [PATCH v2 0/4] alienware-wmi: Improvements Kurt Borja
2024-11-20 16:41 ` Kurt Borja [this message]
2024-11-20 16:43 ` [PATCH v2 2/4] alienware-wmi: Improves sysfs groups creation Kurt Borja
2024-11-21 15:37 ` Kurt Borja
2024-11-20 16:43 ` [PATCH v2 3/4] alienware-wmi: Simplify platform device creation Kurt Borja
2024-11-20 16:44 ` [PATCH v2 4/4] alienware-wmi: Remove unnecessary check at module exit Kurt Borja
2024-11-20 18:08 ` [PATCH v2 0/4] alienware-wmi: Improvements Mario Limonciello
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=20241120164129.6893-2-kuurtb@gmail.com \
--to=kuurtb@gmail.com \
--cc=Dell.Client.Kernel@dell.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=w_armin@gmx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.