From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 368833803F4 for ; Tue, 18 Aug 2026 23:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787095087; cv=none; b=FJMr83ixWnVy4QKXBEhqbXPLejoEk4NDRy8n+KIGJ515rcT1wOeLNm1qx0bdvDOGSQhq2+G4aVi3gAXQMgLOSG23FkYc/EJIOKKobOfMuQZtqFcx+/kZY7mlsjUQ3Q6h+w4zTbHjy6WDckZ4LSoeqPTz4zZvG4vLMeIGY0A0ziE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787095087; c=relaxed/simple; bh=a8IOTYHpzARDBkDXw7Oai/tzL+r3gsDh+8SANcfGXjg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Il3WtNuLqbbm5sDySlv5vPygY4HWEKq5s7WPeaOgcpaTendVZTTLbaESVebW0kiCRsEDP+ypZhKFoTosjl0V5wNhrRXeXCqGvi72T2TiAQr+TJbVckodlCSzeB6V7zuSljZOsHVcChb8BEUWKifQ6k8CazN/VULAPqbvfjQoaw0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=CGNmYkqK; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="CGNmYkqK" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-5b2a1fd0ab0so45144e87.0 for ; Tue, 18 Aug 2026 16:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1787095082; x=1787699882; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=azicBGUhuLKBlVAXIqSFD4EKWplTYg8gpsiCO/t2g/Q=; b=CGNmYkqKQWoKGH41Id2BAn7W9SO5PFWE/QIFxaclbUx3fZJiZSciMddLrVApf7/nYo EZZV7oqBqEUhXu2Y/lL5n3uqw8ByTxjAmT19Hs9+6+glt7zKHN2BbJxjywX+YcsrXLBr csA+Xt5xDYlCM8I6U0FpLBmLaE6PC/xj+9ZuFGVT9YQNE5MQsYioFvS44VoVoQIadBox ME0IslyHnd1Uv46o0LGmFerfwZSJ805gDaKuwfvITN4Gj37z8kLNs5Ba6hBDEuu3AtzG lhHFNi/eaZZ7RzpPGlAz0UXgPsGgPz6wgL+eJR4ioLfFbsjoiv2frOAlq0czNsrgsNBd /inA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787095082; x=1787699882; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:subject:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=azicBGUhuLKBlVAXIqSFD4EKWplTYg8gpsiCO/t2g/Q=; b=act9XDM1lyvLRGzKrmZh0GBS0y864kQJ98CQVrCN5plAfjGN0QT72V3mqS2tHDBXCV ZE+w19O9IMCPETKzYnVLfoDDN1dg2Nch4mRnYHsOVvRDufebpPmr+lGXcOrMV7ubQ5+l n+Nt9V1qob8zgVRfsNLDobjEhC1BnbcKEH0kBXkuazWvNmu7mKuVQxHX9TlkEcoffZEr K2kPjtiaceezws0EGCP/EnShTgTjqIP/bZlQSdTlduJgF0IPTnE8zldTolBJH3fpmJEW iGRb4JNu/4YPsGT8gOWw9hlhuoMf6UN8piBRf6cVJ3vt/7R6vI5+23bR7hGnbMPROvz7 9yWA== X-Forwarded-Encrypted: i=1; AHgh+RrE8qJ2DMVUziWjTQQm1G8wv47hCYB+iZdN+YLUhTI9weMxLQ6bFDl8uSQzDWK97yj6mmxi1xEdkvPFXvQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwOd4lwboncp5Th+46d23cYX0p759dOMBxwt9A752JNbmnnsPde jSVqS/6upBh0Op1ioZwi9jITk4xFR70YcVDBTYZ10yFkFi2VKyO9ayfOLFvxAx1Hd0Q= X-Gm-Gg: AR+sD13tR2MoabHdzAXpPw7SLQa6C+ZG31Lzllm0Kh+gk83bXosjGO4gHy7jimHGP87 QEZ8XwVGKFbzqxCAWNHln3PKPqhuANkWDi2hGMF3r+Up3D+4hrx3SEdU8Brwma7MWI32HScBnYC c1MkZA5LVE8IcFSoK/kCHfHJoOJCt5CGpulZf07plcBWMa3GnE3Xjaw3DvbqsgKeg2EgvpEThiS VVfEC2PNgB/nSq8zHiaR1X8sxPzHxxx3MnDuVYWYvLlQ/kxVjhftK4QZ8QBuq2EYM8XcywJaFNE o/TkO4M22uQBNA8k4wMj2q3Zy93Y+A3DjZxoy0X5zDKARVhalr40odGJNlh4Xzq6HoXIYD1t6zX dvwDXVgva3kYpTwe45+BWJDkI6FI7F+QmzabIvlNUHgUOGnnYkjlbveJ9zOqE7Y6Geyi7idl8mj zPD2y3bMR6Zb747X3jq+nPV3CKn8VrqfTVjFPCq/iN1LxbDk9H5HZgVNa9ngccVKgpPYG0SwuDg W4+dwXdXaemcggvgHZDnJnHjcJzIqsQ1KO5kKqxuQ== X-Received: by 2002:a05:6512:31cf:b0:5ae:cfd3:4753 with SMTP id 2adb3069b0e04-5b478bdf314mr34845e87.3.1787095082233; Tue, 18 Aug 2026 16:18:02 -0700 (PDT) Received: from [192.168.1.100] (91-159-24-186.elisa-laajakaista.fi. [91.159.24.186]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b47885ac3esm59601e87.28.2026.08.18.16.18.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Aug 2026 16:18:01 -0700 (PDT) Message-ID: Date: Wed, 19 Aug 2026 02:18:00 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove() To: Liu Zhenlong , linux-i2c@vger.kernel.org Cc: konrad.dybcio@oss.qualcomm.com, stable@vger.kernel.org, Loic Poulain , Robert Foss , Andi Shyti , Bjorn Andersson , Wolfram Sang , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260815140931.53297-1-dragonliu2018@gmail.com> <20260818175750.4205-1-dragonliu2018@gmail.com> From: Vladimir Zapolskiy In-Reply-To: <20260818175750.4205-1-dragonliu2018@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Liu. On 8/18/26 20:57, Liu Zhenlong wrote: > The of_node_put() matching of_node_get() runs after i2c_del_adapter(), > whose trailing memset() zeroes adap->dev and thus adap->dev.of_node, > making the put a no-op and leaking the node on every adapter removal > and error cleanup. > > Use a devm action: the pointer is captured at registration, out of > reach of that memset(), and devres runs the put once on probe failure > and detach, replacing the three manual of_node_put() calls. The > setup loop uses the scoped iterator form so the child node is released > automatically if devm_add_action_or_reset() fails mid-loop. > > Suggested-by: Konrad Dybcio > Fixes: 02a4a69667a2 ("i2c: qcom-cci: don't put a device tree node before i2c_add_adapter()") > Cc: stable@vger.kernel.org > Assisted-by: Claude:claude-opus-5 > Signed-off-by: Liu Zhenlong > --- > Changes in v2: > - Rework the fix to use a devm action (cci_put_of_node) instead of > caching the pointer before i2c_del_adapter(), per Konrad Dybcio. > The pointer is captured at registration, out of reach of the > memset() in i2c_del_adapter(); the three manual of_node_put() calls > are removed. > - Use for_each_available_child_of_node_scoped() so the child > reference is released if devm_add_action_or_reset() fails mid-loop. > > drivers/i2c/busses/i2c-qcom-cci.c | 20 +++++++++++--------- > 1 file changed, 11 insertions(+), 9 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c > index bdeda3979c48..d3528c7d15bd 100644 > --- a/drivers/i2c/busses/i2c-qcom-cci.c > +++ b/drivers/i2c/busses/i2c-qcom-cci.c > @@ -497,10 +497,14 @@ static const struct dev_pm_ops qcom_cci_pm = { > SET_RUNTIME_PM_OPS(cci_suspend_runtime, cci_resume_runtime, NULL) > }; > > +static void cci_put_of_node(void *data) > +{ > + of_node_put(data); > +} > + > static int cci_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > - struct device_node *child; > struct resource *r; > struct cci *cci; > int ret, i; > @@ -516,7 +520,7 @@ static int cci_probe(struct platform_device *pdev) > if (!cci->data) > return -ENOENT; > > - for_each_available_child_of_node(dev->of_node, child) { > + for_each_available_child_of_node_scoped(dev->of_node, child) { > struct cci_master *master; > u32 idx; > > @@ -537,6 +541,9 @@ static int cci_probe(struct platform_device *pdev) > master->adap.algo = &cci_algo; > master->adap.dev.parent = dev; > master->adap.dev.of_node = of_node_get(child); > + ret = devm_add_action_or_reset(dev, cci_put_of_node, child); I believe the new cci_put_of_node() and the original of_node_put() functions are type compatible, therefore a function type cast could be sufficient here: (void (*)(void *))of_node_put In any case the change seems to correct, thank you for the fix! Reviewed-by: Vladimir Zapolskiy -- Best wishes, Vladimir