From nobody Thu Oct 2 15:34:42 2025 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32D3C3101D8 for ; Thu, 2 Oct 2025 11:34:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759404857; cv=none; b=DpHSaqGyOZ0sfOMigFL7oQK1tq1OBx+0A3By2RnhpDJM1I16+3oPLPksR8QRbvhluwD6Z43WGyNZ8FopITjSr4P8T/CwM6Sez0emgPdlwBuqFtq+xlDLU8WpE+pXvf8GMBltMFWNeoJCTncP9RygLqvpfaulFIljPj2+Eu00dXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759404857; c=relaxed/simple; bh=jGzuARMYnBvr8zehQalwEPWJlbunoDDp9WM0aTu/GGg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZG97QQisnG027foXOS1J7V7DIGF9QF9hXM7iP+Az61B4HJdNiPkPDvwowEp1kGNk9KvXR3pi1HxGxwUsB2My7z0lomE1abhhRHXzf5uRMe7wXMi/kBFQuLqFrrHLVNOVTDHcMhzcUozng2DS2Rle/ktLw4cCk7Dia5JwlG1D+C0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--srosek.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2K1FyOdl; arc=none smtp.client-ip=209.85.208.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--srosek.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2K1FyOdl" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-6349af0e766so1251678a12.3 for ; Thu, 02 Oct 2025 04:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759404852; x=1760009652; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Z336Gm+cXT/UC4w0tslyQ8BibQkKtAXFk7vuVFzlfeA=; b=2K1FyOdlo3UIrximlpqg2XmXJQRzmYOWpD/OWzCyUWyTJFxJVp1OLslekisNKc5tXk zTMUBYMad/YIL5I76baRdwLYqFePRYLcNYu7p4JftUTZIBUZQtSgXuly1vAfTe345wvL kgi2eSbDKGMeW6ZZ2Vl8unvLfuQMcI+lcEbVr72acLCdpKMABUfqgzyNNmXZn3Ji95Sv 8YPCtuObD0ltufuqlAChcOMP0I/nCWFKGC85PSU8oud8hqQFqh/xY3B3yuYPZeVULd2K EOthOqiCaSd27WT1BRWfrJ6lv4pguyMAOwW1NfWcxHDd0TQWlX1b+1rJx6HpPeXzzU9u esYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759404852; x=1760009652; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Z336Gm+cXT/UC4w0tslyQ8BibQkKtAXFk7vuVFzlfeA=; b=UG8rS6BcAL2gZOSfXSgzskgenUoTMo1BMyzyzuBt+1LdK3q9ak5P4dywsUEhld1CWo AyjZmjFWa9POXqS2Az09nOGZwIdrP/gAl8PSxwf8Vmwr+iV9k71CDmLVDq9kPtGr88WN n+WIR48+RPY9flSgHZSEHt9QEB8xZiyAOjXIVwBzMJp1Gm4tGYPWHwSi5JmeIpELisEJ tgEvH+Ctkz0CVoPvV0wqVZGqv9xjeOVORyWhF7DYe7ft3ehNRuDsY3FzOmwWxp2FIxER Pe9cf/FRqWT+oLkrLg7Vdxx9PhDmxcd3JeTHtAmRFvJA//ibb9BbvFgAyBM6DBoz291o YMYQ== X-Forwarded-Encrypted: i=1; AJvYcCWIuY89edwCSAhZ9qMdFFMX32RDnjbzkUgH8o7MmcSqIBfAOtRGILXqC5/lYDfyWPCuWimRe2G4Exh3qBY=@vger.kernel.org X-Gm-Message-State: AOJu0Ywb49zw0EIaI96mqDRq22OhTkwxqCCapoAYWAcmWSVmmb9xSa5F DxzUvBZsyIZMtASXe3+bRgMsmMwoBjuBRqjh+qMyv+sEPFnmDoJFbMyHv43NOIWRE8vhRR149oA plNGkDg== X-Google-Smtp-Source: AGHT+IFAVHO3UURkms4Px09NV4CiDY2z3xTeYtmA76T6c6XpkpIyxX6hgNSwOsfI7DB7ygO5B6MwLch1EDU= X-Received: from edyb2.prod.google.com ([2002:aa7:df82:0:b0:634:5269:e012]) (user=srosek job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:354f:b0:634:b651:48b9 with SMTP id 4fb4d7f45d1cf-63678bce60amr7133335a12.4.1759404852085; Thu, 02 Oct 2025 04:34:12 -0700 (PDT) Date: Thu, 2 Oct 2025 11:34:03 +0000 In-Reply-To: <20251002113404.3117429-1-srosek@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251002113404.3117429-1-srosek@google.com> X-Mailer: git-send-email 2.51.0.618.g983fd99d29-goog Message-ID: <20251002113404.3117429-6-srosek@google.com> Subject: [PATCH v3 5/6] ACPI: platform: Add macro for acpi platform driver From: Slawomir Rosek To: "Rafael J . Wysocki" , Alex Hung , Hans de Goede , Ilpo Jarvinen , AceLan Kao , Daniel Lezcano Cc: Greg Kroah-Hartman , Zhang Rui , Srinivas Pandruvada , Tomasz Nowicki , Stanislaw Kardach , Michal Krawczyk , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, Slawomir Rosek Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce module_acpi_platform_driver() macro to simplify dynamic enumeration of ACPI device objects on the platform bus by loadable modules. Move common code from the intel-hid and intel-vbtn drivers to the ACPI platform core. Signed-off-by: Slawomir Rosek --- drivers/acpi/acpi_platform.c | 27 +++++++++++++++++++++++++ drivers/platform/x86/intel/hid.c | 33 +++---------------------------- drivers/platform/x86/intel/vbtn.c | 30 +--------------------------- include/linux/platform_device.h | 17 ++++++++++++++++ 4 files changed, 48 insertions(+), 59 deletions(-) diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c index 48d15dd785f6..adf32ffa6be6 100644 --- a/drivers/acpi/acpi_platform.c +++ b/drivers/acpi/acpi_platform.c @@ -190,6 +190,33 @@ struct platform_device *acpi_create_platform_device(st= ruct acpi_device *adev, } EXPORT_SYMBOL_GPL(acpi_create_platform_device); =20 +static acpi_status +__acpi_platform_driver_register_cb(acpi_handle handle, u32 lvl, + void *context, void **rv) +{ + const struct acpi_device_id *ids =3D context; + struct acpi_device *dev =3D acpi_fetch_acpi_dev(handle); + + if (dev && acpi_match_device_ids(dev, ids) =3D=3D 0) + if (!IS_ERR_OR_NULL(acpi_create_platform_device(dev, NULL))) { + dev_info(&dev->dev, + "created platform device\n"); + } + + return AE_OK; +} + +int __acpi_platform_driver_register(struct platform_driver *drv, + struct module *owner) +{ + acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, + __acpi_platform_driver_register_cb, NULL, + (void *)drv->driver.acpi_match_table, NULL); + + return __platform_driver_register(drv, owner); +} +EXPORT_SYMBOL_GPL(__acpi_platform_driver_register); + void __init acpi_platform_init(void) { acpi_reconfig_notifier_register(&acpi_platform_notifier); diff --git a/drivers/platform/x86/intel/hid.c b/drivers/platform/x86/intel/= hid.c index f25a427cccda..37f990686446 100644 --- a/drivers/platform/x86/intel/hid.c +++ b/drivers/platform/x86/intel/hid.c @@ -775,34 +775,7 @@ static struct platform_driver intel_hid_pl_driver =3D { * * As a workaround until the ACPI core figures out how to handle * this corner case, manually ask the ACPI platform device code to - * claim the ACPI node. + * claim the ACPI node by using module_acpi_platform_driver() + * instead of the regular module_platform_driver(). */ -static acpi_status __init -check_acpi_dev(acpi_handle handle, u32 lvl, void *context, void **rv) -{ - const struct acpi_device_id *ids =3D context; - struct acpi_device *dev =3D acpi_fetch_acpi_dev(handle); - - if (dev && acpi_match_device_ids(dev, ids) =3D=3D 0) - if (!IS_ERR_OR_NULL(acpi_create_platform_device(dev, NULL))) - dev_info(&dev->dev, - "intel-hid: created platform device\n"); - - return AE_OK; -} - -static int __init intel_hid_init(void) -{ - acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, - ACPI_UINT32_MAX, check_acpi_dev, NULL, - (void *)intel_hid_ids, NULL); - - return platform_driver_register(&intel_hid_pl_driver); -} -module_init(intel_hid_init); - -static void __exit intel_hid_exit(void) -{ - platform_driver_unregister(&intel_hid_pl_driver); -} -module_exit(intel_hid_exit); +module_acpi_platform_driver(intel_hid_pl_driver); diff --git a/drivers/platform/x86/intel/vbtn.c b/drivers/platform/x86/intel= /vbtn.c index 232cd12e3c9f..42932479de35 100644 --- a/drivers/platform/x86/intel/vbtn.c +++ b/drivers/platform/x86/intel/vbtn.c @@ -390,32 +390,4 @@ static struct platform_driver intel_vbtn_pl_driver =3D= { .remove =3D intel_vbtn_remove, }; =20 -static acpi_status __init -check_acpi_dev(acpi_handle handle, u32 lvl, void *context, void **rv) -{ - const struct acpi_device_id *ids =3D context; - struct acpi_device *dev =3D acpi_fetch_acpi_dev(handle); - - if (dev && acpi_match_device_ids(dev, ids) =3D=3D 0) - if (!IS_ERR_OR_NULL(acpi_create_platform_device(dev, NULL))) - dev_info(&dev->dev, - "intel-vbtn: created platform device\n"); - - return AE_OK; -} - -static int __init intel_vbtn_init(void) -{ - acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, - ACPI_UINT32_MAX, check_acpi_dev, NULL, - (void *)intel_vbtn_ids, NULL); - - return platform_driver_register(&intel_vbtn_pl_driver); -} -module_init(intel_vbtn_init); - -static void __exit intel_vbtn_exit(void) -{ - platform_driver_unregister(&intel_vbtn_pl_driver); -} -module_exit(intel_vbtn_exit); +module_acpi_platform_driver(intel_vbtn_pl_driver); diff --git a/include/linux/platform_device.h b/include/linux/platform_devic= e.h index 074754c23d33..3b70b054d8a5 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -264,6 +264,14 @@ extern int __platform_driver_register(struct platform_= driver *, struct module *); extern void platform_driver_unregister(struct platform_driver *); =20 +/* + * use a macro to avoid include chaining to get THIS_MODULE + */ +#define acpi_platform_driver_register(drv) \ + __acpi_platform_driver_register(drv, THIS_MODULE) +extern int __acpi_platform_driver_register(struct platform_driver *, + struct module *); + /* non-hotpluggable platform devices may use this so that probe() and * its support may live in __init sections, conserving runtime memory. */ @@ -292,6 +300,15 @@ static inline void platform_set_drvdata(struct platfor= m_device *pdev, module_driver(__platform_driver, platform_driver_register, \ platform_driver_unregister) =20 +/* module_acpi_platform_driver() - Helper macro for drivers that don't do + * anything special in module init/exit. This eliminates a lot of + * boilerplate. Each module may only use this macro once, and + * calling it replaces module_init() and module_exit() + */ +#define module_acpi_platform_driver(__platform_driver) \ + module_driver(__platform_driver, acpi_platform_driver_register, \ + platform_driver_unregister) + /* builtin_platform_driver() - Helper macro for builtin drivers that * don't do anything special in driver init. This eliminates some * boilerplate. Each driver may only use this macro once, and --=20 2.51.0.618.g983fd99d29-goog