Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2939095rwd; Fri, 16 Jun 2023 10:03:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5e15as71YWzo+NX+bvbVs2Q4JX8KdhJ56IMrCBqj4YCSWP29NPYqShu2CNasLYvrc9VFbJ X-Received: by 2002:a17:903:1ce:b0:1b0:4934:88bc with SMTP id e14-20020a17090301ce00b001b0493488bcmr2415104plh.47.1686935006718; Fri, 16 Jun 2023 10:03:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686935006; cv=none; d=google.com; s=arc-20160816; b=Sxn1JeFuvzZ2cFXCf53hwVbE/wVEKxHUzA9W8n3v8UppXnNdpBiOAuOzgnN37f5XA/ F7RDQmXI5wYRE4Xp2cSngVf8xA/MqLO1EIrIzBTnp9MezsgUwbcA3WG9DnEb1nNAjp6W VPcKIvsWSMunJGN+31mCFKonMoeICy5CMEEwvsg5aFaAcGGaT0/PJmbWXwu+HUIUDouh KdgE3gItyj1CO8Cdjumq1egh+xuMr2FDvBzT9Qlf2m/C5pdVUk8dH2+wz22PVVn8Y4sN 1F9xxIJhhwPHi7P3Jbc/jmvh6SAEPxsfoZwsHGKbxgN2zXJg18a9/iZIZzWtUXfux/1s JTmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HdJBZdbh0ho8GScOsb83sqU8HdvvOItlit+a+z9tqQ4=; b=dW67W58LCxdz6jE+kzbDcxTckbhtBeYulG3lhf8Doz7gvOkeC6QmhECIOa85nokcnz Eyh3vnOEEAmg0XcHNx/4UQqL8h1ENJBVmN9XtNsdgD/OjGmsPPTkigfj2VuAvKkGbG9q EVPDbQVQe1rWbGsa0+vX7CPN6lS+VJ+CO7mnnzPhcKlbtxEOGhy/LNMtKCD7+/YAymjS 918DCZupTcxyQoJ3qYUSM7LRY6JpRjlV1XTLRZVFz6UImR+EtMWM1gz+7m7b6nKYpiDT YuKvUFCR22k9Xydoibgq+2KUBWF95vb9ZHFLy+JgOpm+p61MuR32FIVGJSGynFt1FOoJ MuGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OFwekCBE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b16-20020a170903229000b001b25e9a76d5si12976042plh.625.2023.06.16.10.03.12; Fri, 16 Jun 2023 10:03:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OFwekCBE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345778AbjFPQw3 (ORCPT + 99 others); Fri, 16 Jun 2023 12:52:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345835AbjFPQva (ORCPT ); Fri, 16 Jun 2023 12:51:30 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3A743C0A; Fri, 16 Jun 2023 09:51:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686934273; x=1718470273; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YgJs53JcsAi+GPoM5qs7RjcNG38TJwxYF403LVi9ZLQ=; b=OFwekCBErlCVFHwX0cDt/vI1f6AS/nOfFDR4eoUQ3jkU1vB5yauOdy0+ ulImn5xJGinsTkTZs4bJmW34DGfHui/nTaVXzbTMShP7FOQ4q/HiRxYzi yiLrUJLzS+qCufu+SQGXtbIX53qOxwWhE0fQP3tUT63v8hRh/8WEqNUkG NahqSUTB+3iQuzAudzbgK78nh8yghH24DO50022DnlPUMdJQpBjX1D+oX HC1wjnuOVLC/1lq5VBW+d/4bQ2vsMEG5N3tJAuBDCMsZzpqpxRo58ByzT xGNt6kvYORV2RsuimZV9SN4TmSH+WLgyNCIB4it9CJJMidEayFRY9CAGA Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10743"; a="422913027" X-IronPort-AV: E=Sophos;i="6.00,248,1681196400"; d="scan'208";a="422913027" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2023 09:51:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10743"; a="707154175" X-IronPort-AV: E=Sophos;i="6.00,248,1681196400"; d="scan'208";a="707154175" Received: from powerlab.fi.intel.com ([10.237.71.25]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2023 09:51:08 -0700 From: Michal Wilczynski To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, dan.j.williams@intel.com, vishal.l.verma@intel.com, lenb@kernel.org, dave.jiang@intel.com, ira.weiny@intel.com, rui.zhang@intel.com, linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, Michal Wilczynski , "Rafael J . Wysocki" Subject: [PATCH v5 05/10] acpi/battery: Move handler installing logic to driver Date: Fri, 16 Jun 2023 19:50:29 +0300 Message-ID: <20230616165034.3630141-6-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616165034.3630141-1-michal.wilczynski@intel.com> References: <20230616165034.3630141-1-michal.wilczynski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently logic for installing notifications from ACPI devices is implemented using notify callback in struct acpi_driver. Preparations are being made to replace acpi_driver with more generic struct platform_driver, which doesn't contain notify callback. Furthermore as of now handlers are being called indirectly through acpi_notify_device(), which decreases performance. Call acpi_dev_install_notify_handler() at the end of .add() callback. Call acpi_dev_remove_notify_handler() at the beginning of .remove() callback. Change arguments passed to the notify function to match with what's required by acpi_install_notify_handler(). Remove .notify callback initialization in acpi_driver. While at it, fix lack of whitespaces in .remove() callback. Suggested-by: Rafael J. Wysocki Signed-off-by: Michal Wilczynski --- drivers/acpi/battery.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 9c67ed02d797..6337e7b1f6e1 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -1034,11 +1034,14 @@ static void acpi_battery_refresh(struct acpi_battery *battery) } /* Driver Interface */ -static void acpi_battery_notify(struct acpi_device *device, u32 event) +static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) { - struct acpi_battery *battery = acpi_driver_data(device); + struct acpi_device *device = data; + struct acpi_battery *battery; struct power_supply *old; + battery = acpi_driver_data(device); + if (!battery) return; old = battery->bat; @@ -1212,13 +1215,23 @@ static int acpi_battery_add(struct acpi_device *device) device_init_wakeup(&device->dev, 1); - return result; + result = acpi_dev_install_notify_handler(device, + ACPI_ALL_NOTIFY, + acpi_battery_notify); + if (result) + goto fail_deinit_wakup_and_unregister; + + return 0; +fail_deinit_wakup_and_unregister: + device_init_wakeup(&device->dev, 0); + unregister_pm_notifier(&battery->pm_nb); fail: sysfs_remove_battery(battery); mutex_destroy(&battery->lock); mutex_destroy(&battery->sysfs_lock); kfree(battery); + return result; } @@ -1228,10 +1241,17 @@ static void acpi_battery_remove(struct acpi_device *device) if (!device || !acpi_driver_data(device)) return; - device_init_wakeup(&device->dev, 0); + 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); + mutex_destroy(&battery->lock); mutex_destroy(&battery->sysfs_lock); kfree(battery); @@ -1264,11 +1284,9 @@ 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 = &acpi_battery_pm, }; -- 2.41.0