From patchwork Wed Sep 4 07:12:52 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: 825678 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 7F165146A7A; Wed, 4 Sep 2024 07:13:07 +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=1725433991; cv=none; b=d1/aU59CjmlkzlluzeTQ88kU+wKLj70o/d03b2TAbh1TO59pPjkrDWu3DPdrjQx1j5Adm5wpWhxeMoxbO7IFWb/mvubf7h1KIa7MGjOxE4pjHA927Mu3tdQomXE0N7j+kDIwOwnsa/UJb4VbiTmGCOP7XEhK1FbsJB1rvdX+ML0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725433991; c=relaxed/simple; bh=Lo47J8vVQ9sY5GjhyJ305oT5BSxprDB45/xE/NvMdkc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X/8uQPGd53K8jNNzIolI9LWdLQzI9dOIGFDG5n5ccNGm/XP2f+jPM18qrgufWW/gFP56NNUm0uzOY4vci71vbeCrxdM6S8DVL3jpcFSIt14bNboBOlEStSQRjUYPM7HMYkVH5hjoKWbo7ysD97O1wGOn7LUabxN6+Pd6axeLPRQ= 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=S6I3oXxT; 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="S6I3oXxT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1725433984; bh=Lo47J8vVQ9sY5GjhyJ305oT5BSxprDB45/xE/NvMdkc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=S6I3oXxTI18FFedKFIAKA3+Hk2i9CXtkIJvo1ui7c9DJ0KQam+rJ05thAA1befqEK l+XmqR4pDV/m9725/FdEkf5wnbMmdOQz+1I2DoZz5MJNGxYhvn4PSuvHpMnuVtNzuA 2MqBdHYdX0BIafDykWJPEIAbowjmorRlQls5hGp8= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 04 Sep 2024 09:12:52 +0200 Subject: [PATCH 1/5] ACPI: battery: check result of register_pm_notifier() Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240904-acpi-battery-cleanups-v1-1-a3bf74f22d40@weissschuh.net> References: <20240904-acpi-battery-cleanups-v1-0-a3bf74f22d40@weissschuh.net> In-Reply-To: <20240904-acpi-battery-cleanups-v1-0-a3bf74f22d40@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thom?= =?utf-8?q?as_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1725433984; l=734; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Lo47J8vVQ9sY5GjhyJ305oT5BSxprDB45/xE/NvMdkc=; b=EpNdWKvlWwX5uqCpIxeels1V8/9XfN7uAEPnC+J+cdbkuKz6oyvlBmtRYtTqb9UjnTgZlj3pZ bygupYUKVvVDC/3DnbOnwkBxlLaHRgkPevTdOfs/AnkmF4xBlKYLmLp X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= This function call can fail, check for that. Signed-off-by: Thomas Weißschuh --- drivers/acpi/battery.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index da3a879d638a..677618eb38bf 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -1235,7 +1235,9 @@ static int acpi_battery_add(struct acpi_device *device) device->status.battery_present ? "present" : "absent"); battery->pm_nb.notifier_call = battery_notify; - register_pm_notifier(&battery->pm_nb); + result = register_pm_notifier(&battery->pm_nb); + if (result) + goto fail; device_init_wakeup(&device->dev, 1); From patchwork Wed Sep 4 07:12:53 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: 825354 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 7F11C83CA3; Wed, 4 Sep 2024 07:13:06 +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=1725433991; cv=none; b=VHLKzmDqMFeP1bWG2V/noF5cjpA89fuqq6Mp2JIDzWW3WvvZnv46LQ4kx52XW8EWj6dQr4AlRsvM0OKxkMS8zyi+7/bvC0MyparO2QGMfVj6yyyGtmdr0hJZvsR6dLqdGN4zxs3yc4FOezyM/TJc+/KoP5gQIvqivs0XKhis2L8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725433991; c=relaxed/simple; bh=5k0BoqRQGceC6Q94sFXBaBULbzuT+NUhzfZtoBIIH/Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rycYyXrXY5Yg5Odn0XWk21Hds7FQ1+WV7kqtvlF/FOHZUswAeiOccaRTf0mOfgvJ2fpNeKMlIyEILyOL7JuN6pCzfOKNcV1ye7/5wk2olwEOW+Xkv3OPTvYSyoHnX7+ilRuZ9spL9YmFmbCU36snQTCDLuYXklVBpjXfeoHRzds= 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=L7hFAaWN; 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="L7hFAaWN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1725433984; bh=5k0BoqRQGceC6Q94sFXBaBULbzuT+NUhzfZtoBIIH/Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=L7hFAaWNOCftx0YW4JerPT+NZEiwGafmK+4cuSFdDCuFOOQTv6vdnTVueLzl9kLYs LvccBRa0AvsMf2FYazn0/BEMGfVwWs4E6t+tUCEScHyP1IJvKhk+cT7u37yAd3Vumb oAC/BuQZ338SMcftLAMey/QzDPK+ucjMw+yGzZsg= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 04 Sep 2024 09:12:53 +0200 Subject: [PATCH 2/5] ACPI: battery: allocate driver data through devm_ APIs Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240904-acpi-battery-cleanups-v1-2-a3bf74f22d40@weissschuh.net> References: <20240904-acpi-battery-cleanups-v1-0-a3bf74f22d40@weissschuh.net> In-Reply-To: <20240904-acpi-battery-cleanups-v1-0-a3bf74f22d40@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thom?= =?utf-8?q?as_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1725433984; l=1138; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=5k0BoqRQGceC6Q94sFXBaBULbzuT+NUhzfZtoBIIH/Q=; b=3OwIEqPims6Mr504oojSJWG0Mwmqilqur1OrslBquJzPGX//GfM3vsuvu3lNERZOuNPdv2q6Y IsXLxqd82wYCs6CLydk1vkk0EeZ/cvTbFoUIb/XSDHNSa6HohQWTx6e X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Simplify the cleanup logic a bit. Signed-off-by: Thomas Weißschuh --- drivers/acpi/battery.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 677618eb38bf..a778bf6a6c4e 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -1215,7 +1215,7 @@ static int acpi_battery_add(struct acpi_device *device) if (device->dep_unmet) return -EPROBE_DEFER; - battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL); + battery = devm_kzalloc(&device->dev, sizeof(*battery), GFP_KERNEL); if (!battery) return -ENOMEM; battery->device = device; @@ -1255,7 +1255,6 @@ static int acpi_battery_add(struct acpi_device *device) sysfs_remove_battery(battery); mutex_destroy(&battery->lock); mutex_destroy(&battery->sysfs_lock); - kfree(battery); return result; } @@ -1278,7 +1277,6 @@ static void acpi_battery_remove(struct acpi_device *device) mutex_destroy(&battery->lock); mutex_destroy(&battery->sysfs_lock); - kfree(battery); } #ifdef CONFIG_PM_SLEEP From patchwork Wed Sep 4 07:12:54 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: 825677 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 06F6C14831E; Wed, 4 Sep 2024 07:13:12 +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=1725433993; cv=none; b=kVaJOOMAf238IzOc6fwkq6kjfkMPhLq6G75IIPkZ91YQQ5Laank2MVXkRqd7+FvtFORAN9GQhTtbpJG6DpojLqcbsaHM7JZMKrx/a+guiZ7lBxVkOPz1Gl8ZXhzdmlAxiLwNI5ZtGIkZHljtAr12a7ALOBkUgudHxX0jeTIcLP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725433993; c=relaxed/simple; bh=iidNbhVu9dGaX9vvLnlzhXLhakvIQbqR4E89Zx6qqiw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ftP7cz5y/Bmyawv75f6bmF7iPt09+rYMjCMLEBR8K7CYXcZTCDF9+dn4ozGBf2ayw2clGb+QBeKgM+/TrnDy1l9BQJtMYwbUkI1TEJjBzivuLectsxtT5XPECvgN9FxFho33gxGEt/OG9G8niL4B81uxrbwJuzw66rWHShQ37nM= 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=Gy97Wmbd; 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="Gy97Wmbd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1725433984; bh=iidNbhVu9dGaX9vvLnlzhXLhakvIQbqR4E89Zx6qqiw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Gy97WmbdUGElt/MXyov6S7aJ497tLRKJYxLsMSG933t+uIS/luPBApz4axlyzs5HF jm8f7fbSnvsJqDBxe9lMIdF1fce3qW4UJUBbIUrjHIU6Qa5dQinNtMGMretzM9qNIh 9/T7zgjGNtMqXRazSMzmURKJnCK3Le8qqQtkDjqk= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 04 Sep 2024 09:12:54 +0200 Subject: [PATCH 3/5] ACPI: battery: initialize mutexes through devm_ APIs Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240904-acpi-battery-cleanups-v1-3-a3bf74f22d40@weissschuh.net> References: <20240904-acpi-battery-cleanups-v1-0-a3bf74f22d40@weissschuh.net> In-Reply-To: <20240904-acpi-battery-cleanups-v1-0-a3bf74f22d40@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thom?= =?utf-8?q?as_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1725433984; l=1468; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=iidNbhVu9dGaX9vvLnlzhXLhakvIQbqR4E89Zx6qqiw=; b=6jatBtz7LB/NNCd63oh4MIxWG+ziT6GhhTJ8cyWPxddrGz4HLd6tEECn4bzLm3FXqYHJoj89Q 6fKaSg1vDPXA4azW52X1E31H98T9PpjN9G0oZExIyLR2OxYnW4AolKz X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Simplify the cleanup logic a bit. Signed-off-by: Thomas Weißschuh --- drivers/acpi/battery.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index a778bf6a6c4e..da50ca8df007 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -1222,8 +1222,8 @@ static int acpi_battery_add(struct acpi_device *device) strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); device->driver_data = battery; - mutex_init(&battery->lock); - mutex_init(&battery->sysfs_lock); + devm_mutex_init(&device->dev, &battery->lock); + devm_mutex_init(&device->dev, &battery->sysfs_lock); if (acpi_has_method(battery->device->handle, "_BIX")) set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags); @@ -1253,8 +1253,6 @@ static int acpi_battery_add(struct acpi_device *device) unregister_pm_notifier(&battery->pm_nb); fail: sysfs_remove_battery(battery); - mutex_destroy(&battery->lock); - mutex_destroy(&battery->sysfs_lock); return result; } @@ -1274,9 +1272,6 @@ static void acpi_battery_remove(struct acpi_device *device) device_init_wakeup(&device->dev, 0); unregister_pm_notifier(&battery->pm_nb); sysfs_remove_battery(battery); - - mutex_destroy(&battery->lock); - mutex_destroy(&battery->sysfs_lock); } #ifdef CONFIG_PM_SLEEP From patchwork Wed Sep 4 07:12:55 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: 825355 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 7F1FA146A83; Wed, 4 Sep 2024 07:13:07 +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=1725433991; cv=none; b=DIjMs0P8wTlCAUf4rGn5E8gQt+Le+pe219EfnwKetqoA3z1QqcT5/1wXD6iNPVj0CUKembu31iK+GuX6vKHVstA7dG2hs+jaeLJod5IHn6oj/I7Q3XXMs8dECAV+Sj9NVCZRObQE8jWBtDsKIDgAt3srgJcvcR3w1RohSspi4VU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725433991; c=relaxed/simple; bh=/F26bT56Alfb0hZVxsZjubPK5KJki1t5EcCZVGq2Z/M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pGv031iHRCsBBNWU4hfCmOqFBfY/SmxaVCrzGZ45WLB4p//FpX62FvXZgHwhoi8kmNgAEYj4UrF3ttwdaBytVk+U7N+BLXMgeVcKHoNWl0i2E4/LoVtlOXG3lUkFrXOG5MUTwCOq6b+L9tXlM8HMoKubG8g+YGAh4cuEqELr6fg= 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=ou7Rffa8; 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="ou7Rffa8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1725433985; bh=/F26bT56Alfb0hZVxsZjubPK5KJki1t5EcCZVGq2Z/M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ou7Rffa8mn+GyKcKdIBhSyCn5G8aEqsVw1pI6DtCzLTMsaqx7bzxPKwSDIFif8t+X xY/XdRIETapoRnzL3H1+p1hqOCbB6whjOfnfZSb/+ueoRjclNla32UxwGer0ahH6Ss 1+id8xguyGY+3byjlM2LPXcbkEO+M24fFt1U/cxI= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 04 Sep 2024 09:12:55 +0200 Subject: [PATCH 4/5] ACPI: battery: use DEFINE_SIMPLE_DEV_PM_OPS Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240904-acpi-battery-cleanups-v1-4-a3bf74f22d40@weissschuh.net> References: <20240904-acpi-battery-cleanups-v1-0-a3bf74f22d40@weissschuh.net> In-Reply-To: <20240904-acpi-battery-cleanups-v1-0-a3bf74f22d40@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thom?= =?utf-8?q?as_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1725433984; l=1499; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=/F26bT56Alfb0hZVxsZjubPK5KJki1t5EcCZVGq2Z/M=; b=nCthR7VdRbmYhdGY+0xQsNJJIeRAl9jWACe/UDguKsPm9DUI4LduoH8p4lpUDbctDoAvb0Q3B Awn4C5zoD0uDqVw4fbvcyGRW1YoIJZRdj3hpV79nuOiIHUS3m9yh3CU X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Use the recommended macro to define the PM ops. Also use pm_sleep_ptr() when assigning the ops to the driver. This allows the removal of the ifdef CONFIG_PM_SLEEP. Signed-off-by: Thomas Weißschuh --- drivers/acpi/battery.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index da50ca8df007..4bd746f8c0ac 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -1274,7 +1274,6 @@ static void acpi_battery_remove(struct acpi_device *device) sysfs_remove_battery(battery); } -#ifdef CONFIG_PM_SLEEP /* this is needed to learn about changes made in suspended state */ static int acpi_battery_resume(struct device *dev) { @@ -1291,11 +1290,8 @@ static int acpi_battery_resume(struct device *dev) acpi_battery_update(battery, true); return 0; } -#else -#define acpi_battery_resume NULL -#endif -static SIMPLE_DEV_PM_OPS(acpi_battery_pm, NULL, acpi_battery_resume); +static DEFINE_SIMPLE_DEV_PM_OPS(acpi_battery_pm, NULL, acpi_battery_resume); static struct acpi_driver acpi_battery_driver = { .name = "battery", @@ -1305,7 +1301,7 @@ static struct acpi_driver acpi_battery_driver = { .add = acpi_battery_add, .remove = acpi_battery_remove, }, - .drv.pm = &acpi_battery_pm, + .drv.pm = pm_sleep_ptr(&acpi_battery_pm), }; static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie) From patchwork Wed Sep 4 07:12:56 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: 825679 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 7F1BB146A7B; Wed, 4 Sep 2024 07:13:07 +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=1725433991; cv=none; b=rjZGnxJdTFnBCHF6mRZVlHYuI8OjyYxJ9TD006gI16m7OVmL9goRBazrF1RmhC2kTYcXycs27Lp+YU4p5mzTV8zFYfVJSBvlP0cd+Fxfk7czYDsvdueftO/sXLJ/JAb1EPfp3lqckjwLmiiChAl8Frr+WIdqVQOteXLpyf/RbuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725433991; c=relaxed/simple; bh=wQXxSCmkiFU6W3wml5qaESF/PpuUQynjgR0MHH9BQqs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I8gRv8M1EWEGu6x8pHlcHPv7Pm4OIEZ1DXLmMg5coEIHl/CdxdZRDaFCSGE+vHZNgp0BcQ6gqGfwuSTJiAM+ZIPg8DjkLadswPhroIwQrhBG7K9oGKMzaq7CTEiMWobHun7CXij/tcAmUmOnHK5pC2Hx5MkO2g1SwJG1vPy4+C8= 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=IScRhpdU; 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="IScRhpdU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1725433985; bh=wQXxSCmkiFU6W3wml5qaESF/PpuUQynjgR0MHH9BQqs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IScRhpdUMdSYuhxrFcDgc31tTLS/2hCqPdKV8GDggsreCqLen1I27dxau8mahB8pw u5YQaD583WgH8314m/ol/M22r6gCEM4oIURMsZ+jhc4mZWq/2eCjWaDAiNpTxdumjI ZeKhF2n1PI9AECiIB/RvTv61LVM+iQf265OJjRRI= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 04 Sep 2024 09:12:56 +0200 Subject: [PATCH 5/5] ACPI: battery: install notify handler through ACPI core Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240904-acpi-battery-cleanups-v1-5-a3bf74f22d40@weissschuh.net> References: <20240904-acpi-battery-cleanups-v1-0-a3bf74f22d40@weissschuh.net> In-Reply-To: <20240904-acpi-battery-cleanups-v1-0-a3bf74f22d40@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thom?= =?utf-8?q?as_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1725433984; l=1982; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=wQXxSCmkiFU6W3wml5qaESF/PpuUQynjgR0MHH9BQqs=; b=Gu1oTyUw6dW6jhbdERyp4pMp6ClyLdmCg7yYgA6t/OFkhX+YKdypTcRa80nnz0FhcN1L7mmT6 7DEmGnqbdgKAhsn0UaVD3dZWMYz5UGW7ql0bfhaZxrJMJuXKZsahdbs X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The ACPI core can register the notify handler on its own, simplifying error handling and cleanup. Signed-off-by: Thomas Weißschuh --- drivers/acpi/battery.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 4bd746f8c0ac..88899c417f15 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -1060,9 +1060,8 @@ static void acpi_battery_refresh(struct acpi_battery *battery) } /* Driver Interface */ -static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) +static void acpi_battery_notify(struct acpi_device *device, u32 event) { - struct acpi_device *device = data; struct acpi_battery *battery = acpi_driver_data(device); struct power_supply *old; @@ -1241,16 +1240,8 @@ static int acpi_battery_add(struct acpi_device *device) device_init_wakeup(&device->dev, 1); - result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY, - acpi_battery_notify, device); - if (result) - goto fail_pm; - return 0; -fail_pm: - device_init_wakeup(&device->dev, 0); - unregister_pm_notifier(&battery->pm_nb); fail: sysfs_remove_battery(battery); @@ -1266,9 +1257,6 @@ static void acpi_battery_remove(struct acpi_device *device) battery = acpi_driver_data(device); - acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY, - acpi_battery_notify); - device_init_wakeup(&device->dev, 0); unregister_pm_notifier(&battery->pm_nb); sysfs_remove_battery(battery); @@ -1297,9 +1285,11 @@ static struct acpi_driver acpi_battery_driver = { .name = "battery", .class = ACPI_BATTERY_CLASS, .ids = battery_device_ids, + .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, .ops = { .add = acpi_battery_add, .remove = acpi_battery_remove, + .notify = acpi_battery_notify, }, .drv.pm = pm_sleep_ptr(&acpi_battery_pm), };