From patchwork Fri Jun 16 16:50:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wilczynski, Michal" X-Patchwork-Id: 109264 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1482894vqr; Fri, 16 Jun 2023 09:57:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ627N6nRTlq7F+t4ni1IRjcrifoZiGKUSxeSFLLmv50DrQU8s07BGiaM2P9FklGy1kPNyhw X-Received: by 2002:a05:6808:20a9:b0:39e:b397:637b with SMTP id s41-20020a05680820a900b0039eb397637bmr1057188oiw.26.1686934657472; Fri, 16 Jun 2023 09:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686934657; cv=none; d=google.com; s=arc-20160816; b=aKrXHVKQ1qx03x6ur3Jmn0E5PBY+DkaBCrCm9mnOyG+ho7w6+xKv8AUBKOocuMYTrV LtV/Xov99qySnuOsmoJ+mpRPkM8jm0Gvl2/iSu3T24pqTQgugLms6Undq6a6eR5jYTvd VQFM7htITr9UKoAZn0jLaQEqFT1XkIMCO5nWMWeGAkdI8yFl6ti1fNhWAhg0QovxxENt nh2D0M+qb/3y+5p4FevEywrZpkPY6pSzzndOXI3IYtT5Csq00p6UiKWK8jX17k+LScdX 8t2Mqx6c8An2CyNH4MmMXrIMUSvPogjaJj2b1AxvajxeLlKT8ZVZpeJwvYHY/+2LI3W4 3VDA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020a63c041000000b005303a26dbf8si15223493pgi.408.2023.06.16.09.57.23; Fri, 16 Jun 2023 09:57:37 -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 S1345839AbjFPQw3 (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768879195144314976?= X-GMAIL-MSGID: =?utf-8?q?1768879195144314976?= 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, };