diff options
| author | Marco Scardovi <scardracs@disroot.org> | 2026-07-07 23:36:12 +0200 |
|---|---|---|
| committer | Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> | 2026-07-09 16:44:02 +0300 |
| commit | 7952692dce653d33e94d5482492278f822da7d19 (patch) | |
| tree | 4ff893ea440ebf93baf06402a9f264bf24ee21db | |
| parent | 76708233b4acd6255fc54d5e1b15e779e91132e7 (diff) | |
platform/x86: asus-armoury: use cleanup.h to manage tunables
Convert init_rog_tunables() to use the cleanup infrastructure to
automatically free ac_rog_tunables if dc_rog_tunables allocation fails.
By declaring local pointers with the __free(kfree) attribute, the
manual kfree() in the error path can be removed. Upon successful
initialization, the ownership is transferred to the global struct
using no_free_ptr().
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Marco Scardovi <scardracs@disroot.org>
Link: https://patch.msgid.link/20260707213741.6515-3-scardracs@disroot.org
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
| -rw-r--r-- | drivers/platform/x86/asus-armoury.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/platform/x86/asus-armoury.c b/drivers/platform/x86/asus-armoury.c index fa7d0485c712..93d9665717af 100644 --- a/drivers/platform/x86/asus-armoury.c +++ b/drivers/platform/x86/asus-armoury.c @@ -16,6 +16,7 @@ #include <linux/acpi.h> #include <linux/array_size.h> #include <linux/bitfield.h> +#include <linux/cleanup.h> #include <linux/device.h> #include <linux/dmi.h> #include <linux/err.h> @@ -1010,7 +1011,8 @@ fail_class_get: static int init_rog_tunables(void) { const struct power_limits *ac_limits, *dc_limits; - struct rog_tunables *ac_rog_tunables = NULL, *dc_rog_tunables = NULL; + struct rog_tunables *ac_rog_tunables __free(kfree) = NULL; + struct rog_tunables *dc_rog_tunables __free(kfree) = NULL; const struct power_data *power_data; const struct dmi_system_id *dmi_id; @@ -1080,10 +1082,8 @@ static int init_rog_tunables(void) dc_limits = power_data->dc_data; if (dc_limits) { dc_rog_tunables = kzalloc_obj(*dc_rog_tunables); - if (!dc_rog_tunables) { - kfree(ac_rog_tunables); + if (!dc_rog_tunables) return -ENOMEM; - } dc_rog_tunables->power_limits = dc_limits; @@ -1124,8 +1124,8 @@ static int init_rog_tunables(void) pr_debug("No DC PPT limits defined\n"); } - asus_armoury.rog_tunables[ASUS_ROG_TUNABLE_AC] = ac_rog_tunables; - asus_armoury.rog_tunables[ASUS_ROG_TUNABLE_DC] = dc_rog_tunables; + asus_armoury.rog_tunables[ASUS_ROG_TUNABLE_AC] = no_free_ptr(ac_rog_tunables); + asus_armoury.rog_tunables[ASUS_ROG_TUNABLE_DC] = no_free_ptr(dc_rog_tunables); return 0; } |
