From nobody Thu Dec 18 00:09:47 2025 Received: from mr85p00im-ztdg06011201.me.com (mr85p00im-ztdg06011201.me.com [17.58.23.181]) (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 25C841F63CF for ; Tue, 17 Dec 2024 13:07:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.23.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440873; cv=none; b=jRu1VM4V6sWI78CG981e7z/vgymwBlHq+Gv73rw8h0k4ydWxaCjQf+Lf0FCtyR3dlNQfomJebP11YtZ0wcdQgCto7fYLMi9VOzERrJ2ZReOSrgkfmPNbGVPT+biCtRBK3jd7FJX7nEaie86r8tLQb7foiGEAxzOUicSpPSj6bAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440873; c=relaxed/simple; bh=F7VAazrVJ3p7QlbMjlcZ0vd+3ltdvGaw1yJxrtSHdRM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Rkzf7kt2iWJ3QrU4QqqkVLhSVbluVVUE9cN7dFYrlPxW5K1+QB9et8vRZB+rW9bewhHoGvDnJhFIO9QX41fPkMb1iz1ymV/lanJL7/GikGM7Ej9Cr5FDa97uFuKlzDO3MzNEoRxJX23qscVkIfWU55eq2TpMIYBNH2inX80NKH0= 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=aeIDAQFI; arc=none smtp.client-ip=17.58.23.181 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="aeIDAQFI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734440871; bh=1qAwxeqobZh1wxnxdDloQZW9DdsopGVNulsZoYj9sn8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=aeIDAQFILvCLmhmo5TYzU1vl+CC1YfeH4lc91AkyjCEu4SUGtlLHuOvM7mIpwYohe SwLce3Y9RPiOOsNJC4U2KKL8FxWenQVjOILiCI+iPX/7pkvpTRbvuYZAqH1a3t/LFf pfh2YRQAtj+VqGsoSuPmtCMovxOPG7eQ7E/TdXfBvx3j47s3zMrOboInlfc8gIZPpw sQPx4cq7uZZuwTYDb5kneZaZZAK4D2pUEHfb8Lwqpa0kaNtiVM9tGlXBWZqdaILvQm +0yJY8SYeenVjLaS1UXRd7gcCfNVtrFbEr1ZmYrceaXxPrQkOYAix4q1ZDyV05iRrs 3r/FUBTnz06Mg== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-ztdg06011201.me.com (Postfix) with ESMTPSA id 865F796010C; Tue, 17 Dec 2024 13:07:48 +0000 (UTC) From: Zijun Hu Date: Tue, 17 Dec 2024 21:07:25 +0800 Subject: [PATCH v3 1/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: <20241217-of_core_fix-v3-1-3bc49a2e8bda@quicinc.com> References: <20241217-of_core_fix-v3-0-3bc49a2e8bda@quicinc.com> In-Reply-To: <20241217-of_core_fix-v3-0-3bc49a2e8bda@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: mcreafzY2S92rpbezCZ1gMuaiFrnMRjF X-Proofpoint-ORIG-GUID: mcreafzY2S92rpbezCZ1gMuaiFrnMRjF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-17_07,2024-12-17_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 suspectscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412170105 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 Thu Dec 18 00:09:47 2025 Received: from mr85p00im-ztdg06011201.me.com (mr85p00im-ztdg06011201.me.com [17.58.23.181]) (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 A35E31F6675 for ; Tue, 17 Dec 2024 13:07:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.23.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440877; cv=none; b=QTdpRzEptNsMZCst6NAmjPMHtNTrKonAHOMbzYjgwq6Xt9M1x/i8CFhXZ41bxyqOTGZER0P5Y7eM9sGKOR0UOuyk8iSoZCY/mxZJHR8WmQaaNehNHapd7ruVzfXy0o+4KTvnKmBNI7nMLCREaPLXvM2uHJE2cABBaKWJ3xHv6F8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440877; c=relaxed/simple; bh=uSgl6tmpjcKrpfU+/rRT4WEOic2miN6oQ63t67Qe7qc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ooBrCZJBHaZ28h5hLEJFrWZ0nNHtH52bPLdJwMSnjY9aoQctco87ASn26wPvjuJWywlWwbxLWyY5WOayzfdO/pArat0hVR1QmzPXhqKbZHvoFU+5IAHqegBQ2sPuF4E7BWge36Q3nfM33r0MwSkRqW6ze2KRGnzAuuP6Ux/oM/4= 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=eCwRMo7/; arc=none smtp.client-ip=17.58.23.181 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="eCwRMo7/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734440875; bh=lxh3lTkHEDaNLjOBBiXkDjAykRGLwhRpR2ibcxXXYlY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=eCwRMo7/LgSVvktxSqbGgcZApkt6SkauMZqQMw6KZx84xgPXcAymXEFYIaDiH9ilX nFNutISArw21RKc6VG+vHDd//zCabk48QAARiu21Ppo/pvZXKatyFLrz/caX8LOLZp 8Uq16hikiy7OAVtgEXIDbWlOP2wX6JzFv6PhxrTB2Npc+OZuoGKn2mRFNkeSKQaXa2 Y7lN3itTnelKmiHed/RSxuCsf7VO+UNnNF4SNSbmxc6Qtj2tzTs3Hwo+WBePX0Xf0y W2bIVNU3ZtPOcrDVDvxV1lAN6xMHSpnNNVM9gCxH7jkXpl0wZzOXHvY2IEQNEMSEmJ J+cfT3JH5Ytzw== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-ztdg06011201.me.com (Postfix) with ESMTPSA id 5801F96011C; Tue, 17 Dec 2024 13:07:51 +0000 (UTC) From: Zijun Hu Date: Tue, 17 Dec 2024 21:07:26 +0800 Subject: [PATCH v3 2/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: <20241217-of_core_fix-v3-2-3bc49a2e8bda@quicinc.com> References: <20241217-of_core_fix-v3-0-3bc49a2e8bda@quicinc.com> In-Reply-To: <20241217-of_core_fix-v3-0-3bc49a2e8bda@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: F6TYqueI41j27AqSVFER4prK9RSNzbsV X-Proofpoint-ORIG-GUID: F6TYqueI41j27AqSVFER4prK9RSNzbsV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-17_07,2024-12-17_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 suspectscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412170105 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..cb0cb374b21ff89323e11f34bd7= 67b183e7a401e 100644 --- a/drivers/of/pdt.c +++ b/drivers/of/pdt.c @@ -19,6 +19,8 @@ #include #include =20 +#include "of_private.h" + static struct of_pdt_ops *of_pdt_prom_ops __initdata; =20 #if defined(CONFIG_SPARC) diff --git a/include/linux/of.h b/include/linux/of.h index f921786cb8ac782286ed5ff4425a35668204d050..d451c46132b01efe6d4e0b6cf83= a3e2084bb3ec6 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 From nobody Thu Dec 18 00:09:47 2025 Received: from mr85p00im-ztdg06011201.me.com (mr85p00im-ztdg06011201.me.com [17.58.23.181]) (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 4518B1F6697 for ; Tue, 17 Dec 2024 13:07:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.23.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440880; cv=none; b=rA7d62O4VVIGeKf0mRDxaMSeLvRwfoMk8RcbDS5ndKyW4glz9P0UUQL2It/dAod/W4Lqnlg0E+7DsdnpCeQOO68IALpGuhvMgGvBOhe30dPgh/V1ghukHXQm96ht2DJgsF3vsp+GyA1rv2iTlnS0T0scZXSmWRkRxws8DmYeR+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440880; c=relaxed/simple; bh=hhxEV0PSOUDlgXbkxbGpMJBooUyQNe8CgBoY6/KKj6o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cKtgzt8VGYUnjWTNgCmOa8U1S7GtU+RXIXujeA1jZ9qGC1FTkRcDMY/HHVwytpWFVmm1WEd749M28rGbEeaX+m5xdwK2uE9tZ41HR1F37MZoBhJXCBcuqhaJrqgfQEsO/sYmyiXXe0Yg1tShdkiFv4mZJVUFfgxEwRh/8Ad6iBU= 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=tFh43nMm; arc=none smtp.client-ip=17.58.23.181 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="tFh43nMm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734440878; bh=voAtwf0WkjLnq9xLBA6Vyr9IuEpPzAqCBFAvUL3PwiI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=tFh43nMmV+NdMxAnc4CkQ1UTWvNJYiWtHdYdKzOgP9Cgp6Yyn6iyRxgjAC9TOzJ6x jijktlBQHL56tH1x2nkwRqN8c6oECZ4TiBQppmGaWeoKpBrQMJ46iBEWpC0nlcWcLF cDyoiQsHPcYyCV40NFLcLpN6suvkIgoig63A+r6buQxUcfmAkPAteUNcMt2HwCfCME hwiLXC9jNeBWynoaT88FXoP6rDD+yGZVhz1TxLn3+zfX0CP+v3QlZ5Q6+QgVyUp7k4 wjYRrwhqvCQiek4fEgvSX+epnNpqj3uofz6x+Yi3XK58xEs3YlJnvo64Rbl6zmTVU1 /eauuKkB7eRbg== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-ztdg06011201.me.com (Postfix) with ESMTPSA id B70379602F8; Tue, 17 Dec 2024 13:07:55 +0000 (UTC) From: Zijun Hu Date: Tue, 17 Dec 2024 21:07:27 +0800 Subject: [PATCH v3 3/7] of: Make of_property_present() applicable to all kinds of property 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: <20241217-of_core_fix-v3-3-3bc49a2e8bda@quicinc.com> References: <20241217-of_core_fix-v3-0-3bc49a2e8bda@quicinc.com> In-Reply-To: <20241217-of_core_fix-v3-0-3bc49a2e8bda@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: MPjhAigLLIVMa9QiJ-HN2NhYXLis75LI X-Proofpoint-ORIG-GUID: MPjhAigLLIVMa9QiJ-HN2NhYXLis75LI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-17_07,2024-12-17_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 suspectscore=0 mlxlogscore=767 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412170105 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu API of_property_present() invokes of_property_read_bool() to check if a property is present or not, and that has 2 shortcomings shown below: - That narrows down property scope applicable to of_property_present() from all kinds of property to only bool type. - That is less logical since it says a property's presence is decided by its bool property value. Fix by making of_property_read_bool() invoke of_property_present(). 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 d451c46132b01efe6d4e0b6cf83a3e2084bb3ec6..fe5d7b74c23b9701743f5debc3d= 030b765bc914f 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1242,17 +1242,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 @@ -1260,17 +1259,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 Thu Dec 18 00:09:47 2025 Received: from mr85p00im-ztdg06011201.me.com (mr85p00im-ztdg06011201.me.com [17.58.23.181]) (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 E337B1F7080 for ; Tue, 17 Dec 2024 13:08:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.23.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440884; cv=none; b=aKLb0GpR7cJSLD/BtRYe6BK61F0TNMKGMhwaGm6UBLilOwLO2Wy8X4mSl9Qo7M6efiwv04GuFraK0MN3UTsPTZVbMgzsOZnQW1jsVIyUuPEPq11UZ+paWkHpJ1D6qoKRPtrI2t0QntXdaDbR0/B1DQ6o6BUCH5NrfcPztpylJOQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440884; c=relaxed/simple; bh=80kccgYvnj9G84Nx3IR+WA53NzpjDh/0RaEOK5puNy8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DkRdJXeM+rom9042Qb36vzG7AJGmEE07EgPzZpr+TiNgBz5UkM65qbtMjx/5Xt6Sp3+ytrPrTH13LhsqvLy0b1rEU0b1N8KfdCRB1qPDyVQV2brNcjEUKu6r0g6kO07QFK8Yywv5f0hTKWR/7Yz/fk7v2etSXcgOhQyXCmj/MbM= 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=CCYir3uY; arc=none smtp.client-ip=17.58.23.181 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="CCYir3uY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734440882; bh=lMZVZTNsgFOCxTCYXq6jCFsMl6EKNzODNeFIS1bvHJg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=CCYir3uYmXczp6PJO7Nuqq7dUcOhXSDKEMvDXNs4queIizGHQGfNBJn8VBoPZP7vU NjX3IqCw4qHjoWig28bhGbFXtSYhW+E+M2UU+cQ5Fc92dcl17hOTc2BYztB8bwU6zr AyjHkLrLKGQ6xBxuK/qYcqxBTUvoOcWIWmYDCTsqmQvxBp7FJmo9+kSfYgD3HCTeLX E1ysgZHFMEMZA3Glmin5Z3GnfaJptBNkX/dTcdP27ywUhJVoh6qzbSW4FWtQWryvfE YSN5WSJ7DuMGWgoVEYgg0vRJ3etGSJ74D0LlYss6wn4ddnCuFmhCuvXT1/OGTQDp8h 9Jefb2E6IAjMA== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-ztdg06011201.me.com (Postfix) with ESMTPSA id 69495960149; Tue, 17 Dec 2024 13:07:59 +0000 (UTC) From: Zijun Hu Date: Tue, 17 Dec 2024 21:07:28 +0800 Subject: [PATCH v3 4/7] of: property: Use of_property_present() for of_fwnode_property_present() 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: <20241217-of_core_fix-v3-4-3bc49a2e8bda@quicinc.com> References: <20241217-of_core_fix-v3-0-3bc49a2e8bda@quicinc.com> In-Reply-To: <20241217-of_core_fix-v3-0-3bc49a2e8bda@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: kufwwEZd3X6wKqziTvihiCvdPK2IIf84 X-Proofpoint-ORIG-GUID: kufwwEZd3X6wKqziTvihiCvdPK2IIf84 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-17_07,2024-12-17_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 suspectscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412170105 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu Use of_property_present() instead of of_property_read_bool() for of_fwnode_property_present() since the former is more applicable obviously. Signed-off-by: Zijun Hu --- Hi Rob, i pick up this change again after some considerations as below: 1) of_property_present() is more suitable than of_property_read_bool() here, deprecated API is not main reason. 2) it does not conflict with your job which warns when use of_property_read_bool() for non-bool property. --- drivers/of/property.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/property.c b/drivers/of/property.c index 519bf9229e613906547b57d8c68e7b8558eff327..dca1a3ebccae1093b2b11f51e8e= 692bca854d0e3 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -966,7 +966,7 @@ of_fwnode_device_get_dma_attr(const struct fwnode_handl= e *fwnode) static bool of_fwnode_property_present(const struct fwnode_handle *fwnode, const char *propname) { - return of_property_read_bool(to_of_node(fwnode), propname); + return of_property_present(to_of_node(fwnode), propname); } =20 static int of_fwnode_property_read_int_array(const struct fwnode_handle *f= wnode, --=20 2.34.1 From nobody Thu Dec 18 00:09:47 2025 Received: from mr85p00im-ztdg06011201.me.com (mr85p00im-ztdg06011201.me.com [17.58.23.181]) (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 5B1A71F7563 for ; Tue, 17 Dec 2024 13:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.23.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440887; cv=none; b=p/d+cGUvkFIQaQ5Mah3xSKfTGGG5/JHpwJkmzMKzbEzJvem+WMkeGbeNE3NVJcURzoBR7uSpGYMm8Q0n6JjxqLoYzBod4dVRoymkBxsfZCMkPaBIvnNLUtg4SC/3vlEWTDMwGU4zUJ2mMAUTuwAnADZ0+52zRzPn8odMBITdjTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440887; c=relaxed/simple; bh=bc6lzGgIEQ1cBkFQ7KiFXTLCSQur3IQsBxM4lNEjjT8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Cm03Z9SlM5hFjA6dZoK3tmQjWjFctOlP5n7DiHdlzXy9iS0cb2hMZ48x2dvcKwDe4g3MJ0TXf86/tCTBYfn77z5HTWq57r0KEdVVfhH+brcJvRKxrHjrLY61sxaWvKw30u7SLuCZknNjAbEmSVPB7Z+ffAy4wEUd2JW3YfzGLoU= 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=V53Jrg/a; arc=none smtp.client-ip=17.58.23.181 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="V53Jrg/a" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734440885; bh=2a/BC8NRIh0uh85HCJfRd8BdlVkBEXk7Aqyv3gynJAM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=V53Jrg/aeAa0HlOtSv9z2RsRHoTPGet8tbXoLXbrCu3AHt1eMcQrI2AQEfBx7N8fz ZGoTpJDzKPU8/HWG/APiksj6I8OuwGc0UU8YVAFfF4q9ZezUMYetpFCMNAQGvXh6Cr QVezyrul/+eY5xKYzSo1qSlmHLcls7BMJBlit6V4GeczOEfcCj75L2bm08L3q8HJbX qbsIRWurkVPMtG+8KUjDgop+JdBDw/v45/IUiPBRDvLTafNEpCmdkkJmykxeMhVA1v t0ntFqxHSKjePdP1xyW8KssG6Vfx64h4ACnfkClggQ2Opj0eJ90Mw4T8bOCh7UJh9l nuybc4Ygvtqeg== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-ztdg06011201.me.com (Postfix) with ESMTPSA id 279C296002A; Tue, 17 Dec 2024 13:08:02 +0000 (UTC) From: Zijun Hu Date: Tue, 17 Dec 2024 21:07:29 +0800 Subject: [PATCH v3 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: <20241217-of_core_fix-v3-5-3bc49a2e8bda@quicinc.com> References: <20241217-of_core_fix-v3-0-3bc49a2e8bda@quicinc.com> In-Reply-To: <20241217-of_core_fix-v3-0-3bc49a2e8bda@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: N3u2fkR6Wp0ERaXHwutVCmYvLhrtt6p7 X-Proofpoint-ORIG-GUID: N3u2fkR6Wp0ERaXHwutVCmYvLhrtt6p7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-17_07,2024-12-17_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 suspectscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412170105 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 Thu Dec 18 00:09:47 2025 Received: from mr85p00im-ztdg06011201.me.com (mr85p00im-ztdg06011201.me.com [17.58.23.181]) (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 02E551F75A0 for ; Tue, 17 Dec 2024 13:08:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.23.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440893; cv=none; b=gGVyWDYEGUmzWNyT0h9KivvR7g/Fl13v6kkjxNNqkD7SObRimihVhHrQR+CjtxAwm3W0CrYuYfUXjeeLy49Zsq+tNVf9w0n7iehiwM5JUYpYdpeURZ60J8Ta5/jUd3fBrKMKRSuEMobbMaHZWtN6rKJ+mm/hcam4M6KBOGu10/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440893; c=relaxed/simple; bh=VZavQ++21q2uPUZ1FUNPyQJnRNl6BcSboy0lOQqrykI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PlvMgZQD3A0sHuvFuU4/M7OC9eynQL4DMnSU3zE/wfxIZLXm5audsj9i3nzlFYUR3TaPbeqlQbh+B9wNmb7bbgSvpXAofdmd8pTDatrvf3F6GdFIJb8KuoegJ7vOT6pRm0BOEdJ2xfxIoY4I1M9xyj/FpytUNZFVbrJtQVUOcfs= 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=yL+E8R+A; arc=none smtp.client-ip=17.58.23.181 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="yL+E8R+A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734440889; bh=xQkfDGL0XIq7y1IU6Bhqw+rN458Q+Hz+5g2SVbEqwoU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=yL+E8R+A/oJ/fSmUCF+22x7yo61F5LN7YNkPGBJ23O0kz2dwoQiUuSwwVmGjlpKvc +yY5BMTMs/6KOnInDzUbGdHo5rb/YeKBSQGbhsfPW8iCc9JUorAIWi/4hcYPjsNrFy EGYA5VMXSizyHicoQ0PbQ/+5Zu+i6nIZMLWay/OxZXm1bBVlVJOmxu41FV8eLS0hqe HaFIxks4x4xmHi6RmxbuyywGDLR0nMLbe/Gxfe1nMbxJUFLy/tOGUkyNGR6vanZ5Ha 9z60T0Ap/cTYwO/8w/rAnS7DG62DbdQEfo7TS3vFxL5dITb8SHoMMv04FkadV3aKvI hnRaMe/C5f7Gg== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-ztdg06011201.me.com (Postfix) with ESMTPSA id 7C271960252; Tue, 17 Dec 2024 13:08:06 +0000 (UTC) From: Zijun Hu Date: Tue, 17 Dec 2024 21:07:30 +0800 Subject: [PATCH v3 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: <20241217-of_core_fix-v3-6-3bc49a2e8bda@quicinc.com> References: <20241217-of_core_fix-v3-0-3bc49a2e8bda@quicinc.com> In-Reply-To: <20241217-of_core_fix-v3-0-3bc49a2e8bda@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: ehRZmWmdSfAKaTCii1oPUctISHaj8Mgj X-Proofpoint-ORIG-GUID: ehRZmWmdSfAKaTCii1oPUctISHaj8Mgj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-17_07,2024-12-17_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 suspectscore=0 mlxlogscore=944 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412170105 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 | 7 ++-- 3 files changed, 79 insertions(+), 70 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 fe5d7b74c23b9701743f5debc3d030b765bc914f..f36bab2caa8ccffbd43593d8b67= 20946e19503e0 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 */ @@ -761,10 +761,9 @@ static inline int of_count_phandle_with_args(const str= uct 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; + return ERR_PTR(-ENODEV); } =20 static inline int of_request_module(const struct device_node *np) --=20 2.34.1 From nobody Thu Dec 18 00:09:47 2025 Received: from mr85p00im-ztdg06011201.me.com (mr85p00im-ztdg06011201.me.com [17.58.23.181]) (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 803581F76B2 for ; Tue, 17 Dec 2024 13:08:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.23.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440894; cv=none; b=LfoesPxjVtWI5seOAA0vZet0lvcX2pRkcsMzrRpT3SbYBXocWXQnLeJDAtWriX6LQX+GOHxjhZyg9kGf0XNAitoeoKKUIkjoyFOuvu4vh18yJxXb0U2Sg1Om6hEnPxdXkStP9ymLmk//Adx0KJANW9OMLJVDBThpT2MgrdbtxTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734440894; c=relaxed/simple; bh=4/H70e0punnJ+RTZIpTcPhQowk99820k7GsZQcgr2+s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VgfrR5aVIjtgHxfT9q8u8ToozeM8owNJKDwL3OHo6sOqB1PicYF4pX0k4GWLC4YzgQrqxwzxsf4tl2El2EiQzA+jpMLkPvYn6O12ikEMYXoqzz4ZpsYBPGJxRaxHA9G+RT1ZW5bCr6wDjLT71J/3s2Gix2wZVovLn3Wm5Rb34NQ= 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=Z1LtAnKN; arc=none smtp.client-ip=17.58.23.181 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="Z1LtAnKN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734440893; bh=n/2ECFFvsy3oX54LANvs+QW1uDJIfzCg4fhckcEOoYA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=Z1LtAnKNwOC+QV0YGMlZBb04806CMisrTeKAyrcfTXei+5ba4InX6JY0dMcqHX7pC 4c+ifodEy52ro11bEqH3ywp/drFfcmxLTzUu7F43otS+7Ryzt4ndqyGaKNtuEYc94Y RDmHn7aoYqQkjE2zxLBj4H1ZkyvD2DbDocZCbYaRUy4IZQQnbpZjWjr7vgnHxgVJxm GzUpIzwQxJ5Vm06Cs9dRWRrJjHezowjXwMqjZS/oWhFeVlUgRdVfUUVawc0YWdt4R5 vN3mmOus58vX9eg1C1shPZTirr+anFAOzl/Pn8JBNSSzCsSqKLcRtwwXe/8/dCVy8g 9+15DBLa7b0Ng== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-ztdg06011201.me.com (Postfix) with ESMTPSA id 28BE09602BA; Tue, 17 Dec 2024 13:08:09 +0000 (UTC) From: Zijun Hu Date: Tue, 17 Dec 2024 21:07:31 +0800 Subject: [PATCH v3 7/7] of: Do not expose of_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: <20241217-of_core_fix-v3-7-3bc49a2e8bda@quicinc.com> References: <20241217-of_core_fix-v3-0-3bc49a2e8bda@quicinc.com> In-Reply-To: <20241217-of_core_fix-v3-0-3bc49a2e8bda@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: 9vUZ2aJGuQLZzk4fqjghWZ0W9NDnSOfF X-Proofpoint-ORIG-GUID: 9vUZ2aJGuQLZzk4fqjghWZ0W9NDnSOfF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-17_07,2024-12-17_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1015 malwarescore=0 suspectscore=0 mlxlogscore=664 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412170105 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu Do not expose of_modalias() since it has no external callers. Signed-off-by: Zijun Hu --- drivers/of/module.c | 2 ++ drivers/of/of_private.h | 2 ++ include/linux/of.h | 6 ------ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/of/module.c b/drivers/of/module.c index 03a2b1b381e5b353b6699dac183c03186afb0486..6dd670f7e4fe68b6a8f4b30a810= 64a1b8e4a0644 100644 --- a/drivers/of/module.c +++ b/drivers/of/module.c @@ -8,6 +8,8 @@ #include #include =20 +#include "of_private.h" + /* * of_modalias - get MODALIAS string value for a OF device node * @np: the OF device node diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 3433ccd330e84fd3a4b54638e0e922069757c8f0..5facb6ff63cce46205fbe3969ae= 2e9f7858ac9bd 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -150,6 +150,8 @@ extern void __of_detach_node(struct device_node *np); extern void __of_sysfs_remove_bin_file(struct device_node *np, const struct property *prop); =20 +char *of_modalias(const struct device_node *np, ssize_t *lenp); + /* illegal phandle value (set when unresolved) */ #define OF_PHANDLE_ILLEGAL 0xdeadbeef =20 diff --git a/include/linux/of.h b/include/linux/of.h index f36bab2caa8ccffbd43593d8b6720946e19503e0..d9062d4fbd143d42b6b217942ac= ed66fa34f1c80 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -382,7 +382,6 @@ extern int of_count_phandle_with_args(const struct devi= ce_node *np, const char *list_name, const char *cells_name); =20 /* module functions */ -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 */ @@ -761,11 +760,6 @@ static inline int of_count_phandle_with_args(const str= uct device_node *np, return -ENOSYS; } =20 -static inline char *of_modalias(const struct device_node *np, ssize_t *len= p) -{ - return ERR_PTR(-ENODEV); -} - static inline int of_request_module(const struct device_node *np) { return -ENODEV; --=20 2.34.1