From patchwork Sun Jun 30 20:54:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13717428 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D22E943AD2; Sun, 30 Jun 2024 20:57:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719781027; cv=none; b=uy5BxnZYCe+5pHxQeggH8ouq2Tk66CZ1HuWlVSFk7cbX6O5SjHI4so2kg8gNr1asAZSdLgutkYEd8Y1C3TY0MkT6CE1YDsyyoWC3UTFwXUXNCuXBwVV+szKqBiAfWJD3DsDmo0edUsvn9J3TJCJ/n/QB10T4nLKe2IRewnlrMfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719781027; c=relaxed/simple; bh=uw8nLh7+K+VERVHPyxd+3eO/7NhujZLZvDsfiJLrD+k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O2pwuYSh1UhgIcWdoaGUpr7cCUW+iUP/mdZgmHsdClhs2dXqQQ3T+1hVS5Ib7G8w4hxDMg5DyU9REQIQW65MKUn3BSz/fqjLFIlk7OBcqALaD22wkuIEgeceEBDp6MIrwxfJR2bF2jVc9TL74NfjkokL4FWD4EDIc7Rm0qL/pVc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=ZAydGxhz; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="ZAydGxhz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1719781013; bh=uw8nLh7+K+VERVHPyxd+3eO/7NhujZLZvDsfiJLrD+k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZAydGxhzKy2BRBPebAf7jE+fd7WxQqrzZxNBo/mukB5ZHdKF5KZFR0MufVAIF2b1N GGNOORrbdWk+h7TccUCPrZj8f0FY3aBHEaMHdpMVodMdsth58+r9qfXnXMWU5/KWs3 ibv478/fkqXAKT/IM4ac8JVXf6OmKpEK6xWDOfnE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 30 Jun 2024 22:54:08 +0200 Subject: [PATCH v5 1/5] ACPI: battery: add devm_battery_hook_register() Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240630-cros_ec-charge-control-v5-1-8f649d018c52@weissschuh.net> References: <20240630-cros_ec-charge-control-v5-0-8f649d018c52@weissschuh.net> In-Reply-To: <20240630-cros_ec-charge-control-v5-0-8f649d018c52@weissschuh.net> To: Benson Leung , Guenter Roeck , Sebastian Reichel , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , "Rafael J. Wysocki" , Len Brown , Robert Moore , Tzung-Bi Shih Cc: chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Mario Limonciello , Dustin Howett , Stephen Horvath , Rajas Paranjpe , linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, Matt Hartley , Kieran Levin , "Rafael J. Wysocki" , =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1719781012; l=1828; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=uw8nLh7+K+VERVHPyxd+3eO/7NhujZLZvDsfiJLrD+k=; b=RVHWtd+9L3ZrbCRqbpof/wsE5mrtK9K0/YEZaN/a9i6SR8hj7KrpRk8ZtiXYKXO9+44YXlQiI QQn4bscPzLNDyntpXJ4CsPxXedowJSEKebuEvvKhMTz6EuIMxZ1eENi X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Add a utility function for device-managed registration of battery hooks. The function makes it easier to manage the lifecycle of a hook. Acked-by: Rafael J. Wysocki Signed-off-by: Thomas Weißschuh --- drivers/acpi/battery.c | 15 +++++++++++++++ include/acpi/battery.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index b379401ff1c2..6ea979f76f84 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -756,6 +756,21 @@ void battery_hook_register(struct acpi_battery_hook *hook) } EXPORT_SYMBOL_GPL(battery_hook_register); +static void devm_battery_hook_unregister(void *data) +{ + struct acpi_battery_hook *hook = data; + + battery_hook_unregister(hook); +} + +int devm_battery_hook_register(struct device *dev, struct acpi_battery_hook *hook) +{ + battery_hook_register(hook); + + return devm_add_action_or_reset(dev, devm_battery_hook_unregister, hook); +} +EXPORT_SYMBOL_GPL(devm_battery_hook_register); + /* * This function gets called right after the battery sysfs * attributes have been added, so that the drivers that diff --git a/include/acpi/battery.h b/include/acpi/battery.h index 611a2561a014..c93f16dfb944 100644 --- a/include/acpi/battery.h +++ b/include/acpi/battery.h @@ -2,6 +2,7 @@ #ifndef __ACPI_BATTERY_H #define __ACPI_BATTERY_H +#include #include #define ACPI_BATTERY_CLASS "battery" @@ -19,5 +20,6 @@ struct acpi_battery_hook { void battery_hook_register(struct acpi_battery_hook *hook); void battery_hook_unregister(struct acpi_battery_hook *hook); +int devm_battery_hook_register(struct device *dev, struct acpi_battery_hook *hook); #endif