From: "Derek J. Clark" <derekjohn.clark@gmail.com>
To: "Rong Zhang" <i@rong.moe>,
"Mark Pearson" <mpearson-lenovo@squebb.ca>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Armin Wolf" <W_Armin@gmx.de>
Cc: Charles <hanker007@gmail.com>,
Navon John Lukose <navonjohnlukose@gmail.com>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 03/12] platform/x86: lenovo-wmi-capdata: Only allocate sub-master info when necessary
Date: Fri, 09 Oct 2026 08:15:46 -0700 [thread overview]
Message-ID: <807F11B7-33B6-454F-B550-F516E974703B@gmail.com> (raw)
In-Reply-To: <20261009-lwmi-wmi-new-api-v2-3-402828382679@rong.moe>
On October 9, 2026 5:53:45 AM PDT, Rong Zhang <i@rong.moe> wrote:
>When capdata00 declares no fan test support, there is no need to
>allocate sub-master info as it's basically unused except for the
>priv->sub_master->sub_component_list == ERR_PTR(-ENODEV) placeholder.
>
>Therefore, only allocate priv->sub_master when necessary, otherwise its
>absence implies the absence of sub-component. With that,
>PTR_ERR(sub_component_list) == -ENODEV is repurposed for the following
>changes to represent stubbed sub-component.
>
>Signed-off-by: Rong Zhang <i@rong.moe>
>---
> drivers/platform/x86/lenovo/wmi-capdata.c | 36 ++++++++++++++++++-------------
> 1 file changed, 21 insertions(+), 15 deletions(-)
>
>diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x86/lenovo/wmi-capdata.c
>index 58787da959b4..3a823aee608a 100644
>--- a/drivers/platform/x86/lenovo/wmi-capdata.c
>+++ b/drivers/platform/x86/lenovo/wmi-capdata.c
>@@ -101,9 +101,11 @@ struct lwmi_cd_priv {
> struct lwmi_cd_sub_master_priv {
> struct device *master_dev;
> cd_list_cb_t master_cb;
>- struct cd_list *sub_component_list; /* ERR_PTR(-ENODEV) implies no sub-component. */
>+ struct cd_list *sub_component_list; /* ERR_PTR(-ENODEV) implies stubbed
>+ * sub-component.
>+ */
Hi Rong,
Hitting the column limit here looks ugly and harms readability IMO. Perhaps we could rename the variable (sc_list?) or be less explicit about the full error signature?
- Derek
> bool registered; /* Has the sub-master been registered? */
>- } *sub_master;
>+ } *sub_master; /* NULL impLnlies no sub-component. */
> };
>
> struct cd_list {
>@@ -258,6 +260,12 @@ static int lwmi_cd_component_bind(struct device *cd_dev,
> case LENOVO_CAPABILITY_DATA_00:
> binder->cd00_list = priv->list;
>
>+ /* Missing sub-master info implies missing sub-component. */
>+ if (!priv->sub_master) {
>+ binder->cd_fan_list_cb(om_dev, NULL);
>+ break;
>+ }
>+
> priv->sub_master->master_dev = om_dev;
> priv->sub_master->master_cb = binder->cd_fan_list_cb;
> lwmi_cd_call_master_cb(priv);
>@@ -288,13 +296,9 @@ static void lwmi_cd_component_unbind(struct device *cd_dev,
> {
> struct lwmi_cd_priv *priv = dev_get_drvdata(cd_dev);
>
>- switch (priv->list->type) {
>- case LENOVO_CAPABILITY_DATA_00:
>+ if (priv->sub_master) {
> priv->sub_master->master_dev = NULL;
> priv->sub_master->master_cb = NULL;
>- return;
>- default:
>- return;
> }
> }
>
>@@ -369,17 +373,19 @@ static int lwmi_cd_sub_master_add(struct lwmi_cd_priv *priv,
> struct component_match *master_match = NULL;
> int ret;
>
>+ /*
>+ * If the sub-master has no sub-component, there is no need to allocate
>+ * or register the sub-master. The master callback will be called with
>+ * NULL on master <-> sub-master bind to inform the master about the
>+ * absence of sub-component.
>+ */
>+ if (sub_component_type == CD_TYPE_NONE)
>+ return 0;
>+
> priv->sub_master = devm_kzalloc(&priv->wdev->dev, sizeof(*priv->sub_master), GFP_KERNEL);
> if (!priv->sub_master)
> return -ENOMEM;
>
>- if (sub_component_type == CD_TYPE_NONE) {
>- /* The master callback will be called with NULL on bind. */
>- priv->sub_master->sub_component_list = ERR_PTR(-ENODEV);
>- priv->sub_master->registered = false;
>- return 0;
>- }
>-
> /*
> * lwmi_cd_match() needs a pointer to enum lwmi_cd_type, but on-stack
> * data cannot be used here. Steal one from lwmi_cd_table.
>@@ -404,7 +410,7 @@ static int lwmi_cd_sub_master_add(struct lwmi_cd_priv *priv,
> */
> static void lwmi_cd_sub_master_del(struct lwmi_cd_priv *priv)
> {
>- if (!priv->sub_master->registered)
>+ if (!priv->sub_master || !priv->sub_master->registered)
> return;
>
> component_master_del(&priv->wdev->dev, &lwmi_cd_sub_master_ops);
>
next prev parent reply other threads:[~2026-10-09 15:15 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 12:53 [PATCH v2 00/12] platform/x86: lenovo-wmi-{other,capdata,helpers}: Improve robustness on faulty firmware Rong Zhang
2026-10-09 12:53 ` [PATCH v2 01/12] platform/wmi: Introduce wmidev_exists() Rong Zhang
2026-10-09 20:25 ` Mark Pearson
2026-10-09 12:53 ` [PATCH v2 02/12] platform/x86: lenovo-wmi-capdata: Do not stop the AC notifier chain on error Rong Zhang
2026-10-09 12:53 ` [PATCH v2 03/12] platform/x86: lenovo-wmi-capdata: Only allocate sub-master info when necessary Rong Zhang
2026-10-09 15:15 ` Derek J. Clark [this message]
2026-10-09 15:45 ` Rong Zhang
2026-10-09 12:53 ` [PATCH v2 04/12] platform/x86: lenovo-wmi-capdata: Store a pointer to component info Rong Zhang
2026-10-09 12:53 ` [PATCH v2 05/12] platform/x86: lenovo-wmi-capdata: Defer mutex initialization Rong Zhang
2026-10-09 12:53 ` [PATCH v2 06/12] platform/x86: lenovo-wmi-{capdata,other}: Only allocate capdata list when necessary Rong Zhang
2026-10-09 12:53 ` [PATCH v2 07/12] platform/x86: lenovo-wmi-capdata: Adopt new WMI API Rong Zhang
2026-10-10 1:16 ` Armin Wolf
2026-10-10 1:51 ` Rong Zhang
2026-10-09 12:53 ` [PATCH v2 08/12] platform/x86: lenovo-wmi-capdata: Register component even on WMI error Rong Zhang
2026-10-09 12:53 ` [PATCH v2 09/12] platform/x86: lenovo-wmi-capdata: Detect stubbed capdata device Rong Zhang
2026-10-09 12:53 ` [PATCH v2 10/12] platform/x86: lenovo-wmi-capdata: Do not match missing components Rong Zhang
2026-10-09 12:53 ` [PATCH v2 11/12] platform/x86: lenovo-wmi-helpers: Adopt new WMI API Rong Zhang
2026-10-10 1:19 ` Armin Wolf
2026-10-09 12:53 ` [PATCH v2 12/12] MAINTAINERS: Add myself as a LENOVO drivers co-maintainer Rong Zhang
2026-10-09 20:26 ` Mark Pearson
2026-10-09 23:01 ` [PATCH v2 00/12] platform/x86: lenovo-wmi-{other,capdata,helpers}: Improve robustness on faulty firmware Derek J. Clark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=807F11B7-33B6-454F-B550-F516E974703B@gmail.com \
--to=derekjohn.clark@gmail.com \
--cc=W_Armin@gmx.de \
--cc=hanker007@gmail.com \
--cc=hansg@kernel.org \
--cc=i@rong.moe \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mpearson-lenovo@squebb.ca \
--cc=navonjohnlukose@gmail.com \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®