From nobody Tue Apr 7 04:33:30 2026 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (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 2C78339891E for ; Mon, 6 Apr 2026 20:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775506446; cv=none; b=OfGeWBI/sfaXSqcDwhxyE9U7F8qrlt2gIfGXKG8z6WWQQWNh9mGgjbsvycHfyDSda2AJS3amOwEVpcfZKE1NlDmY2K68EHir3i04U/5mzXlEqBGsVXgXr92P1vGggjGvEvasFXD0hLrP0i2uG9iwjdys/x6h6XlH7RbS7RG1evA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775506446; c=relaxed/simple; bh=WAyuXvHg+IDaHK96s8SFan2J1QbE5G5c5VzthemtNBg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s/5BUn2X/+mCnxU7ZOuNfJqmZrfdoTlgCxjtN7ncRAO/VUPUbBC+vPhGoxcf7F1nPDA7lgc1+zn/wXLCNg1J9McX2wSIgbusObeeO5b9a2sU9k1QewfdyVGnSqgq5Qs9tBXgwNBaAdblTwDHqP1HPFKkmQQR1gUEYAN5yz59zR8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PzF24vC+; arc=none smtp.client-ip=74.125.82.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PzF24vC+" Received: by mail-dl1-f54.google.com with SMTP id a92af1059eb24-12c0f979c16so560377c88.0 for ; Mon, 06 Apr 2026 13:14:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775506444; x=1776111244; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dtWSJAsPoNeIGexvUzam2g4A6bay7wxoWEXeu9FJabM=; b=PzF24vC+vYWCfIvwd9U5wFTsDs1cYnKBwsfqHYD8CQJxYnRujtA/UWbEY6j/WORXiO 5Pn0ohyRJsV/iVjnhAjQV7SoDg6kdBDSHcLOVud6oqRww154NsoS9e/m7rh6Uvstye0C 1M+vtCfikxA9hoK3xTo9Le/NckovI5c6m+Ya/RSI1lFzaF4BUZAWEEB+aUM1yOyltuPZ gREFYh+j0vbFMsxhEGDXGhn7t0e6ske20+y743qy9Mir7BKKEwHYHDTRE54sMyrHRv6i WO8b6woSfv6AO4guer3cW3FTBrRZyQGkW3cdbwsYyuqtEV/6tcJC/DpltJa7qExfZZ7f bHYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775506444; x=1776111244; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dtWSJAsPoNeIGexvUzam2g4A6bay7wxoWEXeu9FJabM=; b=S4VnkOEVTVbnkxiIj94hI5QEytM9wrkrhAYzWeYiwOc3pts4khwgZlSl8fSrbmgthQ 2A5Wup2dWv1XqskKI++ChyxAjrBiErz7tGFukQ6X3GY330lYy4oODHRzJ5GBYgf2lKBv wnofeGc4b105SSi43tE6oyzKaVkz7xpgT7828gLMJ0fPt63HWWzuAkR9sHZQneWo6okW pn+GSS1CRrVW5KdShZv4aVPU0WwgY592jWVy5q/4Kk8YOApucjs+vluu+YDIjYCVgt/V +IJFs7uPNHwflMcQkbnCpk+D1+cbfgxyIN+bmeBagTNZfcLGAmiGhHx6Dh/h/ajH57xR qpAg== X-Forwarded-Encrypted: i=1; AJvYcCVFZnc2B6mpwuIM+5OgyWnV13T/+wODD9wIRMZ4frbgMFDFRD1aSnoFpJlNTRjLahpBmdSpQvFOF2HoP6g=@vger.kernel.org X-Gm-Message-State: AOJu0YyueWlTbBmlUDyMCWUKwVBqz7+B3+ftFCTMdk2WHPlnqWRyha5F E3jQ909aawO8t+SpeEnRYn2Hzpq1Nnrjat6iBTj0TkHHdInquYYfaECe X-Gm-Gg: AeBDiet4ZRMwmKLbld7uB70vaCcRjfNtHL32h8R3MpcaTgTEV/lt1Q1OR18J1ascraL /IOf5ABsRnSVpswo2JuswvJ9lgdhPNzrmfuTGTprod2cggAfQ2i7zo/+EKc05uq9dFGpU7K6/kQ kULrhLpOvElalTMxSkkG6ArtxN6Q9ZJToV/kgzvd6g+qlrArePXDVsQs5hvCb5LZYw2FdUwUyOF A7weYMVEBQzxD5mz7fIAd+Fpm8rE/b0XlwA1l4JeOx9aexS7RhpTJ8ip7SDPzNn5rN6vZezVWzQ koOLgI89ipPzHg19AQtnBwB+y75nMKh6nb2GuscZVqORC+oEpB8yGnkpPNRHXgfjowIEySsopDP bHqy3o3x5PstpZtdwGBvqZ4LKws2NzPzOD3w0+EQlFwFqCfd1zJ9ilCxjRd21fYoEiFX29JOI4u Fu1NPS1vo2rMLNwtqojV6uu/X0vzucjVC5T2LZUfYOkqkLfdFT1o5znaNciw42NvJ8cYxkB0vyZ NAw X-Received: by 2002:a05:7022:112:b0:128:e6d0:d7c3 with SMTP id a92af1059eb24-12bfb73eec9mr6480840c88.20.1775506444250; Mon, 06 Apr 2026 13:14:04 -0700 (PDT) Received: from lappy (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12bed93f861sm17022333c88.0.2026.04.06.13.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Apr 2026 13:14:03 -0700 (PDT) From: "Derek J. Clark" To: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Hans de Goede Cc: Mark Pearson , Armin Wolf , Jonathan Corbet , Rong Zhang , Kurt Borja , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v8 02/16] platform/x86: lenovo-wmi-other: Balance IDA id allocation and free Date: Mon, 6 Apr 2026 20:13:46 +0000 Message-ID: <20260406201400.438221-3-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260406201400.438221-1-derekjohn.clark@gmail.com> References: <20260406201400.438221-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Rong Zhang Currently, the IDA id is only freed on wmi-other device removal or failure to create firmware-attributes device, kset, or attributes. It leaks IDA ids if the wmi-other device is bound multiple times, as the unbind callback never frees the previously allocated IDA id. Additionally, if the wmi-other device has failed to create a firmware-attributes device before it gets removed, the wmi-device removal callback double frees the same IDA id. These bugs were found by sashiko.dev [1]. Fix them by moving ida_free() into lwmi_om_fw_attr_remove() so it is balanced with ida_alloc() in lwmi_om_fw_attr_add(). With them fixed, properly set and utilize the validity of priv->ida_id to balance firmware-attributes registration and removal, without relying on propagating the registration error to the component framework, which is more reliable and aligns with the hwmon device registration and removal sequences. No functional change intended. Fixes: edc4b183b794 ("platform/x86: Add Lenovo Other Mode WMI Driver") Cc: stable@vger.kernel.org Link: https://sashiko.dev/#/patchset/20260331181208.421552-1-derekjohn.clar= k%40gmail.com [1] Signed-off-by: Rong Zhang --- drivers/platform/x86/lenovo/wmi-other.c | 34 +++++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86= /lenovo/wmi-other.c index 6040f45aa2b0..b47418df099f 100644 --- a/drivers/platform/x86/lenovo/wmi-other.c +++ b/drivers/platform/x86/lenovo/wmi-other.c @@ -957,17 +957,17 @@ static struct capdata01_attr_group cd01_attr_groups[]= =3D { /** * lwmi_om_fw_attr_add() - Register all firmware_attributes_class members * @priv: The Other Mode driver data. - * - * Return: Either 0, or an error code. */ -static int lwmi_om_fw_attr_add(struct lwmi_om_priv *priv) +static void lwmi_om_fw_attr_add(struct lwmi_om_priv *priv) { unsigned int i; int err; =20 priv->ida_id =3D ida_alloc(&lwmi_om_ida, GFP_KERNEL); - if (priv->ida_id < 0) - return priv->ida_id; + if (priv->ida_id < 0) { + err =3D priv->ida_id; + goto err; + } =20 priv->fw_attr_dev =3D device_create(&firmware_attributes_class, NULL, MKDEV(0, 0), NULL, "%s-%u", @@ -993,7 +993,7 @@ static int lwmi_om_fw_attr_add(struct lwmi_om_priv *pri= v) =20 cd01_attr_groups[i].tunable_attr->dev =3D &priv->wdev->dev; } - return 0; + return; =20 err_remove_groups: while (i--) @@ -1007,7 +1007,12 @@ static int lwmi_om_fw_attr_add(struct lwmi_om_priv *= priv) =20 err_free_ida: ida_free(&lwmi_om_ida, priv->ida_id); - return err; + +err: + priv->ida_id =3D -EIDRM; + + dev_warn(&priv->wdev->dev, + "failed to register firmware-attributes device: %d\n", err); } =20 /** @@ -1016,12 +1021,17 @@ static int lwmi_om_fw_attr_add(struct lwmi_om_priv = *priv) */ static void lwmi_om_fw_attr_remove(struct lwmi_om_priv *priv) { + if (priv->ida_id < 0) + return; + for (unsigned int i =3D 0; i < ARRAY_SIZE(cd01_attr_groups) - 1; i++) sysfs_remove_group(&priv->fw_attr_kset->kobj, cd01_attr_groups[i].attr_group); =20 kset_unregister(priv->fw_attr_kset); device_unregister(priv->fw_attr_dev); + ida_free(&lwmi_om_ida, priv->ida_id); + priv->ida_id =3D -EIDRM; } =20 /* =3D=3D=3D=3D=3D=3D=3D=3D Self (master: lenovo-wmi-other) =3D=3D=3D=3D= =3D=3D=3D=3D */ @@ -1063,7 +1073,9 @@ static int lwmi_om_master_bind(struct device *dev) =20 lwmi_om_fan_info_collect_cd00(priv); =20 - return lwmi_om_fw_attr_add(priv); + lwmi_om_fw_attr_add(priv); + + return 0; } =20 /** @@ -1115,13 +1127,7 @@ static int lwmi_other_probe(struct wmi_device *wdev,= const void *context) =20 static void lwmi_other_remove(struct wmi_device *wdev) { - struct lwmi_om_priv *priv =3D dev_get_drvdata(&wdev->dev); - component_master_del(&wdev->dev, &lwmi_om_master_ops); - - /* No IDA to free if the driver is never bound to its components. */ - if (priv->ida_id >=3D 0) - ida_free(&lwmi_om_ida, priv->ida_id); } =20 static const struct wmi_device_id lwmi_other_id_table[] =3D { --=20 2.53.0