public inbox for patches@lists.linux.dev
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Sasha Levin" <sashal@kernel.org>,
	kenneth.t.chan@gmail.com, hansg@kernel.org,
	platform-driver-x86@vger.kernel.org
Subject: [PATCH AUTOSEL 6.18-5.15] platform/x86: panasonic-laptop: Fix sysfs group leak in error path
Date: Mon,  9 Feb 2026 07:26:46 -0500	[thread overview]
Message-ID: <20260209122714.1037915-7-sashal@kernel.org> (raw)
In-Reply-To: <20260209122714.1037915-1-sashal@kernel.org>

From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

[ Upstream commit 43b0b7eff4b3fb684f257d5a24376782e9663465 ]

The acpi_pcc_hotkey_add() error path leaks sysfs group pcc_attr_group
if platform_device_register_simple() fails for the "panasonic" platform
device.

Address this by making it call sysfs_remove_group() in that case for
the group in question.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/3398370.44csPzL39Z@rafael.j.wysocki
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

## Analysis

### Commit Message Analysis

The commit message is clear and precise: it identifies a **sysfs group
leak** in the error path of `acpi_pcc_hotkey_add()`. Specifically, when
`platform_device_register_simple()` fails, the code jumps to
`out_backlight`, which skips the `sysfs_remove_group()` cleanup for
`pcc_attr_group` that was successfully created earlier. This is a
classic resource leak on an error path.

The author is Rafael J. Wysocki, a highly respected kernel maintainer
(PM subsystem, ACPI), and the patch is reviewed by Ilpo Järvinen (Intel
platform/x86 maintainer). Both are strong trust indicators.

### Code Change Analysis

The fix is extremely small and surgical — exactly 3 lines changed:

1. **Changed `goto out_backlight` to `goto out_sysfs`** — When
   `platform_device_register_simple()` fails, instead of jumping past
   the sysfs cleanup, it now jumps to a new label that properly removes
   the sysfs group first.

2. **Added new `out_sysfs:` label** with
   `sysfs_remove_group(&device->dev.kobj, &pcc_attr_group)` — This
   ensures the sysfs group created by `sysfs_create_group()` a few lines
   earlier is properly cleaned up.

The error path ordering is now correct:
- `out_platform` → unregister platform device
- `out_sysfs` → remove sysfs group (NEW)
- `out_backlight` → unregister backlight
- `out_input` → unregister input device
- `out_sinf` → free sinf
- `out_hotkey` → free pcc

This follows the standard reverse-order cleanup pattern in Linux kernel
drivers.

### Bug Classification

This is a **resource leak fix** on an error path. The leaked sysfs group
means:
- Sysfs entries remain dangling after driver probe failure
- Memory associated with the sysfs group attributes is leaked
- Could cause issues if the driver is retried or another driver tries to
  use the same sysfs paths

### Scope and Risk Assessment

- **Lines changed**: ~3 effective lines (one goto target change, two new
  lines for the label and cleanup call)
- **Files touched**: 1 (drivers/platform/x86/panasonic-laptop.c)
- **Risk**: Extremely low — this only affects the error path when
  `platform_device_register_simple()` fails. It cannot affect the normal
  (successful) code path at all.
- **Correctness**: Obviously correct — it follows the standard cleanup
  ordering pattern used everywhere in the kernel.

### Stable Kernel Criteria

1. **Obviously correct and tested**: Yes — trivial fix, reviewed by
   subsystem maintainer
2. **Fixes a real bug**: Yes — resource leak in error path
3. **Important issue**: Moderate — resource leak in driver probe error
   path. While not a crash, it's a correctness issue
4. **Small and contained**: Yes — 3 lines in one file
5. **No new features**: Correct — pure bug fix
6. **Clean backport**: The code should be straightforward to backport as
   this driver has been stable for a long time

### User Impact

This affects Panasonic laptop users. While the error path is not
frequently hit (it requires `platform_device_register_simple()` to fail,
which is uncommon), when it does occur, resources are leaked. The fix is
zero-risk to the normal path and trivially correct.

### Conclusion

This is a textbook stable-worthy fix: a small, obvious resource leak fix
in an error path, written by a top kernel maintainer, reviewed by the
subsystem maintainer, with zero risk of regression. It meets all stable
kernel criteria.

**YES**

 drivers/platform/x86/panasonic-laptop.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index 255317e6fec88..937f1a5b78edf 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -1089,7 +1089,7 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
 			PLATFORM_DEVID_NONE, NULL, 0);
 		if (IS_ERR(pcc->platform)) {
 			result = PTR_ERR(pcc->platform);
-			goto out_backlight;
+			goto out_sysfs;
 		}
 		result = device_create_file(&pcc->platform->dev,
 			&dev_attr_cdpower);
@@ -1105,6 +1105,8 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
 
 out_platform:
 	platform_device_unregister(pcc->platform);
+out_sysfs:
+	sysfs_remove_group(&device->dev.kobj, &pcc_attr_group);
 out_backlight:
 	backlight_device_unregister(pcc->backlight);
 out_input:
-- 
2.51.0


  parent reply	other threads:[~2026-02-09 12:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-09 12:26 [PATCH AUTOSEL 6.18-6.12] drm/amd/display: extend delta clamping logic to CM3 LUT helper Sasha Levin
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18] io_uring/fdinfo: be a bit nicer when looping a lot of SQEs/CQEs Sasha Levin
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18-6.12] ALSA: hda/realtek: Enable headset mic for Acer Nitro 5 Sasha Levin
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18-5.10] platform/x86: classmate-laptop: Add missing NULL pointer checks Sasha Levin
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18-6.6] platform/x86/amd/pmc: Add quirk for MECHREVO Wujie 15X Pro Sasha Levin
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18-6.6] ASoC: amd: yc: Add quirk for HP 200 G2a 16 Sasha Levin
2026-02-09 12:26 ` Sasha Levin [this message]
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18-5.15] ASoC: fsl_xcvr: fix missing lock in fsl_xcvr_mode_put() Sasha Levin
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18-6.12] tracing/dma: Cap dma_map_sg tracepoint arrays to prevent buffer overflow Sasha Levin
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18-5.10] drm/tegra: hdmi: sor: Fix error: variable ‘j’ set but not used Sasha Levin
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18-6.1] ASoC: Intel: sof_es8336: Add DMI quirk for Huawei BOD-WXX9 Sasha Levin
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18] ASoC: sof_sdw: Add a quirk for Lenovo laptop using sidecar amps with cs42l43 Sasha Levin
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18-5.10] gpiolib: acpi: Fix gpio count with string references Sasha Levin
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18-6.6] ASoC: cs42l43: Correct handling of 3-pole jack load detection Sasha Levin
2026-02-09 12:26 ` [PATCH AUTOSEL 6.18-6.12] drm/amd/display: remove assert around dpp_base replacement Sasha Levin

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=20260209122714.1037915-7-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=kenneth.t.chan@gmail.com \
    --cc=patches@lists.linux.dev \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=stable@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