From nobody Wed Dec 17 18:00:08 2025 Received: from pv50p00im-ztdg10021101.me.com (pv50p00im-ztdg10021101.me.com [17.58.6.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6F6D171BB for ; Mon, 16 Dec 2024 00:41:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309673; cv=none; b=jOcuzLYCWILts9WFstovQRR1djW/reJKXmM5g156iAVPiotE6semxYQoL/wZKYKinSH8Ku22NYszCnU73SqtPjND1jwyqF/eaLGPTP6zql7CJ2jt1kp6Mv/hDivGzeNEYAziSCAtpu1qNWaA6kFFz+eyy03gHXotLq5cl9TLNh8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309673; c=relaxed/simple; bh=bW7CnirDx7zej4qtmPVX70ePmhN8Fwa34XfzNhqJIgY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lsK19lQY1FHocsTRUKltreQNRSAUIpMcLQw0TieewTbesiMkTMQ88v5bM8wRb/5hFagKYqe0SKCnOH39nSYeWlGJ6DUjYzlvDLBNMAfz+NR7Jvho1eAVJ0I5SyfaTqWl9HVzlr8bGvKNYoUsXdM1IkUn9rjSlrT9wo62/am6o9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=tUOSUB/Q; arc=none smtp.client-ip=17.58.6.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="tUOSUB/Q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734309671; bh=fS1N4Pd37szoJLeCtWm7wLGDRu5IJW7gYY3s1rjRIUI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=tUOSUB/Qtm1vG+NycGLcSdyErM2mxAoB4ldYO5hYpjeA33dP32KfxulWJVE/bTdU3 I5FB9CCucEZ2SEUbH4wEgqvNluAd0GPVvmhqdq69kyfsBvZWaEiqkT4k8SUgg8eEWF Xko7Czd33lo1gx+W2CtqYUQWQ/jgYFIxtca/L4ezZYLX4DeiH/s+jSU6gxoMGFQbJH TukbvbtalBNvL+FL7/5QKNmFsHr+BiJgLv3JjhovA+LJXJynSVZRHextc3HM/QV0da b8lS1GxUzwOyuollJizVqXTzPFmt13xXimvywsX1OHVbNMe+tBqPI6Gt3D6gyDbAf6 B6paJLRWV0NdQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021101.me.com (Postfix) with ESMTPSA id 95BCED00191; Mon, 16 Dec 2024 00:41:07 +0000 (UTC) From: Zijun Hu Date: Mon, 16 Dec 2024 08:40:40 +0800 Subject: [PATCH v2 1/7] of: Fix API of_find_node_opts_by_path() finding OF device node failure Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241216-of_core_fix-v2-1-e69b8f60da63@quicinc.com> References: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> In-Reply-To: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> To: Rob Herring , Saravana Kannan , Maxime Ripard , Robin Murphy , Grant Likely Cc: Zijun Hu , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Zijun Hu , stable@vger.kernel.org X-Mailer: b4 0.14.2 X-Proofpoint-GUID: -XcEA3KUb7_IsMMnXqimvOsx4-FGHuwF X-Proofpoint-ORIG-GUID: -XcEA3KUb7_IsMMnXqimvOsx4-FGHuwF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-15_10,2024-12-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxlogscore=952 adultscore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412160002 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu API of_find_node_opts_by_path() fails to find OF device node when its @path parameter have pattern below: "alias-name/node-name-1/.../node-name-N:options". The reason is that alias name length calculated by the API is wrong, as explained by example below: "testcase-alias/phandle-tests/consumer-a:testaliasoption". ^ ^ ^ 0 14 39 The right length of alias 'testcase-alias' is 14, but the result worked out by the API is 39 which is obvious wrong. Fix by using index of either '/' or ':' as the length who comes earlier. Fixes: 75c28c09af99 ("of: add optional options parameter to of_find_node_by= _path()") Cc: stable@vger.kernel.org Signed-off-by: Zijun Hu --- drivers/of/base.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index d2d021f7cf5809b6e765c14911bda0df55f36ca9..bf18d5997770eb81e47e749198d= d505a35203d10 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -893,10 +893,10 @@ struct device_node *of_find_node_opts_by_path(const c= har *path, const char **opt /* The path could begin with an alias */ if (*path !=3D '/') { int len; - const char *p =3D separator; + const char *p =3D strchrnul(path, '/'); =20 - if (!p) - p =3D strchrnul(path, '/'); + if (separator && separator < p) + p =3D separator; len =3D p - path; =20 /* of_aliases must not be NULL */ --=20 2.34.1 From nobody Wed Dec 17 18:00:08 2025 Received: from pv50p00im-ztdg10021101.me.com (pv50p00im-ztdg10021101.me.com [17.58.6.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FBD81DDEA for ; Mon, 16 Dec 2024 00:41:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309677; cv=none; b=SpG0azHj2LZQfgB9FpmfcMDGLy3Cqs8LbGW++9DKl2Otm61xOCIHACREZkpcZo+NEhG/zFdlWSHG6LfWy4tyZlne6Xum9wMpGwWkVNpwVq5C3JteG5+2yE0HvQS/1YuXXYGGh/6tI509NfUtAp25Iucywp8uSuxClANdg/9j770= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309677; c=relaxed/simple; bh=KMO14dnE9tRhaAGc5YxLFebssXtmFMt2M5jkVn0AjI4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gzwak+C02kKCF4JH911Ecz6NfQAiOYRkJ/Yz/IG4w7vZwaQyBY7FthvpXw4JW82mkFNLvTWsGuIUH4H3tqRd8zcpbaA9ToG5qWGlo7SB8Fgl9NaK/2OBT1Xn2DsytkQMvg1++RLjxlfCImEBhQp8+5aWpv8YNQxMYotLipW3XRM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=wjnrfhS3; arc=none smtp.client-ip=17.58.6.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="wjnrfhS3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734309676; bh=Fj6BdgBM2U8SqvVK8X/8qKlugmpUIDlPqiwGDV3HR8c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=wjnrfhS3Off0m322naodLBWNWpYBcMOYPCa3+HnTlB4LNtTgGJQN0AcJ2bKEgbfFW wIQdyzi12s2Kv68CIiObIDu0sa7N+reF3XKTTz0koJuMGmL1wlGfezUcLwaTItatk5 09jCi/lQzGjAjsIK0K4BpsNCD0co0t/oYXGZHsK1Qh2aZWOAOWSamZhF/NSwEDLgAP reKUp9h9Be8eo4aRHLmpXvAPcHFFYgZ8kxsSqVSxVC4jYHXtqMd9n1DL6x5P/IlwaW N592aA8/Qb7WXpZPxer1p9EOB+TrLYAS6O4keaT9k9yobeyB7J/C4uWLTLXmBp7zDl AhBvKtrYfOV2g== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021101.me.com (Postfix) with ESMTPSA id 42EFBD00211; Mon, 16 Dec 2024 00:41:11 +0000 (UTC) From: Zijun Hu Date: Mon, 16 Dec 2024 08:40:41 +0800 Subject: [PATCH v2 2/7] of: unittest: Add a test case for API of_find_node_opts_by_path() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241216-of_core_fix-v2-2-e69b8f60da63@quicinc.com> References: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> In-Reply-To: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> To: Rob Herring , Saravana Kannan , Maxime Ripard , Robin Murphy , Grant Likely Cc: Zijun Hu , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Proofpoint-GUID: dv7li9viv4lCM-e_YTdRfq5DVT4lJJKF X-Proofpoint-ORIG-GUID: dv7li9viv4lCM-e_YTdRfq5DVT4lJJKF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-15_10,2024-12-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxlogscore=992 adultscore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412160002 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu To test of_find_node_opts_by_path() take @path argument with pattern: "alias-name/node-name-1/.../node-name-N:options", for example: "testcase-alias/phandle-tests/consumer-a:testaliasoption" Signed-off-by: Zijun Hu --- drivers/of/unittest.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index daf9a2dddd7e0dbc680f708496b6dce6d23999cf..ed343509505f536436f8457bd20= 0ccc323acffdf 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -161,6 +161,15 @@ static void __init of_unittest_find_node_by_name(void) "option alias path test, subcase #1 failed\n"); of_node_put(np); =20 + np =3D of_find_node_opts_by_path("testcase-alias/phandle-tests/consumer-a= :testaliasoption", + &options); + name =3D kasprintf(GFP_KERNEL, "%pOF", np); + unittest(np && name && !strcmp("/testcase-data/phandle-tests/consumer-a",= name) && + !strcmp("testaliasoption", options), + "option alias path test, subcase #2 failed\n"); + of_node_put(np); + kfree(name); + np =3D of_find_node_opts_by_path("testcase-alias:testaliasoption", NULL); unittest(np, "NULL option alias path test failed\n"); of_node_put(np); --=20 2.34.1 From nobody Wed Dec 17 18:00:08 2025 Received: from pv50p00im-ztdg10021101.me.com (pv50p00im-ztdg10021101.me.com [17.58.6.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06CDF286A9 for ; Mon, 16 Dec 2024 00:41:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309682; cv=none; b=XuOfTAHwPiZahLE7+Ydqi3BydzPh/JSZOI9j2rraCQkIpVpzgS/Ba1C2Eb8W1CPpozT7abPegDjjSUlklT4L46RAOJZKu4AcoePEuUWmvfihu9B0+7cIyQMGtQjrbalcczJeEt4PUsbbxFSZK09+faWkcnJ/D/D3QeKL4uQ0o9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309682; c=relaxed/simple; bh=F7VAazrVJ3p7QlbMjlcZ0vd+3ltdvGaw1yJxrtSHdRM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jDoQeNGofvjKTTBRkHGJP4iR+/cF1uu58O4eWQ5+uqaXeBQzxELZ2+62da4m7mU9wr1zt8xr38rCleYTuqJvH/wrMlh9jMkMyci/uz9iogZYHEEVf9ZyH8Fx9yTeKVrtzxA6oIetTuNEkmW0dz18fOH7ssLPiXelzG1M8KqPKRQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=EvI2/3b7; arc=none smtp.client-ip=17.58.6.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="EvI2/3b7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734309680; bh=1qAwxeqobZh1wxnxdDloQZW9DdsopGVNulsZoYj9sn8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=EvI2/3b7vO79Td/eHUfdKoPN87R2WhhuUIUNJBuBxH4WZqajCNVMv3h+IvGnVSD+0 SfLHgRrxwTI7SGYGNjswEIi+XqNR+H0IV7GE7sPR5A06PWADZTXMwbOblk6xMAp/67 +NVfKQQ8SwaSC5MH7VMtTtRBjFQXwAhOcjZIln4g+gUHiHZ6I/zagzIIfQaBQ6MzI5 YExaQxuV0Ve2Jbrkvx9OFeYgjyKiOQRUDJNtT87pWLzzXOIOE7AYiu4jFebwBqhxFa 515C4gFGmlIcueerpOE0pCIAh5SGDLE8euGVxAhRV/Zgpci5urNX1A2qyE1bV5TtyF YWZ6kKcMdYHmg== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021101.me.com (Postfix) with ESMTPSA id AF7E4D00191; Mon, 16 Dec 2024 00:41:16 +0000 (UTC) From: Zijun Hu Date: Mon, 16 Dec 2024 08:40:42 +0800 Subject: [PATCH v2 3/7] of: Correct child specifier used as input of the 2nd nexus node Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241216-of_core_fix-v2-3-e69b8f60da63@quicinc.com> References: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> In-Reply-To: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> To: Rob Herring , Saravana Kannan , Maxime Ripard , Robin Murphy , Grant Likely Cc: Zijun Hu , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Zijun Hu , stable@vger.kernel.org X-Mailer: b4 0.14.2 X-Proofpoint-GUID: -ykJM0NGSyyXqdyLVu9ZY0Qb8rFOwFSa X-Proofpoint-ORIG-GUID: -ykJM0NGSyyXqdyLVu9ZY0Qb8rFOwFSa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-15_10,2024-12-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 adultscore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412160002 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu API of_parse_phandle_with_args_map() will use wrong input for nexus node Nexus_2 as shown below: Node_1 Nexus_1 Nexus_2 &Nexus_1,arg_1 -> arg_1,&Nexus_2,arg_2' -> &Nexus_2,arg_2 -> arg_2,... map-pass-thru=3D<...> Nexus_1's output arg_2 should be used as input of Nexus_2, but the API wrongly uses arg_2' instead which !=3D arg_2 due to Nexus_1's map-pass-thru. Fix by always making @match_array point to @initial_match_array into which to store nexus output. Fixes: bd6f2fd5a1d5 ("of: Support parsing phandle argument lists through a = nexus node") Cc: stable@vger.kernel.org Signed-off-by: Zijun Hu --- drivers/of/base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index bf18d5997770eb81e47e749198dd505a35203d10..969b99838655534915882abe358= 814d505c6f748 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1536,7 +1536,6 @@ int of_parse_phandle_with_args_map(const struct devic= e_node *np, * specifier into the out_args structure, keeping the * bits specified in -map-pass-thru. */ - match_array =3D map - new_size; for (i =3D 0; i < new_size; i++) { __be32 val =3D *(map - new_size + i); =20 @@ -1545,6 +1544,7 @@ int of_parse_phandle_with_args_map(const struct devic= e_node *np, val |=3D cpu_to_be32(out_args->args[i]) & pass[i]; } =20 + initial_match_array[i] =3D val; out_args->args[i] =3D be32_to_cpu(val); } out_args->args_count =3D list_size =3D new_size; --=20 2.34.1 From nobody Wed Dec 17 18:00:08 2025 Received: from pv50p00im-ztdg10021101.me.com (pv50p00im-ztdg10021101.me.com [17.58.6.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95B6E433B1 for ; Mon, 16 Dec 2024 00:41:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309686; cv=none; b=K65IijcLu7g4juTj2yoIiqNQdP5eE0fOOBuhY+ErRG8bM2gA9gFQAXVK74iWFtIH7XXD/N7pbpCJwqCZ2H3j7zciBGku4ysksx/6TuOPbcbPg+w2MmPulO61yg7NYtDUio/PP1ZYPWLAmR/34Hy2m/FWFEn0qXlGFgGnId/yIPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309686; c=relaxed/simple; bh=SsxIe7B8Ubifh8yxK4TNdpGpDInnToF21ZEilh+Nrlw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AtdlUFrzsDVetiOgXPVSpBs7/smZqi05arVqv6xERQK5F4IMZeFznh8aAltkR+2r/bnIvz+1n6kfhOINTM8A/ADWkjQKIbAC8wy5ptYyTP8KML21+RJYGS9xKKNh/Cxtsg3qTfT0UZ4xabwbS8fc13MFx5fFEetlhdN+B9Anzzc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=bcDO002/; arc=none smtp.client-ip=17.58.6.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="bcDO002/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734309685; bh=skHmLwNtPEPyB8SzViTBhLp6k6+TIgi9ScSYe4Bfhms=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=bcDO002/ZMap/j5xp+inXucALxs9JebnMRwDuOV6gS+5ycMPAr+w6bPiSlhQilEh6 XB2UXgufVYcSrrKnlCBDQzvC1M5vd5bAU9+gKfHgcrj/AH9505IAm56EwXbXl+h01w SECGGPz3KsciPGVpmyLNJWVN9gyzTDnqq9XGy72UKnEZQ51gcTcwc7wDlsF7lHz3Om 9/4LXgINqar6cMyAo5JosImZ9AGO55j8Xq6/UPgWS6YxmwkHSia9UprLBx9Ff0K3uD o6XQMPSCWnFEP3cN6DuZ8FIZ2A6qCA1nXdNsgeIltOp/92MRk7bj+vtr9VNycloFX/ JKSG9E4OLqOjg== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021101.me.com (Postfix) with ESMTPSA id 64B8FD0028A; Mon, 16 Dec 2024 00:41:21 +0000 (UTC) From: Zijun Hu Date: Mon, 16 Dec 2024 08:40:43 +0800 Subject: [PATCH v2 4/7] of: Exchange implementation between of_property_present() and of_property_read_bool() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241216-of_core_fix-v2-4-e69b8f60da63@quicinc.com> References: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> In-Reply-To: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> To: Rob Herring , Saravana Kannan , Maxime Ripard , Robin Murphy , Grant Likely Cc: Zijun Hu , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Proofpoint-GUID: KkO7ASRbB1myZ90BDPATCssXqKJrUehG X-Proofpoint-ORIG-GUID: KkO7ASRbB1myZ90BDPATCssXqKJrUehG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-15_10,2024-12-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxlogscore=848 adultscore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412160002 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu of_property_present() is to check if a property is present or not, and it should be applicable for all kinds of property, but it calls of_property_read_bool() to implement the function, so narrows its property scope to only bool type. Fix by exchanging implementation, namely, changing call chain from: of_property_present() -> of_property_read_bool() -> of_find_property() to : of_property_read_bool() -> of_property_present() -> of_find_property() which looks more logical as well. Signed-off-by: Zijun Hu --- include/linux/of.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/include/linux/of.h b/include/linux/of.h index f921786cb8ac782286ed5ff4425a35668204d050..7b0da8d352dffd8b87299890328= 2119b6164a5bc 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1243,17 +1243,16 @@ static inline int of_property_read_string_index(con= st struct device_node *np, } =20 /** - * of_property_read_bool - Find a property - * @np: device node from which the property value is to be read. + * of_property_present - Test if a property is present in a node + * @np: device node to search for the property. * @propname: name of the property to be searched. * - * Search for a boolean property in a device node. Usage on non-boolean - * property types is deprecated. + * Test for a property present in a device node. * * Return: true if the property exists false otherwise. */ -static inline bool of_property_read_bool(const struct device_node *np, - const char *propname) +static inline bool of_property_present(const struct device_node *np, + const char *propname) { const struct property *prop =3D of_find_property(np, propname, NULL); =20 @@ -1261,17 +1260,19 @@ static inline bool of_property_read_bool(const stru= ct device_node *np, } =20 /** - * of_property_present - Test if a property is present in a node - * @np: device node to search for the property. + * of_property_read_bool - Find a property + * @np: device node from which the property value is to be read. * @propname: name of the property to be searched. * - * Test for a property present in a device node. + * Search for a boolean property in a device node. Usage on non-boolean + * property types is deprecated. * * Return: true if the property exists false otherwise. */ -static inline bool of_property_present(const struct device_node *np, const= char *propname) +static inline bool of_property_read_bool(const struct device_node *np, + const char *propname) { - return of_property_read_bool(np, propname); + return of_property_present(np, propname); } =20 /** --=20 2.34.1 From nobody Wed Dec 17 18:00:08 2025 Received: from pv50p00im-ztdg10021101.me.com (pv50p00im-ztdg10021101.me.com [17.58.6.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BB4555896 for ; Mon, 16 Dec 2024 00:41:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309691; cv=none; b=gCSsEw7FGo+0bF9fVmwrCXBDyainsKki60LFy6xicYbuhM0EbP9UJ/ZtHzKwO0d8zr77sxMDz6shCPkj+7+yaddyvQWcR5ThWs02/kzxqytsxuDpHDcSACGdFn+dIWXKn26sSrfCZA38HCoR8kByP5K7G0Zh+L7KWJnSzogQ3Iw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309691; c=relaxed/simple; bh=bc6lzGgIEQ1cBkFQ7KiFXTLCSQur3IQsBxM4lNEjjT8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s3/29IOYLMmsOIENV6/77XMqFeX1W3aIm+7RfFUON5WCIhGYi3TICu1NZq1gJP0HVmrXXH+xDIe3EInX3d1AbtMf19ntkrvztA/uZX0TZw4fhRXNvgO86a90Tw2TVNxLREg2V5Egujqe5aIkOmMaI6xzKdLWNp74UF/OnoYKvhA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=Ks3TG7R6; arc=none smtp.client-ip=17.58.6.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="Ks3TG7R6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734309689; bh=2a/BC8NRIh0uh85HCJfRd8BdlVkBEXk7Aqyv3gynJAM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=Ks3TG7R6ZfDkLmx0+3HcuV8JTnhIN+XzZrRD/4AYl+0jXYZFp2dQpBOP3itsQfSTi RFTK2+W0ZrnjsfsQC5QlKcHcJmNRhkluHc1ORxKACFpuGxABCfYp4NgUOw2fKuugCi j9AT/XMhtJy5gn9Qe0i8ShItRpu3k+T7GzJO3PIYFj23p+f0eRL3WHg4nfz5BaA6dD fMrD4iwA6fdtSuXaUKHUGtiSMisZRs44PiQpiHf7ibsQ3sdf1ZJiNUSe+Tn/eqU5Tr xhtSlPw+onaACfS0iw2HBTSRzOwjjtTAEcwPAeYsfmiNOEs7FYo9aQQLz8P1jL8jud Bass6e6eH1KCw== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021101.me.com (Postfix) with ESMTPSA id D2B51D002CC; Mon, 16 Dec 2024 00:41:25 +0000 (UTC) From: Zijun Hu Date: Mon, 16 Dec 2024 08:40:44 +0800 Subject: [PATCH v2 5/7] of: Fix available buffer size calculating error in API of_device_uevent_modalias() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241216-of_core_fix-v2-5-e69b8f60da63@quicinc.com> References: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> In-Reply-To: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> To: Rob Herring , Saravana Kannan , Maxime Ripard , Robin Murphy , Grant Likely Cc: Zijun Hu , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Proofpoint-GUID: 9VUYbPiFtn5lGPtNOWA3onl0jZx4Gp1U X-Proofpoint-ORIG-GUID: 9VUYbPiFtn5lGPtNOWA3onl0jZx4Gp1U X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-15_10,2024-12-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 adultscore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412160002 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu of_device_uevent_modalias() saves MODALIAS value from offset (@env->buflen - 1), so the available buffer size should be (sizeof(@env->buf) - @env->buflen + 1), but it uses the wrong size (sizeof(@env->buf) - @env->buflen). Fix by using size of space from char '\0' inclusive which ends "MODALIAS=3D= ". Fixes: dd27dcda37f0 ("of/device: merge of_device_uevent") Signed-off-by: Zijun Hu --- drivers/of/device.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index edf3be1972658f6dc165f577da53b10c7eebc116..f24c19e7aba8e01656f503ae328= a4e08aab5a5f3 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -257,6 +257,7 @@ EXPORT_SYMBOL_GPL(of_device_uevent); int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent= _env *env) { int sl; + int pos; =20 if ((!dev) || (!dev->of_node) || dev->of_node_reused) return -ENODEV; @@ -265,13 +266,18 @@ int of_device_uevent_modalias(const struct device *de= v, struct kobj_uevent_env * if (add_uevent_var(env, "MODALIAS=3D")) return -ENOMEM; =20 - sl =3D of_modalias(dev->of_node, &env->buf[env->buflen-1], - sizeof(env->buf) - env->buflen); + /* + * @env->buflen is pointing to the char after '\0' now + * override the '\0' to save MODALIAS value. + */ + pos =3D env->buflen - 1; + sl =3D of_modalias(dev->of_node, &env->buf[pos], + sizeof(env->buf) - pos); if (sl < 0) return sl; - if (sl >=3D (sizeof(env->buf) - env->buflen)) + if (sl >=3D (sizeof(env->buf) - pos)) return -ENOMEM; - env->buflen +=3D sl; + env->buflen =3D pos + sl + 1; =20 return 0; } --=20 2.34.1 From nobody Wed Dec 17 18:00:08 2025 Received: from pv50p00im-ztdg10021101.me.com (pv50p00im-ztdg10021101.me.com [17.58.6.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06C358F49 for ; Mon, 16 Dec 2024 00:42:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309725; cv=none; b=fJb8kSoeaA+9TqOixUulaTDKuSXMFKskMAg84E7WFlU/w3WqCMi6ac3hSiAxzZQ7NYQSlWWKKR3x2VAbfcaVwiEaAa3YpGHeVsnggFeobN8puVVXGI4rFgLCFt+FxT5KENzc79QnHpaQcbbLa3HOO0S1n+ah866Z2LBk9cACnQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309725; c=relaxed/simple; bh=nSYXCv7Z/bKVTSvJE3MUbp8NkYW76YNJJBAJAlkRWY4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tD5McTiCk3OqFG9ZRn5oBw8ueo00RtRIgthy60vTNiWJSsX8SjZOH5/LbVNqbvtDuPKKFjoAaRtavR/a8JMjGKXwjHspsHW1DubsT3/QjQyxHnizSf/ynZBPQQ/jsxWCMID4zCASFr15nMDCrw4jP8JuhYgj67oeA5IFdtRFDk0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=EdnHadMU; arc=none smtp.client-ip=17.58.6.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="EdnHadMU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734309723; bh=Ak4E137BxRWwHua7Mm4mhu/aSYLHuL/rTY58sloG2vo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=EdnHadMUmgr7r4hIOT4FUgy7fRvgdd16kUhJv2os4pjD+CqUWxucoGbcFPsT7OzYf THM78NPM80HSMy2SHayB1Nut6wFpbHvIgxnyXvxuoCGM9dwoUIlM4Gp5k0YXBZ7G/t YoSaXyyOUbDacKCefMoUApi0+HKHopMSh9Inqfz4cIUaO+lT5L0Ld+95E9t7zl6D22 AFRzEHS8ZA4+hOqdHRKSNzhktrAXDSBMV2E8qD+oYJRJd4NWqwEg4cQJgQ50CYIP+H C1negPcaY8S59P2+wQMKssu1+ZR2dw090h67vUZos955bA1KCLZ/MZgj3T2AXQFu67 LWFdcc4ocDnNg== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021101.me.com (Postfix) with ESMTPSA id 3F7F5D0015A; Mon, 16 Dec 2024 00:41:29 +0000 (UTC) From: Zijun Hu Date: Mon, 16 Dec 2024 08:40:45 +0800 Subject: [PATCH v2 6/7] of: Fix potential wrong MODALIAS uevent value Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241216-of_core_fix-v2-6-e69b8f60da63@quicinc.com> References: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> In-Reply-To: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> To: Rob Herring , Saravana Kannan , Maxime Ripard , Robin Murphy , Grant Likely Cc: Zijun Hu , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu API of_device_uevent_modalias() makes uevent "MODALIAS=3DITS_VALUE" in two steps, namely, produces "MODALIAS=3D" with add_uevent_var() fistly, then remainning "ITS_VALUE" with of_modalias() finally, and that may result in various wrong uevents as explained below: "MODALIAS=3D\0" // @env->buf is full after the 1st step. "MODALIAS=3DITS_\0" // @env->buf is not enough during 2nd step. "MODALIAS=3DITS_VAR=3DVAR_VALUE\0" // another uevent "VAR=3DVAR_VALUE" come= s. The API depends on uevent internal design, so is not good practice as well. Fix by: 1) Respin the callee of_modalias() with new prototype which is friendly with its callers. 2) Invoke add_uevent_var() to make the whole MODALIAS uevent. 3) Adapt new of_modalias() for its other callers. BTW, there are no external callers of of_modalias() now. Closes: https://lore.kernel.org/all/CAL_JsqL+CRmCQMzcF4-A-PRBrCsfK8nduJtOO= =3DRrsDtCUUR7og@mail.gmail.com Signed-off-by: Zijun Hu --- drivers/of/device.c | 39 +++++++------------- drivers/of/module.c | 103 +++++++++++++++++++++++++++++++-----------------= ---- include/linux/of.h | 5 +-- 3 files changed, 78 insertions(+), 69 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index f24c19e7aba8e01656f503ae328a4e08aab5a5f3..6355707c200da9ced354132528a= dbcce24121247 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -195,19 +195,18 @@ EXPORT_SYMBOL(of_device_get_match_data); ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len) { ssize_t sl; + char *ptr __free(kfree) =3D NULL; =20 if (!dev || !dev->of_node || dev->of_node_reused) return -ENODEV; =20 - sl =3D of_modalias(dev->of_node, str, len - 2); - if (sl < 0) - return sl; - if (sl > len - 2) + ptr =3D of_modalias(dev->of_node, &sl); + if (IS_ERR(ptr)) + return PTR_ERR(no_free_ptr(ptr)); + if (sl + 2 > len) return -ENOMEM; =20 - str[sl++] =3D '\n'; - str[sl] =3D 0; - return sl; + return snprintf(str, len, "%s\n", ptr); } EXPORT_SYMBOL_GPL(of_device_modalias); =20 @@ -256,30 +255,20 @@ EXPORT_SYMBOL_GPL(of_device_uevent); =20 int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent= _env *env) { - int sl; - int pos; + int ret; + char *ptr; =20 if ((!dev) || (!dev->of_node) || dev->of_node_reused) return -ENODEV; =20 - /* Devicetree modalias is tricky, we add it in 2 steps */ - if (add_uevent_var(env, "MODALIAS=3D")) - return -ENOMEM; + ptr =3D of_modalias(dev->of_node, NULL); + if (IS_ERR(ptr)) + return PTR_ERR(ptr); =20 - /* - * @env->buflen is pointing to the char after '\0' now - * override the '\0' to save MODALIAS value. - */ - pos =3D env->buflen - 1; - sl =3D of_modalias(dev->of_node, &env->buf[pos], - sizeof(env->buf) - pos); - if (sl < 0) - return sl; - if (sl >=3D (sizeof(env->buf) - pos)) - return -ENOMEM; - env->buflen =3D pos + sl + 1; + ret =3D add_uevent_var(env, "MODALIAS=3D%s", ptr); =20 - return 0; + kfree(ptr); + return ret; } EXPORT_SYMBOL_GPL(of_device_uevent_modalias); =20 diff --git a/drivers/of/module.c b/drivers/of/module.c index 1e735fc130ad3ea9046f08bfab2cc9a07914e633..03a2b1b381e5b353b6699dac183= c03186afb0486 100644 --- a/drivers/of/module.c +++ b/drivers/of/module.c @@ -8,71 +8,92 @@ #include #include =20 -ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len) +/* + * of_modalias - get MODALIAS string value for a OF device node + * @np: the OF device node + * @lenp: MODALIAS string length returned if set, exclude '\0' + * + * This function gets MODALIAS value for a device node. + * + * Returns MODALIAS string on success, or ERR_PTR() on error. + * + * Note: please kfree successful return value afer using it. + */ +char *of_modalias(const struct device_node *np, ssize_t *lenp) { const char *compat; char *c; struct property *p; ssize_t csize; ssize_t tsize; + char *str =3D NULL; + ssize_t len =3D 0; + ssize_t pos =3D 0; + int counting =3D 1; + + if (lenp) + *lenp =3D 0; =20 /* - * Prevent a kernel oops in vsnprintf() -- it only allows passing a - * NULL ptr when the length is also 0. Also filter out the negative - * lengths... + * Two cycles controlled by @counting, the fist cycle counts + * chars, the second saves chars. */ - if ((len > 0 && !str) || len < 0) - return -EINVAL; + do { + /* Name & Type */ + /* %p eats all alphanum characters, so %c must be used here */ + csize =3D snprintf(str + pos, len - pos, "of:N%pOFn%c%s", np, 'T', + of_node_get_device_type(np)); + if (counting) + tsize =3D csize; + else + pos +=3D csize; =20 - /* Name & Type */ - /* %p eats all alphanum characters, so %c must be used here */ - csize =3D snprintf(str, len, "of:N%pOFn%c%s", np, 'T', - of_node_get_device_type(np)); - tsize =3D csize; - if (csize >=3D len) - csize =3D len > 0 ? len - 1 : 0; - len -=3D csize; - str +=3D csize; + of_property_for_each_string(np, "compatible", p, compat) { + csize =3D snprintf(str + pos, len - pos, "C%s", compat); + if (counting) { + tsize +=3D csize; + continue; + } =20 - of_property_for_each_string(np, "compatible", p, compat) { - csize =3D snprintf(str, len, "C%s", compat); - tsize +=3D csize; - if (csize >=3D len) - continue; - for (c =3D str; c; ) { - c =3D strchr(c, ' '); - if (c) - *c++ =3D '_'; + for (c =3D str + pos; c; ) { + c =3D strchr(c, ' '); + if (c) + *c++ =3D '_'; + } + pos +=3D csize; } - len -=3D csize; - str +=3D csize; - } =20 - return tsize; + if (counting) { + /* Include '\0' of MODALIAS string. */ + len =3D tsize + 1; + /* MODALIAS value is too long */ + if (unlikely(len > 2048)) + return ERR_PTR(-EINVAL); + + str =3D kmalloc(len, GFP_KERNEL); + if (!str) + return ERR_PTR(-ENOMEM); + } + + } while (counting--); + + if (lenp) + *lenp =3D tsize; + return str; } =20 int of_request_module(const struct device_node *np) { char *str; - ssize_t size; int ret; =20 if (!np) return -ENODEV; =20 - size =3D of_modalias(np, NULL, 0); - if (size < 0) - return size; - - /* Reserve an additional byte for the trailing '\0' */ - size++; - - str =3D kmalloc(size, GFP_KERNEL); - if (!str) - return -ENOMEM; + str =3D of_modalias(np, NULL); + if (IS_ERR(str)) + return PTR_ERR(str); =20 - of_modalias(np, str, size); - str[size - 1] =3D '\0'; ret =3D request_module(str); kfree(str); =20 diff --git a/include/linux/of.h b/include/linux/of.h index 7b0da8d352dffd8b872998903282119b6164a5bc..2fcc12de4a9178276a24cd4d6c9= 75495b9eb04a2 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -382,7 +382,7 @@ extern int of_count_phandle_with_args(const struct devi= ce_node *np, const char *list_name, const char *cells_name); =20 /* module functions */ -extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_= t len); +char *of_modalias(const struct device_node *np, ssize_t *lenp); extern int of_request_module(const struct device_node *np); =20 /* phandle iterator functions */ @@ -762,8 +762,7 @@ static inline int of_count_phandle_with_args(const stru= ct device_node *np, return -ENOSYS; } =20 -static inline ssize_t of_modalias(const struct device_node *np, char *str, - ssize_t len) +static inline char *of_modalias(const struct device_node *np, ssize_t *len= p) { return -ENODEV; } --=20 2.34.1 From nobody Wed Dec 17 18:00:08 2025 Received: from pv50p00im-ztdg10021101.me.com (pv50p00im-ztdg10021101.me.com [17.58.6.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1ABF17C64 for ; Mon, 16 Dec 2024 00:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309728; cv=none; b=S9CywjaOtY8wD/5sfYhFV0bZX/cAtLvMPM4UuEOAtnS3Hi1/sitVesGDghrbAYCBgNgSbhvUttYeqRFZgM/G1DP99LxZo9zBnk5sjKfkMim+6J482X+is5CADq+eSeLzlGreTE1dGtHZBzDLlPARbWm9cbFJl16r2OhEJwXk7Q0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734309728; c=relaxed/simple; bh=PwJ9PFqWEHq/TOsJswnCkJZzL8dsehuJu7Miuk9kvTw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GzUbJrgp9IYNpHCQ46HIpkeS4t52Oh6Sr/4VQeYPc3EFJYjHbPnpF9zpMrWh0Wxb6qQfwtVVvwr3ZAt+2v17ZDl5cbIybuKBXyO4RjqvyBlumizgDhkAwxBSR2h3mrxf2bsgTMXEtakLIPRjYC7MWQc5SKUmgK/7ttBw8HJyUxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=OroHDgbJ; arc=none smtp.client-ip=17.58.6.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="OroHDgbJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734309727; bh=1aTosr+ehgCRhF05kcISxBde7llaXDsgXEKu5O9zvdI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=OroHDgbJTpLKZuYSXoEIue0GmBFDwPT8G9p4J6cUC/zlqJT2nKi2/q6tF9uuPWyps AGdWBQCu9QwnP4d38KCAqVaLdaw/NPO+Jp/NKXtCyxPm/u7j35C3p8ILfees7tIZCv b102O8NUSRCg5OFWI6RLt6Buh7s7e9IvXpBRiY0pJj+sDcz93MVNfvlImLmSSwmgUm MKNnBPX2CTqvl86c4NYsDqaQ0MWQipMQGBMYmpmYTyEUwXCAHP/rpv9YBoKPkk8vwW qbsDMonr/DFhHDmk4wcyrXOc9Q8HabqLS3opNJhja65Nolj83NzmxMKaF8YBiqLBsy 34pJsmJ3RBRAA== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021101.me.com (Postfix) with ESMTPSA id 25F87D00318; Mon, 16 Dec 2024 00:42:03 +0000 (UTC) From: Zijun Hu Date: Mon, 16 Dec 2024 08:40:46 +0800 Subject: [PATCH v2 7/7] of: Do not expose of_alias_scan() and correct its comments Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241216-of_core_fix-v2-7-e69b8f60da63@quicinc.com> References: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> In-Reply-To: <20241216-of_core_fix-v2-0-e69b8f60da63@quicinc.com> To: Rob Herring , Saravana Kannan , Maxime Ripard , Robin Murphy , Grant Likely Cc: Zijun Hu , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu For of_alias_scan(): - Do not expose it since it has no external callers. - Correct its comments shown below: 1) Replace /* with /** to start comments since it is not a API. 2) Delete return value descriptions since it is a void function. Signed-off-by: Zijun Hu --- drivers/of/base.c | 5 ++--- drivers/of/of_private.h | 2 ++ drivers/of/pdt.c | 2 ++ include/linux/of.h | 1 - 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 969b99838655534915882abe358814d505c6f748..5485307e2a3a3d3a216d271c60b= dfc346dd38460 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1806,14 +1806,13 @@ static void of_alias_add(struct alias_prop *ap, str= uct device_node *np, ap->alias, ap->stem, ap->id, np); } =20 -/** +/* * of_alias_scan - Scan all properties of the 'aliases' node * @dt_alloc: An allocator that provides a virtual address to memory * for storing the resulting tree * * The function scans all the properties of the 'aliases' node and populat= es - * the global lookup table with the properties. It returns the - * number of alias properties found, or an error code in case of failure. + * the global lookup table with the properties. */ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)) { diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index ea5a0951ec5e107bab265ab5f6c043e2bfb15ecc..3433ccd330e84fd3a4b54638e0e= 922069757c8f0 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -119,6 +119,8 @@ extern void *__unflatten_device_tree(const void *blob, void *(*dt_alloc)(u64 size, u64 align), bool detached); =20 +void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); + /** * General utilities for working with live trees. * diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c index 7eda43c66c916198b1c2d8fc5043fcb1edaede7a..f961aaa9b96cc4a31c39f42291e= 87b0007394ec5 100644 --- a/drivers/of/pdt.c +++ b/drivers/of/pdt.c @@ -21,6 +21,8 @@ =20 static struct of_pdt_ops *of_pdt_prom_ops __initdata; =20 +void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); + #if defined(CONFIG_SPARC) unsigned int of_pdt_unique_id __initdata; =20 diff --git a/include/linux/of.h b/include/linux/of.h index 2fcc12de4a9178276a24cd4d6c975495b9eb04a2..b43e8d5561332a10cee006b383d= 42822f28057e1 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -397,7 +397,6 @@ extern int of_phandle_iterator_args(struct of_phandle_i= terator *it, uint32_t *args, int size); =20 -extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); extern int of_alias_get_id(const struct device_node *np, const char *stem); extern int of_alias_get_highest_id(const char *stem); =20 --=20 2.34.1