From patchwork Sat Aug 15 18:12:00 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Zhenlong X-Patchwork-Id: 2286328 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=QOlgOvj+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org; envelope-from=linux-i2c+bounces-19897-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from tor.lore.kernel.org (tor.lore.kernel.org [IPv6:2600:3c04:e001:36c::12fc:5321]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hMnKW2klLz1xqk for ; Sun, 16 Aug 2026 04:13:51 +1000 (AEST) Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id B7A95301DC0A for ; Sat, 15 Aug 2026 18:13:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B6B142DA3A; Sat, 15 Aug 2026 18:12:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QOlgOvj+" X-Original-To: linux-i2c@vger.kernel.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 19FD642C51D for ; Sat, 15 Aug 2026 18:12:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786817575; cv=none; b=g36OHOQyTcCPfx0KjiOsrLB5iJdZ3eAzkh1qm93WeBUb2YZDQNQtDG5kZHlEfrlIJIAWQwoJd/YqriZ1I+TQ5T7PTYLgdPrq0W7kaQGJjqp9tx9ffm+nJq51D/vydHfo8PISd62e84zUlpPoTN8ViQYHY9ZYvVfrifh3/vU+jZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786817575; c=relaxed/simple; bh=g/8fGhqkCV7RQstwEmzMAoWTNxRnB/a8B7+vfAI/r7I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R3+zjE//4WyP+zGSHroYCLG/EcVdwlLgdL1Ckephya9BTYu+K1R4dqm9+b0eT3ceILazrX4RJkK5rQ3aU/aowjtZIpvOD6cVNy07LPRYDpeaX4l9fua2ptnquPVeR+27UIMqJ6N4U/dox9GzKYVysB0tGj2e+GpTd3aKg43av5s= 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=QOlgOvj+; arc=none smtp.client-ip=209.85.214.169 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 Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2cc61541f8cso38948235ad.0 for ; Sat, 15 Aug 2026 11:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786817568; x=1787422368; 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:content-type; bh=Uq/zXomRaUtmPVU0X/7Fe7/2pJ+viXdEE1hutqkzih4=; b=QOlgOvj+whoo5+ZxgIL1l86V/C6PeXlWEPKfaD/ynydtTue1vPvXIjwkmm3KYi5pg1 Kf74xnr4RE7DVn2kgCk1M4802tAMKT5PhikJdUv9iLSP2Waf5zF4NAhuest46wqmtsta ZbLaGIgYuqMzuoOtnrejqYNb7SBkBsNywvo3VdImF6o4vEltAnyzVbZgfjSA9NiN6+mw wZCu+Fe+UmWxGPeOzcvzfd4vt8ZrT/8lzrhyodezjMwfpDej1U5vVrZeKdcwUjU+Ygaz N1NQ5g296iyrWSCFEMb5qSzDnoKsve8Qzw9X7SKXSRaGOLvk1hmkGVOaiPdPpo/z0vpk 3g1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786817568; x=1787422368; 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:content-type; bh=Uq/zXomRaUtmPVU0X/7Fe7/2pJ+viXdEE1hutqkzih4=; b=ThqHHNMcd+G8hrqPU0+Tsz/no71ZJvn9kvKsStSBmyHCPJHxSCXX+GQPMoqPF9bBJh L5amjDMquNZ620MheMkYLfFohxvF+FhuNR6S+8J9miEML8CcT+/J10NRVhEiVf275WJu aFPnFzQnheKUl0vZe4f1FT6CZAEyn89u/umAAGb+BBPSSegyGum/5yX8B1YBJYRnEXaV OnnofGH1w65tmohrwqSyKVBefK1w9dYrd/I8fNOK2jScHhXJrDiEAI2l8SDR8gQuJ4dy 5ZbgkK3IB/zui2QNV1mtIPi2XjcGr1rN4g1HXOJGkkqzOuvFWhABvh8H6P8BadvaPOnx c44Q== X-Forwarded-Encrypted: i=1; AHgh+RpXYm7UNA1RxNt4mfz+Tjn0Z9UHasfsvsk1ifWI5NIFV0iYJntdlGMTl2AtjzBD/uRN56EYBHQQPtg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5wCSqtjMq7pQ4tUuLX5seyqyFIpXow0kMBo17xGza4FzeVAiV NezrzOMrnvjl4ScoqIjdiV74tGhg363WkA2mZ4on7aiIkzz/vycD0orX X-Gm-Gg: AR+sD12YMOG/mf5j9Uw8q4SY3A6HOErH7hz0POKLYjNE8DffYQvVIsRYcgR7sfF25e6 2ce0kKgLgBQzJQPcHLJ/gugFzV7XmBLz3zbXKxSKWfbiOSXce1GK7KbYi0AFtlW7jZq2BydDkOf HYhgTLd9vlUmjlCZLvDQDU9tHds4GHGucMKU5HTOmPXhtrFbdEUdDzU5fmb7lLurEbvd5e5n0or ZmXap70fSAO/FpaDJUyYyKlkmVh1iKshhs9I6v/cVsnwdBd4HfrgfPeqOJPUga0bGFimMTC3BON zfAAcWHL3W+oEAWPwIKDQJF9SQ1fStcork5WGfumyQnN3z3kioJTx4O1Z6Z6bVJr0JDgU+EiYtd XVrTKBDFjVRLBMM3N4Dg5jw1BFQzLs1+ceoMGUrFmT9JOHyLGSEZR0Mzwf0fvSAanKqoIOLaR0w Ow68u0ucp9pY0oLC458iIIZOcWKDstHIBIWGNwLvhvFuRD9YehFlL7XKp5yV6QGsZxp1iU5uqEI jBRLOzfenz9dwyINpuS8yPxqYg= X-Received: by 2002:a17:90b:1b43:b0:38e:9ca8:e99 with SMTP id 98e67ed59e1d1-3933af8b5d7mr10385225a91.5.1786817568272; Sat, 15 Aug 2026 11:12:48 -0700 (PDT) Received: from localhost.localdomain ([240a:4280:4800:6ace:25e8:2607:e94d:caaf]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-394eb7539d3sm7304254a91.15.2026.08.15.11.12.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 15 Aug 2026 11:12:46 -0700 (PDT) From: Liu Zhenlong To: andi.shyti@kernel.org, chris.packham@alliedtelesis.co.nz, jochen@scram.de, maddy@linux.ibm.com, vz@mleia.com, piotr.wojtaszczyk@timesys.com Cc: mpe@ellerman.id.uk, npiggin@gmail.com, chleroy@kernel.org, grant.likely@secretlab.ca, neelegup@linux.vnet.ibm.com, benh@kernel.crashing.org, wsa@kernel.org, stigge@antcom.de, linux-i2c@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Liu Zhenlong , stable@vger.kernel.org Subject: [PATCH 1/5] i2c: mpc: fix device_node refcount leak in fsl_i2c_probe()/fsl_i2c_remove() Date: Sun, 16 Aug 2026 02:12:00 +0800 Message-ID: <20260815181204.2321-2-dragonliu2018@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260815181204.2321-1-dragonliu2018@gmail.com> References: <20260815181204.2321-1-dragonliu2018@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 fsl_i2c_probe() calls of_node_get() to take an extra reference on the platform device's of_node when assigning it to the adapter device, but neither the probe error path nor fsl_i2c_remove() drops it. device_release() does not call of_node_put() and i2c_adapter_dev_release() only completes a struct, so the extra reference is never released, leaking the device_node on every probe failure and every adapter removal. Add the matching of_node_put() to both paths. In the probe error path, i2c_add_numbered_adapter() failure does not run i2c_del_adapter(), so of_node_put(i2c->adap.dev.of_node) is safe. In fsl_i2c_remove(), i2c_del_adapter() clears adap->dev with memset() at the end (commit bd4bc3dbded9 ("i2c: Clear i2c_adapter.dev on adapter removal")), which zeroes adap->dev.of_node before of_node_put() runs, turning it into a no-op. Cache the pointer before calling i2c_del_adapter(), the same approach used in i2c-mux (i2c_mux_del_adapters) and mtd (commit 56570bdad5e3 ("mtd: core: Fix refcount error in del_mtd_device()")). Compile-tested with gcc-powerpc-linux-gnu on pmac32 defconfig; no hardware available for runtime testing. Fixes: 9fd049927ccb ("of/i2c: Generalize OF support") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Signed-off-by: Liu Zhenlong Reviewed-by: Chris Packham --- drivers/i2c/busses/i2c-mpc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index a21fa45bd64c..8182f7dc3d0f 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c @@ -867,8 +867,10 @@ static int fsl_i2c_probe(struct platform_device *op) i2c_set_adapdata(&i2c->adap, i2c); result = i2c_add_numbered_adapter(&i2c->adap); - if (result) + if (result) { + of_node_put(i2c->adap.dev.of_node); return result; + } return 0; }; @@ -876,8 +878,10 @@ static int fsl_i2c_probe(struct platform_device *op) static void fsl_i2c_remove(struct platform_device *op) { struct mpc_i2c *i2c = platform_get_drvdata(op); + struct device_node *node = i2c->adap.dev.of_node; i2c_del_adapter(&i2c->adap); + of_node_put(node); }; static int __maybe_unused mpc_i2c_suspend(struct device *dev) From patchwork Sat Aug 15 18:12:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Zhenlong X-Patchwork-Id: 2286330 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=Ha73oWMX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=linux-i2c+bounces-19898-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hMnLJ6tT3z1xqk for ; Sun, 16 Aug 2026 04:14:32 +1000 (AEST) Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id 8FD943028349 for ; Sat, 15 Aug 2026 18:13:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 12F5A38F65B; Sat, 15 Aug 2026 18:13:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ha73oWMX" X-Original-To: linux-i2c@vger.kernel.org Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 C378D42903F for ; Sat, 15 Aug 2026 18:13:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786817592; cv=none; b=ocTIaPJTGEZwSW0FleeynfMY2CSXs2QOxF2eC5Vnw669dkM3kZNAuL1w1DpgK/BeJzOt8GZePhdGp4ekmxcRdJP9WnzTSggTTTZBRyo7IRVPS0UGe+0IPiZaTlsdfUhv76YgHp4wZugPxwV2acrOfrJ3ICs3C0RstkLJ/Wk6+ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786817592; c=relaxed/simple; bh=t3t7eK6kze1JhppxfIkpcARg5SYY1S80ibdnXdinBHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DqG7AiKBcDtH8N1MjdX/8a/Ik4VDe4BlbWrV7zMt66yqB60O2XisDPDK+QJ1FE6UXupvjvsDj7aDDhEkklwXwu6o6Mmus09X5CX3cNLxc/55x5vSQK2gh1CO0ygmFzw2velPxWqRiOFKYNgm7euT975pZAHoxGiFf2j1ontVW74= 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=Ha73oWMX; arc=none smtp.client-ip=209.85.216.47 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 Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-38125cebfdaso3186613a91.1 for ; Sat, 15 Aug 2026 11:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786817582; x=1787422382; 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:content-type; bh=i7/QgzN5wyVgDaVsVdjpFdimGVN0rJBMi0oSVa7MqkE=; b=Ha73oWMXcWU8QZFT0AT5zV4KcfoCPUdgWcozoJ7227IyIEcMOfy31xDO4GIG9/fHvk XOQrSpvi7EAdo3e5f0XI7VAbbyliI5+VdCp5Q2n/ZYp5lgdK554l3rWSuHjA9PXnsdRJ d2Wpzn0w17Kh37BYlLAiMNNvTnjOd7lImPYE2su7mzPs8YJTn/NEzoiK+haGiKCeqTfv mkOFXzrBudRr5RgZmAfn3LJHcpOZ/B1kHXdXUSdvuzq6lsQFwkOBB+dodLbxpjSDXoaY BvQ6bmeXUY5bMe3dzUZffdzfbueXlhVAwlLeo0cjgx273vHwisLi0Edi3eAwe8+YQ9vt AMQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786817582; x=1787422382; 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:content-type; bh=i7/QgzN5wyVgDaVsVdjpFdimGVN0rJBMi0oSVa7MqkE=; b=T5/r+6nxTn9j715ZbSb1yMkYfIFDsLlPu+Q5UmitSVJEDZfLpEjTgKnURMpvDDtLOg ha9L085L9LbaMrkoD77Zov4RvvOCN2Kl/+SGHDVM4+6pZmx+6Po8k1UJsA5Ww3iOg5lm WqsYKnMH7hApFSTVH2qDFaH+KNKROPjrbz4/1p6hkkVJ1T0VpI/XeBEx0xbpJyXWLOKD mTmNu+kdRDWP4ThTdcwR8pT+yWCViZT5DTc5+b+FyNioNZpVhYMNijMQWiZrwYbV5QiC A1xaHj4B3vcx5Pbxpg5XbX7PQGISKw1dGAw8OVVFrWRft1v+9m19SFm3ITVBzjX7GNi/ /Q7A== X-Forwarded-Encrypted: i=1; AHgh+RpfQORF0fShWs5sRd0x4mmqOj8fUGh9G/IuWnw0VN8hoQrLdf2tDjpYJzRTSJ3QBMzm2stCtpGb2Co=@vger.kernel.org X-Gm-Message-State: AOJu0YwEOfvYDNox00sZoYrFLGc5GQU5h0MUa5QbPaXQXmmcg+phr/Fy yuwAS5BOoXrpeAhfqYq7db27p1RzPw4FwbHI0NSaNw9ooFkTtLXFkERe X-Gm-Gg: AR+sD12SAW3zPJobqYlVs2aVA5nal3SrzwpjJH9yO9UKjCLJ/IaBwcsu/FQsBmxd2rz Sa0uXmVWBctP3sbXBfSpnfrAPJ4dHBodPIu+gwlhgDozdEFnx86xae6TDXscRgpZgV7jIFwT3Z8 s4ncXnsO+ncL8FRdqRnioWe46PWOykHeSuyhY9u+b4jUyB86b2b3V7AZiVL+JLWCje35K8KMSZ2 EKB1UkjIWcY7bBHr9mj6fmOd+o8o8ADagB+3bJCrAU01BdEHBegG6yWODRVBv838VqPfxN/dAeT kZwmTAgFFQ5mzpGIIdzqpEHcocoQuuSg9uzkIHvUD1CGUSsZfFzKnhFCNWKO7pBFocJdCq8VWkC fUzsm447BqiJV9AB2lZeUAdb4PUf9AvJqGV5p4oLuTEXteKeQuG1ZE8Vrrf2dWJ8mK10xH5XJDK 8eI7JpLHC+Au4nI2khckDPU6904S0c4VOFBpXQX58dg07UNRWfyQSGjaBG+XsQRKR0LOnbE2LB1 950c+UOvM1Ukq6oUThi3Rue0UI= X-Received: by 2002:a17:90b:2747:b0:38e:2f21:3bb5 with SMTP id 98e67ed59e1d1-3933baa0da9mr17205808a91.21.1786817581938; Sat, 15 Aug 2026 11:13:01 -0700 (PDT) Received: from localhost.localdomain ([240a:4280:4800:6ace:25e8:2607:e94d:caaf]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-394eb7539d3sm7304254a91.15.2026.08.15.11.12.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 15 Aug 2026 11:13:01 -0700 (PDT) From: Liu Zhenlong To: andi.shyti@kernel.org, chris.packham@alliedtelesis.co.nz, jochen@scram.de, maddy@linux.ibm.com, vz@mleia.com, piotr.wojtaszczyk@timesys.com Cc: mpe@ellerman.id.uk, npiggin@gmail.com, chleroy@kernel.org, grant.likely@secretlab.ca, neelegup@linux.vnet.ibm.com, benh@kernel.crashing.org, wsa@kernel.org, stigge@antcom.de, linux-i2c@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Liu Zhenlong , stable@vger.kernel.org Subject: [PATCH 2/5] i2c: cpm: fix device_node refcount leak in cpm_i2c_probe()/cpm_i2c_remove() Date: Sun, 16 Aug 2026 02:12:01 +0800 Message-ID: <20260815181204.2321-3-dragonliu2018@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260815181204.2321-1-dragonliu2018@gmail.com> References: <20260815181204.2321-1-dragonliu2018@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 cpm_i2c_probe() calls of_node_get() to take an extra reference on the platform device's of_node when assigning it to the adapter device, but neither the probe error paths nor cpm_i2c_remove() drops it. device_release() does not call of_node_put() and i2c_adapter_dev_release() only completes a struct, so the extra reference is never released, leaking the device_node on every probe failure and every adapter removal. Add the matching of_node_put() to the probe error cleanup (out_free, which covers both the cpm_i2c_setup() and i2c_add_numbered_adapter() failure paths, neither of which runs i2c_del_adapter()) and to cpm_i2c_remove(). In cpm_i2c_remove(), i2c_del_adapter() clears adap->dev with memset() at the end (commit bd4bc3dbded9 ("i2c: Clear i2c_adapter.dev on adapter removal")), which zeroes adap->dev.of_node before of_node_put() runs. Cache the pointer before calling i2c_del_adapter(), the same approach used in i2c-mux (i2c_mux_del_adapters) and mtd (commit 56570bdad5e3 ("mtd: core: Fix refcount error in del_mtd_device()")). Compile-tested with gcc-powerpc-linux-gnu on tqm8xx defconfig; no hardware available for runtime testing. Fixes: 9fd049927ccb ("of/i2c: Generalize OF support") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Signed-off-by: Liu Zhenlong --- drivers/i2c/busses/i2c-cpm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c index 2cb6a233d313..08e33db32f14 100644 --- a/drivers/i2c/busses/i2c-cpm.c +++ b/drivers/i2c/busses/i2c-cpm.c @@ -671,6 +671,7 @@ static int cpm_i2c_probe(struct platform_device *ofdev) out_shut: cpm_i2c_shutdown(cpm); out_free: + of_node_put(cpm->adap.dev.of_node); kfree(cpm); return result; @@ -679,9 +680,11 @@ static int cpm_i2c_probe(struct platform_device *ofdev) static void cpm_i2c_remove(struct platform_device *ofdev) { struct cpm_i2c *cpm = platform_get_drvdata(ofdev); + struct device_node *node = cpm->adap.dev.of_node; i2c_del_adapter(&cpm->adap); + of_node_put(node); cpm_i2c_shutdown(cpm); kfree(cpm); From patchwork Sat Aug 15 18:12:02 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Zhenlong X-Patchwork-Id: 2286331 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=bPNEHXWc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org; envelope-from=linux-i2c+bounces-19899-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from tor.lore.kernel.org (tor.lore.kernel.org [IPv6:2600:3c04:e001:36c::12fc:5321]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hMnLk6zxGz1xqk for ; Sun, 16 Aug 2026 04:14:54 +1000 (AEST) Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id 3DE6F302DE20 for ; Sat, 15 Aug 2026 18:13:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE94E42A141; Sat, 15 Aug 2026 18:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bPNEHXWc" X-Original-To: linux-i2c@vger.kernel.org Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (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 B680F42A789 for ; Sat, 15 Aug 2026 18:13:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786817599; cv=none; b=oZjE2ws8oi+w37x321XGx9qYqZf2xjpT/MiUvm5MTS142ZXVUFiA/OvwDH08BgZlPlLFi29SbRlOxrM9gqvvPV0e0XERBtPdo18GMI18JUQIVLKFpbyuQtGDfM7mACum6Bfj/filCKGreWZdtXk4/dYFwOc7g5d/MpXXK+/D1xc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786817599; c=relaxed/simple; bh=AEno/8kJE1dDO+zyyZE4ZuQtK5pId1vsBKGwv9wYw6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JDOLQWZePorP/78inm/t3fqxJD9mYtlpDRD7geigaQ8yMUbj6VpNIjTlGyo168nymTMSgJ7zWvlC02AM7IYyTq5Z8m8ujCmDFi128QpjggD9FN5FlwmD4ic/MpFM0vXMpl9vCAjGRkA/A0QwmA1QjDWiu9f5TAXQgdAuLtfs+q0= 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=bPNEHXWc; arc=none smtp.client-ip=209.85.215.176 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 Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-cbedd5aece4so2214500a12.0 for ; Sat, 15 Aug 2026 11:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786817597; x=1787422397; 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:content-type; bh=hn1w8vtbj9zAmfIr6OtJvXMx3Rjgqtv0x/ZQ8XLdFkg=; b=bPNEHXWcL3cTBBHq/xuIj4vGgxmCtkNecbf5R+bYLpfAV8l8zQdZ2kJdslFq3OwF/K JFfKABreQjaJFEl6BAJe62vbz8mkC2CKfmDtxGRl/XF0F9cOnwipqBBe29n3TK5fODVT rs5VL9yDTO+SFa2pfvsYeVZyaBx/ukCuFiOee99QOdhT024SoFeEvOUvbWsp4etdpCj0 Lpp15VlJpmWDBr+t9mpZ+eU+gig3+khiHWK4lbl3eLzAPjpR7BtE5YoU9zGt1loUg3n/ PiAjgH8wsKhFJ0OR0L0hd/pJ9DidigVS8tZPb7lbd53xKrhMIF0sD/OlE4rnahPKBvY/ 3moQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786817597; x=1787422397; 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:content-type; bh=hn1w8vtbj9zAmfIr6OtJvXMx3Rjgqtv0x/ZQ8XLdFkg=; b=IkqZkIt8WlJG2EVRbhrDe3M5+PvZYmlKL38RmHp/zHZMC/Zr/rFFUVRU0qyFLL5pPx nyPJWo9LNcFGdBT1WJJoVwcdSKEwxbk1WXtqCW6dfrn4Sq8ay/8Aj4H2kNxPZCaUcyIh 1+9OzGTEI0w8Z+2tAsq/4/pI9NZ7ZSCTYgBYFcFRHBAgLj9HkwSxAqXGWEHwqSX2EDll 7WVxkOZAwIX4zhif3jst3zBmxSKyjXa97yIu/XoiL4PoE5ZBuv1HAgaQoSk+yU/wJzbQ hwoQUHBQm8EpdJDNG9nEscRsC3xNzk6xkn2oAzz8t2U8UFYa8FLoPWZSz4PsLuLukn2a mo8A== X-Forwarded-Encrypted: i=1; AHgh+Ron0NL1YWtvmL5sbjg46PGquaJWf0ayPCx15ImWH0Ls8vDJcrFT7PTfThs4PDL1kwhv4NgX0OItZP4=@vger.kernel.org X-Gm-Message-State: AOJu0YycFNq7PhG8+xgwfPyS95xlKqCnTk6SwdhxupAjjufCnzWtcqcn 4gOJPoySwau8JEgMFAQyye/NeK6Su1lRERz/cZiUGqLJUy5WHoJbD4+W X-Gm-Gg: AR+sD11ThBtaTnGy7lWjlxtoXfAAbEcCP8Mn7JRlMCfBANrZvJwKc3OfTHX2ywRVpo/ /ccQ5hNudUsK+vI8eCA0WvzBvdqNOcKCTzhF73DlZ+JNsEx5zR1gm0b+QmcJd1b4YF2n/SFzZQr BFSYpj89wErFwdLM/zYCwMNMcFQuLoJ6zpVK59GCe8Evqa6zvUJw043Hncy+OjZloBhFiXKRi0L +ez5IgO+h164By2xYvc94paxKz2KPSacC+2owVWWD9YDjNo86Ld5/UD+GGeml5fCB5rKdL7P0zv aTorjOSCM3KDuYebIkrRO7GIyYj2Cxae5mqbfuNSLv0yPq9L21t4Md2TZZMIgnX8Gj0dULTJH+K M/AuXFljy3KYkO1q0FAFI3a1R6YQTxi7/P6rOFfVefhhjQZ9U+4V7Agg9/+bdT2jbhARlqaYJLL e6Z2zD8ph2SmSE8SGWOOdXWNbnnsmHJrjFLfRvK4M0KsFdB5o7a5qUMVZB2sQdwlvQaD9Zr5hSd 0PftI+PT3eT+0+7q+Urd2XmJto= X-Received: by 2002:a17:90b:37c3:b0:390:84db:888e with SMTP id 98e67ed59e1d1-3933afb4ba2mr11589304a91.7.1786817596734; Sat, 15 Aug 2026 11:13:16 -0700 (PDT) Received: from localhost.localdomain ([240a:4280:4800:6ace:25e8:2607:e94d:caaf]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-394eb7539d3sm7304254a91.15.2026.08.15.11.13.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 15 Aug 2026 11:13:16 -0700 (PDT) From: Liu Zhenlong To: andi.shyti@kernel.org, chris.packham@alliedtelesis.co.nz, jochen@scram.de, maddy@linux.ibm.com, vz@mleia.com, piotr.wojtaszczyk@timesys.com Cc: mpe@ellerman.id.uk, npiggin@gmail.com, chleroy@kernel.org, grant.likely@secretlab.ca, neelegup@linux.vnet.ibm.com, benh@kernel.crashing.org, wsa@kernel.org, stigge@antcom.de, linux-i2c@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Liu Zhenlong , stable@vger.kernel.org Subject: [PATCH 3/5] i2c: ibm_iic: fix device_node refcount leak in iic_probe()/iic_remove() Date: Sun, 16 Aug 2026 02:12:02 +0800 Message-ID: <20260815181204.2321-4-dragonliu2018@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260815181204.2321-1-dragonliu2018@gmail.com> References: <20260815181204.2321-1-dragonliu2018@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 iic_probe() calls of_node_get() to take an extra reference on the platform device's of_node when assigning it to the adapter device, but neither the probe error path nor iic_remove() drops it. device_release() does not call of_node_put() and i2c_adapter_dev_release() only completes a struct, so the extra reference is never released, leaking the device_node on every probe failure and every adapter removal. Add the matching of_node_put() to the probe error cleanup (error_cleanup, which covers the i2c_add_adapter() failure path; the earlier error paths jump to the same label before of_node_get() runs, but dev is kzalloc'ed so dev->adap.dev.of_node is NULL and of_node_put() is a no-op there) and to iic_remove(). In iic_remove(), i2c_del_adapter() clears adap->dev with memset() at the end (commit bd4bc3dbded9 ("i2c: Clear i2c_adapter.dev on adapter removal")), which zeroes adap->dev.of_node before of_node_put() runs. Cache the pointer before calling i2c_del_adapter(), the same approach used in i2c-mux (i2c_mux_del_adapters) and mtd (commit 56570bdad5e3 ("mtd: core: Fix refcount error in del_mtd_device()")). Compile-tested with gcc-powerpc-linux-gnu on ppc44x defconfig; no hardware available for runtime testing. Fixes: 9fd049927ccb ("of/i2c: Generalize OF support") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Signed-off-by: Liu Zhenlong --- drivers/i2c/busses/i2c-ibm_iic.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c index 7c70e8bda24e..5c3b973c40d9 100644 --- a/drivers/i2c/busses/i2c-ibm_iic.c +++ b/drivers/i2c/busses/i2c-ibm_iic.c @@ -751,6 +751,8 @@ static int iic_probe(struct platform_device *ofdev) free_irq(dev->irq, dev); } + of_node_put(dev->adap.dev.of_node); + if (dev->vaddr) iounmap(dev->vaddr); @@ -764,8 +766,10 @@ static int iic_probe(struct platform_device *ofdev) static void iic_remove(struct platform_device *ofdev) { struct ibm_iic_private *dev = platform_get_drvdata(ofdev); + struct device_node *node = dev->adap.dev.of_node; i2c_del_adapter(&dev->adap); + of_node_put(node); if (dev->irq) { iic_interrupt_mode(dev, 0); From patchwork Sat Aug 15 18:12:03 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Zhenlong X-Patchwork-Id: 2286332 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=U956VqSC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org; envelope-from=linux-i2c+bounces-19900-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from tor.lore.kernel.org (tor.lore.kernel.org [IPv6:2600:3c04:e001:36c::12fc:5321]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hMnMD3TNfz1xts for ; Sun, 16 Aug 2026 04:15:20 +1000 (AEST) Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id 5EDDF301B925 for ; Sat, 15 Aug 2026 18:13:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 168D6429CF0; Sat, 15 Aug 2026 18:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U956VqSC" X-Original-To: linux-i2c@vger.kernel.org Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 22EA342587A for ; Sat, 15 Aug 2026 18:13:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786817610; cv=none; b=iePEZTe0gAU1EButbBO50UHPhNct9FwGVZEhznY4kQsso2/V21TJCazrJuvsYS8lz5z4ZKPhojJe0+dLwOuf48SLXY+oudQgLW6tspeklvbtGA+Lxzx2xFFrJl3poCGM6X1ZTf4E6vfN1VKIablCfMfUmsybGXcyvQ/K0fDh/kU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786817610; c=relaxed/simple; bh=EiNqdaH18y3SuWINgOWAbB1gLMNQaalm9BnumdHTrvY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ITuU4qjujKPzaK0WTqs0UuYpj3NSOo9r3/VwLYQWXx6c/3yTRu8aIdYVAeu6vOhRmYfdpRF+mdchh8tAxI0nC2gmoMcr3uUjc0GuWNoMogbyy8hWgYtKAk8WTh41Nc89WruhTqmEVxP0e4sJlxKIbIX5jicuNwBwuHg7JYe4tnc= 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=U956VqSC; arc=none smtp.client-ip=209.85.215.177 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 Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-cbed97fa26fso1273343a12.0 for ; Sat, 15 Aug 2026 11:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786817607; x=1787422407; 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:content-type; bh=hOjD+7itBEHsMfKmr+ynGew/Kjw1CTU/4y0bM+1NDxI=; b=U956VqSCVddIPuvuS9ihnP5fYgKgUWzUx2e/4b16hOJYlhksMx0WmBxJhAGjZZXviq QjTgK3/Nxw7F7wpTrGXL1PToisBrFkCBV5XSFbpkaC3e/xdmqHTVaok8F9QBVQ0XlnE9 EOjV3bSBlmWUb2byLb7dIIomDMua7yx0r9hoFHHA45DINEzyUKdHrXqwWYA3EGJslkxm FM9Tz3ceKPALHoIQpEdPi3tiWCPEpN0oV8q9vlcM1KvpR/b4GN7hfLMZc5yR9xoxztSd M8F7IUN979njEf7u6Buc1PtSNi/oiJrvEapevk/t7wPd79NdGNgJZYGHR1fUafvEbkVC IqCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786817607; x=1787422407; 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:content-type; bh=hOjD+7itBEHsMfKmr+ynGew/Kjw1CTU/4y0bM+1NDxI=; b=Mr9ck/a9eszKGB6Os/3nGhxtiltOYtTQmtlDPHx9a+/PdcE+lK5oNyIXUdv83eQZan wGd7VwfriQBpmi/7sdI+8YKtBi5tjExCSSAn2WFFjjRoWJso8uR1p2snE5eVm/q2iNXp 1LAl9an6+EStKH4LpSShdYqUn1GiKNTO5eFq5WhZJeAQmwcrbY5eZ/kxPIt3zs/+ipXw szbCYcm6DH8H+addxEuN7H9jtaHauLMIuT7Y5vDJwEK1Y6t33AF11sk0uXp/+JsJ8A4P bQz2kxzimwuUzV5seVkLItZgDepTyJizlKS48tPFDOHN5GarqUH7Prx+cLZWc/XzKCki Vyww== X-Forwarded-Encrypted: i=1; AHgh+RoN2W93d1qKnw+r55zqolRIdD0AMuNMkoQezgEPSMWYakd4g2+5zrAUoW7gBcx/TEP0zKT4A5wsPqE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5O76kbhhugDPvPEBjzeb/IYonCfDw+8H+geJcoVb6dXmJpOYW 2Uq+4Wpq0Hssj8HbO1ay/D9xQgXRrM4uPMhAmLItX7Oo52cddFjEG4nY X-Gm-Gg: AR+sD112EziEAWqXC7rJ2VTK0K+gsBZVch1H1B4QqayHhyVz398i/WSHmTwmXIzNU6u QmngFwuHhu3QvzbbUAiM9onyP8bHJwu0ejuFRnA1rD8c7yiSYL3FqwWMkxrko3QjwwFZSFAtDF9 IEauGAMY81H5uG0h5+BIcK21qhGshTjmK1WKv15JBqFhMSOxMQ5D5xDPhAeJuhleFb26+gk8nnx CnAUNoSVwyEARW4pUMMC1fpZ1KTc1ZJJ8RGByRFAXr01R8Jdk+C6MMiuq2SDNeHT+4bS6J6ICof VqjryTavgx3Baw2wz9Ds6OTzfEaPWYZ6n/JwcI4yCawm3KV3Zys7kcKY4D5/nQ9oeyuR2VzWNqk jkNL9wzNUA5iqwUscUWNAHFzMGJk9qA2rsLuDDi3iE1OLorWUJCeSggApl8pOr1TwK9ni3DQXDF OR3hKMkbOO+qhZtmvtajqGYp9w7xAtkV2eIhcEIR9FccdanXwKCO/moDbNcSnwgAiGVPYeKbYsZ ADz8ctV6fcs4yDKETRqaSdBVms= X-Received: by 2002:a17:90b:4ac6:b0:38f:1a29:7a82 with SMTP id 98e67ed59e1d1-3933afb387cmr9673131a91.6.1786817607293; Sat, 15 Aug 2026 11:13:27 -0700 (PDT) Received: from localhost.localdomain ([240a:4280:4800:6ace:25e8:2607:e94d:caaf]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-394eb7539d3sm7304254a91.15.2026.08.15.11.13.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 15 Aug 2026 11:13:26 -0700 (PDT) From: Liu Zhenlong To: andi.shyti@kernel.org, chris.packham@alliedtelesis.co.nz, jochen@scram.de, maddy@linux.ibm.com, vz@mleia.com, piotr.wojtaszczyk@timesys.com Cc: mpe@ellerman.id.uk, npiggin@gmail.com, chleroy@kernel.org, grant.likely@secretlab.ca, neelegup@linux.vnet.ibm.com, benh@kernel.crashing.org, wsa@kernel.org, stigge@antcom.de, linux-i2c@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Liu Zhenlong , stable@vger.kernel.org Subject: [PATCH 4/5] i2c: opal: fix device_node refcount leak in i2c_opal_probe/remove() Date: Sun, 16 Aug 2026 02:12:03 +0800 Message-ID: <20260815181204.2321-5-dragonliu2018@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260815181204.2321-1-dragonliu2018@gmail.com> References: <20260815181204.2321-1-dragonliu2018@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 i2c_opal_probe() calls of_node_get() to take an extra reference on the platform device's of_node when assigning it to the adapter device, but neither the probe error path nor i2c_opal_remove() drops it. device_release() does not call of_node_put() and i2c_adapter_dev_release() only completes a struct, so the extra reference is never released, leaking the device_node on every probe failure and every adapter removal. Add the matching of_node_put() to both paths. In the probe error path, i2c_add_adapter() failure does not run i2c_del_adapter(), so of_node_put(adapter->dev.of_node) is safe. In i2c_opal_remove(), i2c_del_adapter() clears adap->dev with memset() at the end (commit bd4bc3dbded9 ("i2c: Clear i2c_adapter.dev on adapter removal")), which zeroes adap->dev.of_node before of_node_put() runs. Cache the pointer before calling i2c_del_adapter(), the same approach used in i2c-mux (i2c_mux_del_adapters) and mtd (commit 56570bdad5e3 ("mtd: core: Fix refcount error in del_mtd_device()")). Compile-tested with gcc-powerpc-linux-gnu on powernv defconfig; no hardware available for runtime testing. Fixes: 470834508f87 ("i2c: Driver to expose PowerNV platform i2c busses") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Signed-off-by: Liu Zhenlong --- drivers/i2c/busses/i2c-opal.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-opal.c b/drivers/i2c/busses/i2c-opal.c index c9b62892397a..43b3d17e933b 100644 --- a/drivers/i2c/busses/i2c-opal.c +++ b/drivers/i2c/busses/i2c-opal.c @@ -226,8 +226,10 @@ static int i2c_opal_probe(struct platform_device *pdev) platform_set_drvdata(pdev, adapter); rc = i2c_add_adapter(adapter); - if (rc) + if (rc) { dev_err(&pdev->dev, "Failed to register the i2c adapter\n"); + of_node_put(adapter->dev.of_node); + } return rc; } @@ -235,8 +237,10 @@ static int i2c_opal_probe(struct platform_device *pdev) static void i2c_opal_remove(struct platform_device *pdev) { struct i2c_adapter *adapter = platform_get_drvdata(pdev); + struct device_node *node = adapter->dev.of_node; i2c_del_adapter(adapter); + of_node_put(node); } static const struct of_device_id i2c_opal_of_match[] = { From patchwork Sat Aug 15 18:12:04 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Zhenlong X-Patchwork-Id: 2286329 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=E5Dm7D1n; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=linux-i2c+bounces-19901-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hMnKr1HnLz1xqk for ; Sun, 16 Aug 2026 04:14:08 +1000 (AEST) Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sto.lore.kernel.org (Postfix) with ESMTP id C9A223012664 for ; Sat, 15 Aug 2026 18:13:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A905429803; Sat, 15 Aug 2026 18:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E5Dm7D1n" X-Original-To: linux-i2c@vger.kernel.org Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 9612C42642D for ; Sat, 15 Aug 2026 18:13:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786817623; cv=none; b=gW8URNv4v5uqjsHf+unxJVkvwKJuYRjob3v8MrQu+DN36QmG6U4PL8F/nNaKIsVo7NqjMbLjeNYzEg4IcncuGUgP9AhvG/aqHWvWqfIzE6QD0UHPwz+D0haorygbhIk6QLEmszryJcnPPFcIET7FEIezhB682u0WwPSMHdEZPqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786817623; c=relaxed/simple; bh=96dNgm0w4p4mneCX3nrwNYF339ix1yCXiaxbeFg7LcM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sekm3xsggKu3wZ7pL1yczGWbBo6Nlqk5oJfCdvMYnlow2yzS5518vRjCvEsSo4ecsG/Vwz48hIT0dZVxKCmQrP7bbexlYfK58WjLe679x0UPSv/QcSxdYOg75HACEdzudAlH9pOQt9QdA5dsUTTcUsCoIQPXalvirTHFybNsT6E= 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=E5Dm7D1n; arc=none smtp.client-ip=209.85.216.44 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 Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-3810c5d691bso1531209a91.1 for ; Sat, 15 Aug 2026 11:13:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786817618; x=1787422418; 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:content-type; bh=V91oZrI/zJYRrYjWs8UIHznDrCj9rfvAd4MAMUD9J1o=; b=E5Dm7D1nARdS9er69ZSJ4AAyLGbJn9O7qLI/uWJbMzmtQI65ZO4b9ZCZEt5QIxM3Yu pBlz7zT6eJQlthO7zulBqLLIS2YE6CAonHY3Q/VKHHjZXOfbhpYwJ0JjueAREWLhkayO jgIOFD6Uj49c2A3igYNX6lBIHruwCo8EdtcJD7zIKeioIp4Mv8UmRS1vW9zV5CROUOE0 /hhjzN5SYqY7xgaTgx3qlZPFPVSSle2Up/JjBKd0nPbo+/8ruPsSUpmmsLMvr9fK1ZzX DFoeRrWQsZzKY4HOwvo11MH1igz5KCe3BnvoPMmPLykop1BFeLVbcIv62rfzULxVsLBi 6wjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786817618; x=1787422418; 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:content-type; bh=V91oZrI/zJYRrYjWs8UIHznDrCj9rfvAd4MAMUD9J1o=; b=T4ZX/mo3CsMpT2Pu6zit3VBlXC8b5maG4GeHkYg5SESFd7jZ1LXYPX3/qaYRncXajk uQ54U0ez0iBZyELaKRHlMp6m8FxIzhCNKCnavdq6BgqcmQhig7Yj3W4IxzgNxzA62S5a Rk8k3NX5cJh+qVXwwrFSJhaWYmyIUHgnOb0JNY4gRgphPvU4DQbD7ZH1k3G5iWZGCkFE osK90IKaPj1a5VWnOqXAFc915J4jnsPFJsvczTjo3R/bAj24tTWjjytUGYaXc3UXfa4d hZ4jMgNHqwSEiJ520+s+YbQVoDfGcHZQlXJEUVUKVugptaDnUiiCBxr6lt6HXyrw7sDP Q7Tw== X-Forwarded-Encrypted: i=1; AHgh+Ro8lXa1s6SCvyxeP7YGO5zeZJZWDZRa5KytMGGNLDGuZwYLpJ0mxvRCKCObvfGcllaahhvn25/Dn9M=@vger.kernel.org X-Gm-Message-State: AOJu0YzLYfKGaQpW7G5NhpgnutbwafFigqvPXsvy/2KJnLB+dhN7NC1l 6xYS2wyHpj6Ccc4meXRg0XEi1y9kKp23QTF20tTBL1uggGLufQBOiiyW X-Gm-Gg: AR+sD13zGWjTRAmhebj/TIgjnnD3FrYk6MUBCEnd/0ai0EHlf4HcdGeF+jqjVBq8cqs PeECwE/qzDK7U906+9K4vmSGIFpOjOzhQFb1qmkH05LnMLD6xja4Pz+uc8B6Y1v+wvJumewsv4g hbwNOKgoDd1qHuuzUQVpCL6eZ35/ZV3ce/pEfY++wma6K5D9ORqt5VjVVdLw4biRL/JW8DDSfie a+T5v1WX7YrXBX/RQqC37qwnSwnObxm19s2Js6CAj8jr9RQ61nZmN2KoryeRGajjqlYpVavTWQI XLoihBKhn/NgqIux7UjtXIfA2JgRdFlrQu5Nr0pCH7J2x4OznLbTLluNOTGsSZgGmlDmsuHfmzM MdYshXaYqnvsjNf6+zd1trQ4tdmdpk+YYaU5U047gnSFP7dQITnW73WJZnxhBX6c+p0XTBYYXmx qOm7uGkA2yKaApuDmhOOT+7PCU/Lw0cn+SWVj3Op8rHXCEd6XSro1WPyLjCnaoTQ4kQnuRNmps7 0A7vUI3VUN4FME57h5rbLYtoy8= X-Received: by 2002:a17:90b:1b05:b0:380:873:49cb with SMTP id 98e67ed59e1d1-3933baa0d6amr14788639a91.21.1786817618461; Sat, 15 Aug 2026 11:13:38 -0700 (PDT) Received: from localhost.localdomain ([240a:4280:4800:6ace:25e8:2607:e94d:caaf]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-394eb7539d3sm7304254a91.15.2026.08.15.11.13.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 15 Aug 2026 11:13:36 -0700 (PDT) From: Liu Zhenlong To: andi.shyti@kernel.org, chris.packham@alliedtelesis.co.nz, jochen@scram.de, maddy@linux.ibm.com, vz@mleia.com, piotr.wojtaszczyk@timesys.com Cc: mpe@ellerman.id.uk, npiggin@gmail.com, chleroy@kernel.org, grant.likely@secretlab.ca, neelegup@linux.vnet.ibm.com, benh@kernel.crashing.org, wsa@kernel.org, stigge@antcom.de, linux-i2c@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Liu Zhenlong , stable@vger.kernel.org Subject: [PATCH 5/5] i2c: pnx: fix device_node refcount leak in i2c_pnx_probe()/i2c_pnx_remove() Date: Sun, 16 Aug 2026 02:12:04 +0800 Message-ID: <20260815181204.2321-6-dragonliu2018@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260815181204.2321-1-dragonliu2018@gmail.com> References: <20260815181204.2321-1-dragonliu2018@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 i2c_pnx_probe() calls of_node_get() to take an extra reference on the platform device's of_node when assigning it to the adapter device, but none of the probe error paths nor i2c_pnx_remove() drops it. device_release() does not call of_node_put() and i2c_adapter_dev_release() only completes a struct, so the extra reference is never released, leaking the device_node on every probe failure and every adapter removal. Add the matching of_node_put() to all probe error paths (the three early return paths before clk_prepare_enable(), and the out_clock label which covers the wait_reset(), platform_get_irq(), devm_request_irq() and i2c_add_numbered_adapter() failure paths; dev is devm_kzalloc'ed so adapter.dev.of_node is NULL and of_node_put() is a no-op when CONFIG_OF is not set) and to i2c_pnx_remove(). In i2c_pnx_remove(), i2c_del_adapter() clears adap->dev with memset() at the end (commit bd4bc3dbded9 ("i2c: Clear i2c_adapter.dev on adapter removal")), which zeroes adap->dev.of_node before of_node_put() runs. Cache the pointer before calling i2c_del_adapter(), the same approach used in i2c-mux (i2c_mux_del_adapters) and mtd (commit 56570bdad5e3 ("mtd: core: Fix refcount error in del_mtd_device()")). Compile-tested with gcc on arm64 defconfig using COMPILE_TEST; no hardware available for runtime testing. Fixes: b41a216dafe4 ("i2c: Add device tree support to i2c-pnx.c") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Signed-off-by: Liu Zhenlong Reviewed-by: Vladimir Zapolskiy --- drivers/i2c/busses/i2c-pnx.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c index 8daa0008bd05..0b6c144d9a21 100644 --- a/drivers/i2c/busses/i2c-pnx.c +++ b/drivers/i2c/busses/i2c-pnx.c @@ -644,20 +644,26 @@ static int i2c_pnx_probe(struct platform_device *pdev) } #endif alg_data->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(alg_data->clk)) + if (IS_ERR(alg_data->clk)) { + of_node_put(alg_data->adapter.dev.of_node); return PTR_ERR(alg_data->clk); + } snprintf(alg_data->adapter.name, sizeof(alg_data->adapter.name), "%s", pdev->name); /* Register I/O resource */ alg_data->ioaddr = devm_platform_get_and_ioremap_resource(pdev, 0, &res); - if (IS_ERR(alg_data->ioaddr)) + if (IS_ERR(alg_data->ioaddr)) { + of_node_put(alg_data->adapter.dev.of_node); return PTR_ERR(alg_data->ioaddr); + } ret = clk_prepare_enable(alg_data->clk); - if (ret) + if (ret) { + of_node_put(alg_data->adapter.dev.of_node); return ret; + } freq = clk_get_rate(alg_data->clk); @@ -707,14 +713,17 @@ static int i2c_pnx_probe(struct platform_device *pdev) out_clock: clk_disable_unprepare(alg_data->clk); + of_node_put(alg_data->adapter.dev.of_node); return ret; } static void i2c_pnx_remove(struct platform_device *pdev) { struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); + struct device_node *node = alg_data->adapter.dev.of_node; i2c_del_adapter(&alg_data->adapter); + of_node_put(node); clk_disable_unprepare(alg_data->clk); }