Fri Apr 26 18:19:18 2024 UTC (14d)
PR/58201: Malte Dehling: re-order sysmon initialization before acpi
registration, to avoid needing to call to acpi_deregister_notify on sysmon
failure.


(christos)
diff -r1.121 -r1.122 src/sys/dev/acpi/acpi_bat.c

cvs diff -r1.121 -r1.122 src/sys/dev/acpi/acpi_bat.c (expand / switch to unified diff)

--- src/sys/dev/acpi/acpi_bat.c 2022/01/07 01:10:57 1.121
+++ src/sys/dev/acpi/acpi_bat.c 2024/04/26 18:19:18 1.122
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: acpi_bat.c,v 1.121 2022/01/07 01:10:57 riastradh Exp $ */ 1/* $NetBSD: acpi_bat.c,v 1.122 2024/04/26 18:19:18 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum of By Noon Software, Inc. 8 * by Charles M. Hannum of By Noon Software, Inc.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -65,27 +65,27 @@ @@ -65,27 +65,27 @@
65/* 65/*
66 * ACPI Battery Driver. 66 * ACPI Battery Driver.
67 * 67 *
68 * ACPI defines two different battery device interfaces: "Control 68 * ACPI defines two different battery device interfaces: "Control
69 * Method" batteries, in which AML methods are defined in order to get 69 * Method" batteries, in which AML methods are defined in order to get
70 * battery status and set battery alarm thresholds, and a "Smart 70 * battery status and set battery alarm thresholds, and a "Smart
71 * Battery" device, which is an SMbus device accessed through the ACPI 71 * Battery" device, which is an SMbus device accessed through the ACPI
72 * Embedded Controller device. 72 * Embedded Controller device.
73 * 73 *
74 * This driver is for the "Control Method"-style battery only. 74 * This driver is for the "Control Method"-style battery only.
75 */ 75 */
76 76
77#include <sys/cdefs.h> 77#include <sys/cdefs.h>
78__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.121 2022/01/07 01:10:57 riastradh Exp $"); 78__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.122 2024/04/26 18:19:18 christos Exp $");
79 79
80#include <sys/param.h> 80#include <sys/param.h>
81#include <sys/condvar.h> 81#include <sys/condvar.h>
82#include <sys/device.h> 82#include <sys/device.h>
83#include <sys/kernel.h> 83#include <sys/kernel.h>
84#include <sys/kmem.h> 84#include <sys/kmem.h>
85#include <sys/module.h> 85#include <sys/module.h>
86#include <sys/mutex.h> 86#include <sys/mutex.h>
87#include <sys/systm.h> 87#include <sys/systm.h>
88 88
89#include <dev/acpi/acpireg.h> 89#include <dev/acpi/acpireg.h>
90#include <dev/acpi/acpivar.h> 90#include <dev/acpi/acpivar.h>
91 91
@@ -752,37 +752,36 @@ acpibat_init_envsys(device_t dv) @@ -752,37 +752,36 @@ acpibat_init_envsys(device_t dv)
752 for (i = 0; i < ACPIBAT_COUNT; i++) { 752 for (i = 0; i < ACPIBAT_COUNT; i++) {
753 if (sysmon_envsys_sensor_attach(sc->sc_sme, 753 if (sysmon_envsys_sensor_attach(sc->sc_sme,
754 &sc->sc_sensor[i])) 754 &sc->sc_sensor[i]))
755 goto fail; 755 goto fail;
756 } 756 }
757 757
758 sc->sc_sme->sme_name = device_xname(dv); 758 sc->sc_sme->sme_name = device_xname(dv);
759 sc->sc_sme->sme_cookie = dv; 759 sc->sc_sme->sme_cookie = dv;
760 sc->sc_sme->sme_refresh = acpibat_refresh; 760 sc->sc_sme->sme_refresh = acpibat_refresh;
761 sc->sc_sme->sme_class = SME_CLASS_BATTERY; 761 sc->sc_sme->sme_class = SME_CLASS_BATTERY;
762 sc->sc_sme->sme_flags = SME_POLL_ONLY | SME_INIT_REFRESH; 762 sc->sc_sme->sme_flags = SME_POLL_ONLY | SME_INIT_REFRESH;
763 sc->sc_sme->sme_get_limits = acpibat_get_limits; 763 sc->sc_sme->sme_get_limits = acpibat_get_limits;
764 764
 765 if (sysmon_envsys_register(sc->sc_sme))
 766 goto fail;
 767
765 (void)acpi_register_notify(sc->sc_node, acpibat_notify_handler); 768 (void)acpi_register_notify(sc->sc_node, acpibat_notify_handler);
766 acpibat_update_info(dv); 769 acpibat_update_info(dv);
767 acpibat_update_status(dv); 770 acpibat_update_status(dv);
768 771
769 if (sysmon_envsys_register(sc->sc_sme)) 
770 goto fail; 
771 
772 (void)pmf_device_register(dv, NULL, acpibat_resume); 772 (void)pmf_device_register(dv, NULL, acpibat_resume);
773 773
774 return; 774 return;
775 
776fail: 775fail:
777 aprint_error_dev(dv, "failed to initialize sysmon\n"); 776 aprint_error_dev(dv, "failed to initialize sysmon\n");
778 777
779 sysmon_envsys_destroy(sc->sc_sme); 778 sysmon_envsys_destroy(sc->sc_sme);
780 kmem_free(sc->sc_sensor, ACPIBAT_COUNT * sizeof(*sc->sc_sensor)); 779 kmem_free(sc->sc_sensor, ACPIBAT_COUNT * sizeof(*sc->sc_sensor));
781 780
782 sc->sc_sme = NULL; 781 sc->sc_sme = NULL;
783 sc->sc_sensor = NULL; 782 sc->sc_sensor = NULL;
784} 783}
785 784
786static void 785static void
787acpibat_refresh(struct sysmon_envsys *sme, envsys_data_t *edata) 786acpibat_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
788{ 787{