From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 7C0D7372EE2 for ; Sat, 8 Aug 2026 21:45:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786225518; cv=none; b=C28Fkosy726u4FgL9MWGw+xlH8EIF5MmfHFsF50BLjvILR5DGyC7D4YZwC2zrjfrNejtKqWpft2kLc0aGC4A1kRuUoVcMrruFyfkF+eaFDmeGz4LyBuG4snfBPk6gAlLr5QKFyJ1PKEkNxi0IIBrGoaDtvwhfSdmKz72VdNSy98= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786225518; c=relaxed/simple; bh=hOGTV5ZOsL4kx/Q0FR6cxiFxpMfZE+LbKJAIogwdIRI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hYufolJuhz+WOv6JxkQ1E3aNtks4OqT9SP9AQ6FzJ5s+iJaAyUq/SaED1ADqjwhT361i7Xg4Xk6o35C3mMr0u/ZGQ3BPsxw3B8gyjjEeqg9Qbta46uC+ALn5rQGTDRcAMrMBo71BMROYKJTSXWXvBprVYkiTWEh6m7ssXfSqusE= 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=icXHXXp1; arc=none smtp.client-ip=209.85.214.180 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="icXHXXp1" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2cc97653887so7311085ad.1 for ; Sat, 08 Aug 2026 14:45:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786225517; x=1786830317; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=TWzyFxcV5fFu/M+6J2M1a01Ovc9+42gveuGFxl2QWXQ=; b=icXHXXp1eULjMMAkoglcxSm3UbEiYi1Dl//6L6Eez4erQqFjw3eXzjJPQPVXbcOy8n MMtdmriCsaGttNxM4FMa58G68NlPQkeQanKEhkY6zRpUhXyx8UVH0H4ZBgt1GrqgC6JY HLl2oHbbxPqW1IzN57FErIKNZaWweT7EqdIhAjVpEOebAOiXPNJPrJPpcuw/aMHESdDC cqSvV+3ru5iLBZT5wGuuInk4iJmgrr1hJFNgNsKGlFCPvb31ehUylh3e5ebxcD5ZNrHS dVeStllTGc6v/toAaKr3OLC54/xR/Wt7QGKN+XpelDsS0pezqpRdrC5ATMFv9aJmIkfL YkOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786225517; x=1786830317; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TWzyFxcV5fFu/M+6J2M1a01Ovc9+42gveuGFxl2QWXQ=; b=b13937VpeuQ3+ajM/AfvEIJRckJYWoNG1w3ak4sQgIM2f+JNEzvOlyehdSdl5EMwPn 2Gq0obO1ZZAH+3K3/1qzVlGJm080bhEQpg3HVCwC+14VwjSvHPIIg7VH24bCpelDXuzO iiszeu0c5SjUtomS1tn7C7f5+eddjcF4JjxnBABpsepT31NQCxIYBYoa1utiZrF8yvvV w0g79ZwOYhq9fMWXSoDAPGJZM/gRN8MAOK9UlZG2CURoEQ3snxVsEztPYKHj45GicZdx KcNt9SCxqgSEf93yYtBHo/ndDoFFzwElsHyBvxV0M2V1B8bquqgCNAT2P8L7Zf6d5Zdq 3JMQ== X-Forwarded-Encrypted: i=1; AHgh+RpKpwnBMqNjSnJUDFl5zOuEBXtQfE/8rQiBWpIqnABBX8OdaEU5TVLwNeQ/kQd2JYHbf4+hXzR5l60H7Jk=@vger.kernel.org X-Gm-Message-State: AOJu0YySOeFisNwGp2ibQ1DtC3RpDjv35XHcyhLMoC7BTSAwNZAp+3iQ MRIrQhBIypmVEE9zVTpQhaMz+zz0AHTSXR5Wax81+jWMJ08oojyND+/D X-Gm-Gg: AR+sD13tv2bTpJAVEDrBRvhrmVAC7C/3Q5iDpvhCNsZHbB8i9g5fRfL7VDN30HJ5Ubp xEId184oFOZTUbr1xvdFyc3BroWze5LhG64NRhwkkbxPmUs+8UXQsqFtXCldI27fFpz52TkuRKQ /jl8gT5pUsrFNF3os09uU2fTc1ZojArjLhWuBFvlwrdZesGdzQSKVJWTGWfF9+iwjPBRReZc8bb JHe448zCawZJnHNh3ql6kOPwj6X6Mno7wJZVUUUErGuh7MYcg8q8eZ4RZQCbRWXgNB/cGiaS/LP E+vKOh4oi4gbvBOy55gmY6Dt0F/ZSIZ5tOihfj8BxX48lfLmQ0GPaJjXUXjcMHd0p67icy9ihhJ rf/6lmWDhvcLYxfPT2lHDUcguDROH7cLRhIORV+3QbCTZdknB3DPJc5w0+NOm/l5dqI+bjcQwdF mNZD5iyJ9nd1QjxQAgMUFlZ7M6ongRY/gdHoY+8zV/EXso1shRqAEKkUO1OfDAn1OAnMGm4E9oi /Le8sz9CD5HilZp0C2aigHVSrzemoKaZ547LKenkbeexJ+EcaAKC4yI9EHd0a3EG1ErgJ9L X-Received: by 2002:a05:6a20:cf8d:b0:3c3:94a8:7c18 with SMTP id adf61e73a8af0-3cb8603af1amr40795284637.37.1786225516634; Sat, 08 Aug 2026 14:45:16 -0700 (PDT) Received: from bloom.localdomain ([2604:3d09:178e:e100::6868]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cbe8f35b781sm2194551a12.18.2026.08.08.14.45.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2026 14:45:15 -0700 (PDT) From: Ivy Lopez To: sre@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Ivy Lopez Subject: [PATCH] power: supply: ds2760_battery: fix NULL pointer dereference in w1_ds2760_remove_slave() Date: Sat, 8 Aug 2026 15:44:58 -0600 Message-ID: <20260808214458.201324-1-skunkolee@gmail.com> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit w1_ds2760_add_slave()'s failure paths (di_alloc_failed, batt_failed, workqueue_failed) are all empty labels that just return the error code, with no explicit unwind. This works for di itself and the registered power supply, both are devm-managed against the w1 slave device and get cleaned up automatically. But di->monitor_wqueue and di->pm_notifier are not devm-managed, and are only ever set up in the success tail of the function, after the workqueue allocation and power supply registration have both succeeded. The w1 core's BUS_NOTIFY_ADD_DEVICE handling in w1_family_notify() logs and returns on a failing add_slave(), but does not prevent the w1 slave device from later being removed from the bus, which triggers BUS_NOTIFY_DEL_DEVICE and an unconditional call to remove_slave(). This means w1_ds2760_remove_slave() is effectively the only failure-unwind path for a partially initialized di, and needs to treat every field as potentially never having been set. Currently it does not: it unconditionally calls destroy_workqueue(di->monitor_wqueue), which crashes with a NULL pointer dereference if add_slave() failed before or during the workqueue allocation (e.g. on a power_supply_register() failure, as seen when a colliding sysfs name from a misdetected slave device causes registration to fail). sl->family_data can also be NULL if add_slave() failed at its own allocation, before family_data was ever set, which would crash on the very first dereference in remove_slave(). Fix both: return early if di is NULL, and only call destroy_workqueue() if monitor_wqueue was actually allocated. unregister_pm_notifier() and cancel_delayed_work_sync() are safe to call unconditionally: the former is a no-op if the notifier was never registered, and the latter operates on the embedded delayed_work struct, which is always validly initialized by the time remove_slave() can run with a non-NULL di. Link: https://bugzilla.kernel.org/show_bug.cgi?id=217832 Signed-off-by: Ivy Lopez --- drivers/power/supply/ds2760_battery.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/ds2760_battery.c b/drivers/power/supply/ds2760_battery.c index 142c7492c3c2..3c2433f6b5e9 100644 --- a/drivers/power/supply/ds2760_battery.c +++ b/drivers/power/supply/ds2760_battery.c @@ -723,9 +723,13 @@ static void w1_ds2760_remove_slave(struct w1_slave *sl) { struct ds2760_device_info *di = sl->family_data; + if (!di) + return; + unregister_pm_notifier(&di->pm_notifier); cancel_delayed_work_sync(&di->monitor_work); - destroy_workqueue(di->monitor_wqueue); + if (di->monitor_wqueue) + destroy_workqueue(di->monitor_wqueue); } #ifdef CONFIG_OF -- 2.55.0