From patchwork Wed Oct 11 08:33: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: 13416883 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) (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 3680B1A704 for ; Wed, 11 Oct 2023 08:34:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="amvpAKfZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697013244; x=1728549244; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5PKJcHQuGAJasXvUQcWL2vxKmsvzbQLbVutteBr3/jA=; b=amvpAKfZqAcbKWuhiv2IMo1W/FxAj7GRupmRhYTq4IYqmxQTlaV2NJkx xFotBQjPcSOtnJdHN18VxGYX6tui2/xsFLIQ6SqvegRLVHXeP5fjThs0N qr8Cyn+VZ0EEF3NYSjqYC8SMTmrQWlsHqoAZudvuOi2WTxkfdDS67pGu/ VU9ZLh/mbW/f/bAJK2LeZVNh180IdXCwf/WYXbc68FLTbP9rNLx4LpcpQ +dZCfjLExg9nceHlqam6Ni7Ib8UovKrjqxuvz4dSmeA39UhaFKE9xIyBq nuu/InjMCDhAU7OW744UcZJUfPOoRTXNWsszXL6OL6y1udyXYzO5DS94T g==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="388480161" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="388480161" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:34:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="897548177" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="897548177" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:32:12 -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 Subject: [PATCH v3 1/6] ACPI: AC: Remove unnecessary checks Date: Wed, 11 Oct 2023 11:33:29 +0300 Message-ID: <20231011083334.3987477-2-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231011083334.3987477-1-michal.wilczynski@intel.com> References: <20231011083334.3987477-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove unnecessary checks for NULL for variables that can't be NULL at the point they're checked for it. Defensive programming is discouraged in the kernel. Signed-off-by: Michal Wilczynski --- drivers/acpi/ac.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index aac3e561790c..83d45c681121 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c @@ -131,9 +131,6 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) struct acpi_device *device = data; struct acpi_ac *ac = acpi_driver_data(device); - if (!ac) - return; - switch (event) { default: acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", @@ -216,12 +213,8 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = { static int acpi_ac_add(struct acpi_device *device) { struct power_supply_config psy_cfg = {}; - int result = 0; - struct acpi_ac *ac = NULL; - - - if (!device) - return -EINVAL; + struct acpi_ac *ac; + int result; ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL); if (!ac) @@ -275,16 +268,9 @@ static int acpi_ac_add(struct acpi_device *device) #ifdef CONFIG_PM_SLEEP static int acpi_ac_resume(struct device *dev) { - struct acpi_ac *ac; + struct acpi_ac *ac = acpi_driver_data(to_acpi_device(dev)); unsigned int old_state; - if (!dev) - return -EINVAL; - - ac = acpi_driver_data(to_acpi_device(dev)); - if (!ac) - return -EINVAL; - old_state = ac->state; if (acpi_ac_get_state(ac)) return 0; @@ -299,12 +285,7 @@ static int acpi_ac_resume(struct device *dev) static void acpi_ac_remove(struct acpi_device *device) { - struct acpi_ac *ac = NULL; - - if (!device || !acpi_driver_data(device)) - return; - - ac = acpi_driver_data(device); + struct acpi_ac *ac = acpi_driver_data(device); acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY, acpi_ac_notify); From patchwork Wed Oct 11 08:33:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wilczynski, Michal" X-Patchwork-Id: 13416884 X-Patchwork-Delegate: iweiny@gmail.com Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) (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 8A2D21A711 for ; Wed, 11 Oct 2023 08:34:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="EqnPvV3A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697013246; x=1728549246; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9GeUK2SGN9OGtW6dMn16QDj8PfFEO9Do3zKwnp3cbpk=; b=EqnPvV3Aj7dP5U2L+jn407ohs3XkMEs/6ogno6QeZ4AP8ONZ2IXTVCOM su/ymOdub9R3qbkxYOQMNsxF86u665W4h4TXIvMg7jpSRzmIJIAu7oy3s zoz8sA7dIAnH8naEfY/efFC8XfFKxEJu4F60le7VoBoQjczKfMZHc4f49 rC7266FYMEqpuAXE0RQ5pp8FK9YLulbSp4EkjMYQ/Ft6IFMVJshvvreMc wyAYkSiChdIHlJtKhtlgayQrkJpD86zPz5FIkbJ08EGpdUNepcMn7CHwj F8jxVchniDnupsRcgffEcFyGfxgRghPLbnBKxspHVOEVcPhGJbUi5cmDh w==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="388480171" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="388480171" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:34:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="897548199" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="897548199" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:32:16 -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 , Andy Shevchenko Subject: [PATCH v3 2/6] ACPI: AC: Use string_choices API instead of ternary operator Date: Wed, 11 Oct 2023 11:33:30 +0300 Message-ID: <20231011083334.3987477-3-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231011083334.3987477-1-michal.wilczynski@intel.com> References: <20231011083334.3987477-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use modern string_choices API instead of manually determining the output using ternary operator. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Michal Wilczynski --- drivers/acpi/ac.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index 83d45c681121..f809f6889b4a 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -243,8 +244,8 @@ static int acpi_ac_add(struct acpi_device *device) goto err_release_ac; } - pr_info("%s [%s] (%s)\n", acpi_device_name(device), - acpi_device_bid(device), ac->state ? "on-line" : "off-line"); + pr_info("%s [%s] (%s-line)\n", acpi_device_name(device), + acpi_device_bid(device), str_on_off(ac->state)); ac->battery_nb.notifier_call = acpi_ac_battery_notify; register_acpi_notifier(&ac->battery_nb); From patchwork Wed Oct 11 08:33:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wilczynski, Michal" X-Patchwork-Id: 13416885 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) (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 480B21A716 for ; Wed, 11 Oct 2023 08:34:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SazJ95Dm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697013247; x=1728549247; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r721DVipL9bpqgYhSjxYjGmtAilZNRSPBbALGRuuO1M=; b=SazJ95DmJRzLb18tLk8vhYNnA2K7X80EX1QEfw2myssfiNH2SsGEWc0P FhOZEz+7M1M0bKcFuY+iZrNV3lfPRGH7oZoM336FTZLpmLFkscRI/AbRU TQH0SnYuhYjZj6+Lmd55vHHsjsSQ1nzzIZ/Su5E2i6qTGezzbV0TxtgLr E9MdqaGz0gYLyQ7bt9NTCJ2RI3XWz/fmOfrLXTkWTmzJ7SCJLkHeBwBoA uc+lyNvadJZbDXu2VoMT6dleUmI4fno3O1DHrSe7dc22exHqzbHug4GGx /0GWiAzwBoVxPMC4UrfCevs3vVtuY/vM/JzVhDSSzEVfMT32uI9Jwl978 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="388480191" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="388480191" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:34:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="897548208" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="897548208" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:32:19 -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 v3 3/6] ACPI: AC: Replace acpi_driver with platform_driver Date: Wed, 11 Oct 2023 11:33:31 +0300 Message-ID: <20231011083334.3987477-4-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231011083334.3987477-1-michal.wilczynski@intel.com> References: <20231011083334.3987477-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 AC driver uses struct acpi_driver incorrectly to register itself. This is wrong as the instances of the ACPI devices are not meant to be literal devices, they're supposed to describe ACPI entry of a particular device. Use platform_driver instead of acpi_driver. In relevant places call platform devices instances pdev to make a distinction with ACPI devices instances. Drop unnecessary casts from acpi_bus_generate_netlink_event() and acpi_notifier_call_chain(). Add a blank line to distinguish pdev API vs local ACPI notify function. Suggested-by: Rafael J. Wysocki Signed-off-by: Michal Wilczynski --- drivers/acpi/ac.c | 61 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index f809f6889b4a..1dd4919be7ac 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c @@ -33,8 +33,9 @@ MODULE_AUTHOR("Paul Diefenbaugh"); MODULE_DESCRIPTION("ACPI AC Adapter Driver"); MODULE_LICENSE("GPL"); -static int acpi_ac_add(struct acpi_device *device); -static void acpi_ac_remove(struct acpi_device *device); +static int acpi_ac_probe(struct platform_device *pdev); +static void acpi_ac_remove(struct platform_device *pdev); + static void acpi_ac_notify(acpi_handle handle, u32 event, void *data); static const struct acpi_device_id ac_device_ids[] = { @@ -51,17 +52,6 @@ static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume); static int ac_sleep_before_get_state_ms; static int ac_only; -static struct acpi_driver acpi_ac_driver = { - .name = "ac", - .class = ACPI_AC_CLASS, - .ids = ac_device_ids, - .ops = { - .add = acpi_ac_add, - .remove = acpi_ac_remove, - }, - .drv.pm = &acpi_ac_pm, -}; - struct acpi_ac { struct power_supply *charger; struct power_supply_desc charger_desc; @@ -129,8 +119,9 @@ static enum power_supply_property ac_props[] = { /* Driver Model */ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) { - struct acpi_device *device = data; - struct acpi_ac *ac = acpi_driver_data(device); + struct device *dev = data; + struct acpi_ac *ac = dev_get_drvdata(dev); + struct acpi_device *device = ACPI_COMPANION(dev); switch (event) { default: @@ -152,9 +143,10 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) acpi_ac_get_state(ac); acpi_bus_generate_netlink_event(device->pnp.device_class, - dev_name(&device->dev), event, - (u32) ac->state); - acpi_notifier_call_chain(device, event, (u32) ac->state); + dev_name(dev), + event, + ac->state); + acpi_notifier_call_chain(device, event, ac->state); kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE); } } @@ -211,8 +203,9 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = { {}, }; -static int acpi_ac_add(struct acpi_device *device) +static int acpi_ac_probe(struct platform_device *pdev) { + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); struct power_supply_config psy_cfg = {}; struct acpi_ac *ac; int result; @@ -224,7 +217,8 @@ static int acpi_ac_add(struct acpi_device *device) ac->device = device; strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME); strcpy(acpi_device_class(device), ACPI_AC_CLASS); - device->driver_data = ac; + + platform_set_drvdata(pdev, ac); result = acpi_ac_get_state(ac); if (result) @@ -237,7 +231,7 @@ static int acpi_ac_add(struct acpi_device *device) ac->charger_desc.properties = ac_props; ac->charger_desc.num_properties = ARRAY_SIZE(ac_props); ac->charger_desc.get_property = get_ac_property; - ac->charger = power_supply_register(&ac->device->dev, + ac->charger = power_supply_register(&pdev->dev, &ac->charger_desc, &psy_cfg); if (IS_ERR(ac->charger)) { result = PTR_ERR(ac->charger); @@ -251,7 +245,7 @@ static int acpi_ac_add(struct acpi_device *device) register_acpi_notifier(&ac->battery_nb); result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY, - acpi_ac_notify, device); + acpi_ac_notify, &pdev->dev); if (result) goto err_unregister; @@ -269,7 +263,7 @@ static int acpi_ac_add(struct acpi_device *device) #ifdef CONFIG_PM_SLEEP static int acpi_ac_resume(struct device *dev) { - struct acpi_ac *ac = acpi_driver_data(to_acpi_device(dev)); + struct acpi_ac *ac = dev_get_drvdata(dev); unsigned int old_state; old_state = ac->state; @@ -284,11 +278,12 @@ static int acpi_ac_resume(struct device *dev) #define acpi_ac_resume NULL #endif -static void acpi_ac_remove(struct acpi_device *device) +static void acpi_ac_remove(struct platform_device *pdev) { - struct acpi_ac *ac = acpi_driver_data(device); + struct acpi_ac *ac = platform_get_drvdata(pdev); - acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY, + acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev), + ACPI_ALL_NOTIFY, acpi_ac_notify); power_supply_unregister(ac->charger); unregister_acpi_notifier(&ac->battery_nb); @@ -296,6 +291,16 @@ static void acpi_ac_remove(struct acpi_device *device) kfree(ac); } +static struct platform_driver acpi_ac_driver = { + .probe = acpi_ac_probe, + .remove_new = acpi_ac_remove, + .driver = { + .name = "ac", + .acpi_match_table = ac_device_ids, + .pm = &acpi_ac_pm, + }, +}; + static int __init acpi_ac_init(void) { int result; @@ -308,7 +313,7 @@ static int __init acpi_ac_init(void) dmi_check_system(ac_dmi_table); - result = acpi_bus_register_driver(&acpi_ac_driver); + result = platform_driver_register(&acpi_ac_driver); if (result < 0) return -ENODEV; @@ -317,7 +322,7 @@ static int __init acpi_ac_init(void) static void __exit acpi_ac_exit(void) { - acpi_bus_unregister_driver(&acpi_ac_driver); + platform_driver_unregister(&acpi_ac_driver); } module_init(acpi_ac_init); module_exit(acpi_ac_exit); From patchwork Wed Oct 11 08:33:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wilczynski, Michal" X-Patchwork-Id: 13416886 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) (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 39F5C199CD for ; Wed, 11 Oct 2023 08:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hyuBPz+u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697013250; x=1728549250; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IQEJb1Lz3l1aI2jv3xJq6wSzHRp1z4wipFCT9nVMLO4=; b=hyuBPz+uU/MQwnCwXXXfnaQ1cX1KmiaiOyFTnfeROY+zuKEZoKO37wwu sn77yKzzNBV26Ih4q3j87NotN9bU/RoJ9ZzoFyMsBSm1FOzF6DFdV62nc sB7D8WypSFH/raz3kFmU2VnuXxXH5vcu22g0kzvDN3Id76NQ5tHiiuGlQ 5eJsdJyilVpoXOx/5JlxO3JkZE/li4Cxj29m9/9Fedp4l4iT/yt+HbTj7 ESRooswjdQElZ1H00bdehnmfjZogHb+uM3sD9AI5ACeOpVCFNrOrzwZ7W j/XoFj4YjmfUNNseg3EF4qGwDOk8EKtbKlA8R6epGbhuxLRXXbONn2Ij/ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="388480225" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="388480225" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:34:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="897548215" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="897548215" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:32:23 -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 Subject: [PATCH v3 4/6] ACPI: AC: Rename ACPI device from device to adev Date: Wed, 11 Oct 2023 11:33:32 +0300 Message-ID: <20231011083334.3987477-5-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231011083334.3987477-1-michal.wilczynski@intel.com> References: <20231011083334.3987477-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since transformation from ACPI driver to platform driver there are two devices on which the driver operates - ACPI device and platform device. For the sake of reader this calls for the distinction in their naming, to avoid confusion. Rename device to adev, as corresponding platform device is called pdev. Signed-off-by: Michal Wilczynski --- drivers/acpi/ac.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c index 1dd4919be7ac..2618a7ccc11c 100644 --- a/drivers/acpi/ac.c +++ b/drivers/acpi/ac.c @@ -121,11 +121,11 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) { struct device *dev = data; struct acpi_ac *ac = dev_get_drvdata(dev); - struct acpi_device *device = ACPI_COMPANION(dev); + struct acpi_device *adev = ACPI_COMPANION(dev); switch (event) { default: - acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", + acpi_handle_debug(adev->handle, "Unsupported event [0x%x]\n", event); fallthrough; case ACPI_AC_NOTIFY_STATUS: @@ -142,11 +142,11 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) msleep(ac_sleep_before_get_state_ms); acpi_ac_get_state(ac); - acpi_bus_generate_netlink_event(device->pnp.device_class, + acpi_bus_generate_netlink_event(adev->pnp.device_class, dev_name(dev), event, ac->state); - acpi_notifier_call_chain(device, event, ac->state); + acpi_notifier_call_chain(adev, event, ac->state); kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE); } } @@ -205,7 +205,7 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = { static int acpi_ac_probe(struct platform_device *pdev) { - struct acpi_device *device = ACPI_COMPANION(&pdev->dev); + struct acpi_device *adev = ACPI_COMPANION(&pdev->dev); struct power_supply_config psy_cfg = {}; struct acpi_ac *ac; int result; @@ -214,9 +214,9 @@ static int acpi_ac_probe(struct platform_device *pdev) if (!ac) return -ENOMEM; - ac->device = device; - strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME); - strcpy(acpi_device_class(device), ACPI_AC_CLASS); + ac->device = adev; + strcpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME); + strcpy(acpi_device_class(adev), ACPI_AC_CLASS); platform_set_drvdata(pdev, ac); @@ -226,7 +226,7 @@ static int acpi_ac_probe(struct platform_device *pdev) psy_cfg.drv_data = ac; - ac->charger_desc.name = acpi_device_bid(device); + ac->charger_desc.name = acpi_device_bid(adev); ac->charger_desc.type = POWER_SUPPLY_TYPE_MAINS; ac->charger_desc.properties = ac_props; ac->charger_desc.num_properties = ARRAY_SIZE(ac_props); @@ -238,13 +238,13 @@ static int acpi_ac_probe(struct platform_device *pdev) goto err_release_ac; } - pr_info("%s [%s] (%s-line)\n", acpi_device_name(device), - acpi_device_bid(device), str_on_off(ac->state)); + pr_info("%s [%s] (%s-line)\n", acpi_device_name(adev), + acpi_device_bid(adev), str_on_off(ac->state)); ac->battery_nb.notifier_call = acpi_ac_battery_notify; register_acpi_notifier(&ac->battery_nb); - result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY, + result = acpi_dev_install_notify_handler(adev, ACPI_ALL_NOTIFY, acpi_ac_notify, &pdev->dev); if (result) goto err_unregister; From patchwork Wed Oct 11 08:33:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wilczynski, Michal" X-Patchwork-Id: 13416887 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) (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 8B264199CD for ; Wed, 11 Oct 2023 08:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="LZpkix2j" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697013255; x=1728549255; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KeBW7OgXXmtrM6WG1jnUdssaNB2R2i0a8/3uS3pL1AU=; b=LZpkix2jlDW3Xw0LjB9jvU8dxRfJ24qRc46U1OcTFOCyyuucY+Trz2gu 4SjdAIrz0lPRg7xab/3H9XUHyxH3G7Ws23pqfJVmAHKGe6xvP6zw9BG68 u6JRw8tHY7f+MCTcQ5gqmjLRnt3R3/wpv3Yq7/8HeG89bOyjdSisRB8ds KgrXMcAQZjsPLRb9KYs28oixvsxn95UBl+AE+d1qMxA6Y680oMx+K2P1P WXw3vy9Y3+AeT5HqmLrUxi07tuRRaMNTuLGRRSAv7ToEPNYBkIo8F3eqP Nmrz76osH/iMbhBpOUiFMdqo977RF28rQmJcG2TTxzKEAx6avE1rwztCm A==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="388480264" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="388480264" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:34:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="897548222" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="897548222" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:32:26 -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 v3 5/6] ACPI: NFIT: Replace acpi_driver with platform_driver Date: Wed, 11 Oct 2023 11:33:33 +0300 Message-ID: <20231011083334.3987477-6-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231011083334.3987477-1-michal.wilczynski@intel.com> References: <20231011083334.3987477-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 NFIT driver uses struct acpi_driver incorrectly to register itself. This is wrong as the instances of the ACPI devices are not meant to be literal devices, they're supposed to describe ACPI entry of a particular device. Use platform_driver instead of acpi_driver. In relevant places call platform devices instances pdev to make a distinction with ACPI devices instances. NFIT driver uses devm_*() family of functions extensively. This change has no impact on correct functioning of the whole devm_*() family of functions, since the lifecycle of the device stays the same. It is still being created during the enumeration, and destroyed on platform device removal. Suggested-by: Rafael J. Wysocki Signed-off-by: Michal Wilczynski --- drivers/acpi/nfit/core.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index 3826f49d481b..6b9d10cae92c 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include "intel.h" @@ -98,7 +99,7 @@ static struct acpi_device *to_acpi_dev(struct acpi_nfit_desc *acpi_desc) || strcmp(nd_desc->provider_name, "ACPI.NFIT") != 0) return NULL; - return to_acpi_device(acpi_desc->dev); + return ACPI_COMPANION(acpi_desc->dev); } static int xlat_bus_status(void *buf, unsigned int cmd, u32 status) @@ -3284,11 +3285,11 @@ static void acpi_nfit_put_table(void *table) static void acpi_nfit_notify(acpi_handle handle, u32 event, void *data) { - struct acpi_device *adev = data; + struct device *dev = data; - device_lock(&adev->dev); - __acpi_nfit_notify(&adev->dev, handle, event); - device_unlock(&adev->dev); + device_lock(dev); + __acpi_nfit_notify(dev, handle, event); + device_unlock(dev); } static void acpi_nfit_remove_notify_handler(void *data) @@ -3329,11 +3330,12 @@ void acpi_nfit_shutdown(void *data) } EXPORT_SYMBOL_GPL(acpi_nfit_shutdown); -static int acpi_nfit_add(struct acpi_device *adev) +static int acpi_nfit_probe(struct platform_device *pdev) { struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_nfit_desc *acpi_desc; - struct device *dev = &adev->dev; + struct device *dev = &pdev->dev; + struct acpi_device *adev = ACPI_COMPANION(dev); struct acpi_table_header *tbl; acpi_status status = AE_OK; acpi_size sz; @@ -3360,7 +3362,7 @@ static int acpi_nfit_add(struct acpi_device *adev) acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); if (!acpi_desc) return -ENOMEM; - acpi_nfit_desc_init(acpi_desc, &adev->dev); + acpi_nfit_desc_init(acpi_desc, dev); /* Save the acpi header for exporting the revision via sysfs */ acpi_desc->acpi_header = *tbl; @@ -3391,7 +3393,7 @@ static int acpi_nfit_add(struct acpi_device *adev) return rc; rc = acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY, - acpi_nfit_notify, adev); + acpi_nfit_notify, dev); if (rc) return rc; @@ -3475,11 +3477,11 @@ static const struct acpi_device_id acpi_nfit_ids[] = { }; MODULE_DEVICE_TABLE(acpi, acpi_nfit_ids); -static struct acpi_driver acpi_nfit_driver = { - .name = KBUILD_MODNAME, - .ids = acpi_nfit_ids, - .ops = { - .add = acpi_nfit_add, +static struct platform_driver acpi_nfit_driver = { + .probe = acpi_nfit_probe, + .driver = { + .name = KBUILD_MODNAME, + .acpi_match_table = acpi_nfit_ids, }, }; @@ -3517,7 +3519,7 @@ static __init int nfit_init(void) return -ENOMEM; nfit_mce_register(); - ret = acpi_bus_register_driver(&acpi_nfit_driver); + ret = platform_driver_register(&acpi_nfit_driver); if (ret) { nfit_mce_unregister(); destroy_workqueue(nfit_wq); @@ -3530,7 +3532,7 @@ static __init int nfit_init(void) static __exit void nfit_exit(void) { nfit_mce_unregister(); - acpi_bus_unregister_driver(&acpi_nfit_driver); + platform_driver_unregister(&acpi_nfit_driver); destroy_workqueue(nfit_wq); WARN_ON(!list_empty(&acpi_descs)); } From patchwork Wed Oct 11 08:33:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wilczynski, Michal" X-Patchwork-Id: 13416888 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) (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 EB8B81A5AD for ; Wed, 11 Oct 2023 08:34:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Xmf/ZlVG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697013257; x=1728549257; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+gMT7Bs4QZ3pqRHjQbkVcqijwQt7TCCPLlHrN6GVa+4=; b=Xmf/ZlVGQmk/0RggXtdoEM1uiX5NxnDCSlkRMYVJ+WI61+LOhXsClzhG HkTpC80Fh695AENSiozl4qtnm/bW6ZX64Sx/T+LxjXk3FR+GhgUf+52Dk mBFb++xxnpGTi1leg8aqttGPA8FR8Lopl6b30g9wyQj8tkLMaAaEpVN1Y Q9KFyYq1BHjWRoFy0mkvYbCGoyuWzZStC1OHkMIwiiURrJB4NllBHwTQn 8qMGC4NKN8imVwy+oafCGaR65IQQsqqDZopQXWBYzDckrS57hfUgzh38v LJAncZva8mRufNpNgMHSGJhGlPne5tNRxvsWwRnynP0TGTL11VLvHq/9C g==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="388480282" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="388480282" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:34:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="897548228" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="897548228" Received: from powerlab.fi.intel.com ([10.237.71.25]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:32:29 -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 , Andy Shevchenko Subject: [PATCH v3 6/6] ACPI: NFIT: Remove redundant call to to_acpi_dev() Date: Wed, 11 Oct 2023 11:33:34 +0300 Message-ID: <20231011083334.3987477-7-michal.wilczynski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231011083334.3987477-1-michal.wilczynski@intel.com> References: <20231011083334.3987477-1-michal.wilczynski@intel.com> Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In acpi_nfit_ctl() ACPI handle is extracted using to_acpi_dev() function and accessing handle field in ACPI device. After transformation from ACPI driver to platform driver this is not optimal anymore. To get a handle it's enough to just use ACPI_HANDLE() macro to extract the handle. Suggested-by: Andy Shevchenko Signed-off-by: Michal Wilczynski --- drivers/acpi/nfit/core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index 6b9d10cae92c..402bb56d4163 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -475,8 +475,6 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, guid = to_nfit_uuid(nfit_mem->family); handle = adev->handle; } else { - struct acpi_device *adev = to_acpi_dev(acpi_desc); - cmd_name = nvdimm_bus_cmd_name(cmd); cmd_mask = nd_desc->cmd_mask; if (cmd == ND_CMD_CALL && call_pkg->nd_family) { @@ -493,7 +491,7 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, guid = to_nfit_uuid(NFIT_DEV_BUS); } desc = nd_cmd_bus_desc(cmd); - handle = adev->handle; + handle = ACPI_HANDLE(dev); dimm_name = "bus"; }