Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp450828lqp; Mon, 10 Jun 2024 08:54:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXdNovDQA3fa0c2XoV5qUKgt9NfwhHtbH8o7GCvjOx1gRBpfN8mL2QhGpdhzlC+tO13468HYFqKchoi5U/+TUuQ0gZv3jhDzd0RXu49mA== X-Google-Smtp-Source: AGHT+IGYu+bL63V/MaZEaqG52NAB5aeXd+24FzAF7L5cGlt4ICPmmtKm6t9xmNadBRIhS4N/JArM X-Received: by 2002:a05:6e02:1c25:b0:375:aa46:4a14 with SMTP id e9e14a558f8ab-375aa464d6amr23460415ab.5.1718034859139; Mon, 10 Jun 2024 08:54:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718034859; cv=pass; d=google.com; s=arc-20160816; b=Ml4xkM2IpVzgX8U3aDIya6qoY7BBd6vqQYH9Ei/sH6KlKSXp45NvP+QjWHXPOCvtWf APeY9K5OTUnBKwtuKfPBlqo3oWgiARCoHyr3USeBXFC9sGdggexT4HtHmjt1U1oBkEc4 mwgNzkn79DF9YZ3l+qVtJbzma30e8MbYPcqjcvvZ96xIyBNG9NJKSS+GX3LbM/iVZ77w M4qibPvd03i+SN2hlZ94pV5qs2Hla8Tq8pW+WlZlU/MSVSR4ERyftBFSoz0vB02h0Z15 FpUmpkourTYXIxWtE2kmT5WvMpIt4xCOv3AhCyKvI1iu3HkTzsAebtwXQeZKI757ghm+ Szyg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=0ZKDRVrLLGAal6wfJ0YuLwDuBLjLm5flK4wxOiv/2/I=; fh=mNAGY4UiCC2gtYBxmMCQKDpXYJDs8SkK6GbJ2jw39Lc=; b=AvRGuZ34PSS7FhzBdgojVXyPl2hFvbkvGxPK0q2JA7xM2masjGF0SuHwIgkpCe14S0 U3NnRfGKQGQYkJ1jQXiC4Ss2lks27bZ8qQO0LJHhv9I9tC8TXBZYEeNzat+GN3mJU40C 6aVM6q22LOZdwPUhh9w39Tpyk0y5gS5hq/6sjYcZkEjMdZ68QMIXUHhrNBHLXHBC/XGQ OChT9RUSLguz/KCvGknHqcOBS6BtmphF/9T8DmiMcztIy1pzU2IchdDZvmeq71q/oThp 0vVe8cBuS9Ubj0V+GeviLeM8F9WrcyC24GqEE9TI9RaMyKXtRr0hx42iZqRlK2Tt12Ao FmMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=XOvkVDEJ; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net dmarc=pass fromdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-208512-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208512-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=weissschuh.net Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de289553casi4243536a12.586.2024.06.10.08.54.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 08:54:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208512-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=XOvkVDEJ; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net dmarc=pass fromdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-208512-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208512-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=weissschuh.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EE487288B87 for ; Mon, 10 Jun 2024 15:53:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7EBE9147C79; Mon, 10 Jun 2024 15:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="XOvkVDEJ" 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 A021013F450; Mon, 10 Jun 2024 15:52:09 +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=1718034732; cv=none; b=oWFJ0BP2TEYE9gssGalDlvz3PKCPrB3gwi77aOWdLOVAR2CZZxJkVZm77f3KxeQgap4Z2KeXUP+dc8goAjCP56R3q8+kZE7GfRBlVipMONiAtYxj9QOwp2uNCpJeCCFOQ+RncOsj63Sx82uEkdji+Ar9Inuou43q6DDxKTOqL3o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718034732; c=relaxed/simple; bh=YZm4xIk6nDiHtUnYqBTNSv20zxWLGRO9uBNg5Cg7bQQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RRQ7/EQXpesarCbmDkxQGmUPpSdskjtLim7SSK2kjZRqYHFufX/wHy3ibKDqvPegH5Zc2nViHaz9GAErGGbaTgQAceGGSdyPHY+ImFXNgZjDFCbbs8FDwDhDNd+4yZuyTA2qCNLXq4txXERSLPPNH9Na19j9OpNz2XnkJQm0bjg= 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=XOvkVDEJ; 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1718034726; bh=YZm4xIk6nDiHtUnYqBTNSv20zxWLGRO9uBNg5Cg7bQQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XOvkVDEJHfvHFbY9wdP2Vj+VokZ7VSnZU5+EApDrSMrsNss74IZP4ZdY+GajjLkdB nUWq36d5su33vDqCSc2p0sM27tW0T10G+Fs885e3InBQbndn9sOKqL6+4lQ1zU6tpV BaPSHQvmnJJjIfEJCICq5OzdoaTXxJUzlRDDK+sI= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 10 Jun 2024 17:51:06 +0200 Subject: [PATCH v3 1/5] ACPI: battery: add devm_battery_hook_register() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240610-cros_ec-charge-control-v3-1-135e37252094@weissschuh.net> References: <20240610-cros_ec-charge-control-v3-0-135e37252094@weissschuh.net> In-Reply-To: <20240610-cros_ec-charge-control-v3-0-135e37252094@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 , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1718034726; l=1770; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=YZm4xIk6nDiHtUnYqBTNSv20zxWLGRO9uBNg5Cg7bQQ=; b=2g/GG8lqFBwdVD+9PVUjWJO48YOQ51A4lhZ4oqz9aZkY/sUylc/F86XTHLl0BJhRc3qNpKH2N +bXFL/y/wKDA8d/xiSsmQeubz6EGMIRrC2FD09hwoLaV+HNcLEa1UI4 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. 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 -- 2.45.2