From nobody Wed Dec 17 12:46:24 2025 Received: from st43p00im-ztfb10071701.me.com (st43p00im-ztfb10071701.me.com [17.58.63.173]) (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 C82112144BD for ; Thu, 12 Dec 2024 13:39:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.63.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010771; cv=none; b=BkxmqXiY+pKIbUKSWpkJqEJIbqxT2o4dfBCBzGKvbUFsdHr8sZZrtAh1Tlb/XDgFouWWhGxgojg80njo3zjyI3YSSgeha3WRHKM1bleQcu+ijbv41l1N+OFi8HxgriD00XsNzixjGWwIpNFtViE9tj24/a/g8dEjMk+mzgM0gJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010771; c=relaxed/simple; bh=e/2xP3qFb869WanTNBYe+qJB5MKHi9usxQIzrOvob5c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lJ/p9Ti/d1EKAHXxOawAPhxDX3EBOhMy9/8wURUt7QvXow5zrxAw6JZrvku1qMhVoz9XIuVsGxG7gqYQ73vK5C2kxVLJYGqgAIx4r8UdQ8ofC2u2Mpj8eo7nr0Jg9gY0Ucq4zUAfUJer95a430PLO6oZ2nTm0lvMeS73bGj/XR4= 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=uMGWb7Yg; arc=none smtp.client-ip=17.58.63.173 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="uMGWb7Yg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734010768; bh=Eh2nL80zh7HWftk0msMSgPR2NrIlsrV6kCVdoP2/U/c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=uMGWb7Ygd4lPgRfEQBVse00BCLTdU7yWJG1woa3ZkWgxVMt275JWAzFsRd25UlDM8 ur2mX8+ACw4IwLak3A1LIryb7AtO8FL15wPVG1nqSNPpBjbrZ26E3veEPpqq1qfYBV kDLHApQDZpyMDLmIzCF81z/zMK008PT2gFE4kHjea+TpYOvLwByVD/EArhO6+G0bQn y0AHM1p66H14T9KwmbEzG/tn5mL3YHjNBqe9LrTD103G3R8tXI81+C+Q2YAk4jIWxl uZ8+t9iUdGpAT+nkTaIFShyvkD/kXa7XkKBD+8Av0+F1pDLR7cFk3bczP7OsrBvOZq YZSckuLLkDV7g== Received: from [192.168.1.26] (st43p00im-dlb-asmtp-mailmevip.me.com [17.42.251.41]) by st43p00im-ztfb10071701.me.com (Postfix) with ESMTPSA id 8D8E6CC01EE; Thu, 12 Dec 2024 13:39:19 +0000 (UTC) From: Zijun Hu Date: Thu, 12 Dec 2024 21:38:37 +0800 Subject: [PATCH v3 1/9] driver core: class: Fix wild pointer dereferences in API class_dev_iter_next() 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: <20241212-class_fix-v3-1-04e20c4f0971@quicinc.com> References: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> In-Reply-To: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Tejun Heo , Josef Bacik , Jens Axboe , Boris Burkov , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams Cc: Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Proofpoint-GUID: O3rAVS6GNetLcy20L32Omo3pNoh9hpsO X-Proofpoint-ORIG-GUID: O3rAVS6GNetLcy20L32Omo3pNoh9hpsO 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-12_09,2024-12-12_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412120098 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu There are a potential wild pointer dereferences issue regarding APIs class_dev_iter_(init|next|exit)(), as explained by below typical usage: // All members of @iter are wild pointers. struct class_dev_iter iter; // class_dev_iter_init(@iter, @class, ...) checks parameter @class for // potential class_to_subsys() error, and it returns void type and does // not initialize its output parameter @iter, so caller can not detect // the error and continues to invoke class_dev_iter_next(@iter) even if // @iter still contains wild pointers. class_dev_iter_init(&iter, ...); // Dereference these wild pointers in @iter here once suffer the error. while (dev =3D class_dev_iter_next(&iter)) { ... }; // Also dereference these wild pointers here. class_dev_iter_exit(&iter); Actually, all callers of these APIs have such usage pattern in kernel tree. Fix by: - Initialize output parameter @iter by memset() in class_dev_iter_init() and give callers prompt by pr_crit() for the error. - Check if @iter is valid in class_dev_iter_next(). Fixes: 7b884b7f24b4 ("driver core: class.c: convert to only use class_to_su= bsys") Signed-off-by: Zijun Hu --- Alternative fix solutions ever thought about: 1) Use BUG_ON(!sp) instead of error return in class_dev_iter_init(). 2) Change class_dev_iter_init()'s type to int, lots of jobs to do. This issue is APIs themself issues, and regardless of how various API users use them, and silent wild pointer dereferences are not what API users expect for the error absolutely. --- drivers/base/class.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/base/class.c b/drivers/base/class.c index 582b5a02a5c410113326601fe00eb6d7231f988f..d57f277978dc9033fba3484b462= 0bcf884a4029f 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -323,8 +323,12 @@ void class_dev_iter_init(struct class_dev_iter *iter, = const struct class *class, struct subsys_private *sp =3D class_to_subsys(class); struct klist_node *start_knode =3D NULL; =20 - if (!sp) + memset(iter, 0, sizeof(*iter)); + if (!sp) { + pr_crit("%s: class %p was not registered yet\n", + __func__, class); return; + } =20 if (start) start_knode =3D &start->p->knode_class; @@ -351,6 +355,9 @@ struct device *class_dev_iter_next(struct class_dev_ite= r *iter) struct klist_node *knode; struct device *dev; =20 + if (!iter->sp) + return NULL; + while (1) { knode =3D klist_next(&iter->ki); if (!knode) --=20 2.34.1 From nobody Wed Dec 17 12:46:24 2025 Received: from st43p00im-ztfb10071701.me.com (st43p00im-ztfb10071701.me.com [17.58.63.173]) (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 BC7E5211A0E for ; Thu, 12 Dec 2024 13:39:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.63.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010781; cv=none; b=R6LXYkwfUN3aIXc4XNHEQSBtrAY+ItIQNf2fHKILArSX/ucabIUxBPAt0g6eH/rl2OtePhxOBpNMzhmUUc8naI3/XKr7xtvyerANcezxDzK9IhCz8CMksoPlcWlWZl+W7eKvtjRbi9AK4hyxd22GE2p29aiOII9bbDSfKAclFXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010781; c=relaxed/simple; bh=VJjh6ZhXKGcVCCDU2UfjvJvEycscGCyQOOsgxx+2wNQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PtxgUI5G9KBwtetaAy8UuFUI8AnGEINZTjXW9kFX5mFVM0/xcYyndDnDMNZB2JR2vQ3SFp4prxazUBnUKfEGrdYJFEjNtgm6mu1gETOjPBC1NTJHX6eXQTD2QzP4ujLpbb7p6jgExjhsxShLMk4mSZTE5sTkm8gicf4bVCYbrb8= 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=WE2C1rat; arc=none smtp.client-ip=17.58.63.173 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="WE2C1rat" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734010779; bh=cpH9bgdtvAV2gtShH3Xs87qkc05FUN80N1S8SieWLOU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=WE2C1ratPFZQR/5lUr/YlEzqb7pn4kCQ0/XkCbMdWg4xciFjIXXwugk5e1nOAbw/u RJyVn2Ys/hw1e9TEgRnOE75GO6bzm+c8YnS3vc+xy4fJ6U4X2p6jGlly5lktdQe14R fKpsVZeqaIGIkMsLKwnUl5Yqp1ZgCsXhs9LIzN+aRQHUSdN3p4ZkWEn6v6NsfXKE5F zbweygnUJoU9qx7d4dB6nU11goc+hG3Ij6dDc1LR1z9+9quGnx2L6olpVQ3gS56L1p 2/3yIDNTq3lJRSj2nAyNPha8rs0mXrFPEoORDg5XLjKFmYsj1zyQQ/HLjORP41aX01 /JOJ6FlPXdBzg== Received: from [192.168.1.26] (st43p00im-dlb-asmtp-mailmevip.me.com [17.42.251.41]) by st43p00im-ztfb10071701.me.com (Postfix) with ESMTPSA id A3680CC01D3; Thu, 12 Dec 2024 13:39:29 +0000 (UTC) From: Zijun Hu Date: Thu, 12 Dec 2024 21:38:38 +0800 Subject: [PATCH v3 2/9] blk-cgroup: Fix class @block_class's subsystem refcount leakage 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: <20241212-class_fix-v3-2-04e20c4f0971@quicinc.com> References: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> In-Reply-To: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Tejun Heo , Josef Bacik , Jens Axboe , Boris Burkov , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams Cc: Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu , stable@vger.kernel.org X-Mailer: b4 0.14.2 X-Proofpoint-GUID: RBdV7Ki3-LPAth7cquZxpYKME9w9qxmu X-Proofpoint-ORIG-GUID: RBdV7Ki3-LPAth7cquZxpYKME9w9qxmu 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-12_09,2024-12-12_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412120098 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu blkcg_fill_root_iostats() iterates over @block_class's devices by class_dev_iter_(init|next)(), but does not end iterating with class_dev_iter_exit(), so causes the class's subsystem refcount leakage. Fix by ending the iterating with class_dev_iter_exit(). Fixes: ef45fe470e1e ("blk-cgroup: show global disk stats in root cgroup io.= stat") Cc: Greg Kroah-Hartman Cc: stable@vger.kernel.org Signed-off-by: Zijun Hu Reviewed-by: Michal Koutn=C3=BD --- block/blk-cgroup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index e68c725cf8d975f53703ecf6e6c50594076204c8..fb9858efdfe9443704cb9a239de= f0e08addf2518 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1138,6 +1138,7 @@ static void blkcg_fill_root_iostats(void) blkg_iostat_set(&blkg->iostat.cur, &tmp); u64_stats_update_end_irqrestore(&blkg->iostat.sync, flags); } + class_dev_iter_exit(&iter); } =20 static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s) --=20 2.34.1 From nobody Wed Dec 17 12:46:24 2025 Received: from st43p00im-ztfb10071701.me.com (st43p00im-ztfb10071701.me.com [17.58.63.173]) (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 96D02211A0E for ; Thu, 12 Dec 2024 13:39:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.63.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010791; cv=none; b=bLC6uZZXQL3nJ7drnw65erPUvfEMQmOZHaQGyqC7KXWIqXawQC/RgeM5Wx6lpxVHMtaqoPfSub0EQl8OXvdfiaYTLSjGxxIhc/vClZevJ3Z2xPhzPLnlfLEJN821Q1jV7C7QompkDwOV+iO1iD5S3W98X6uFo602R/VSktZYMQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010791; c=relaxed/simple; bh=9Mx+wakWh59QVSPolqX2ZOXUvKB4IIWdPTof/zgmp/M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lynWljEpgXHLLbZueLIcyKzR4H+EJEGCayZEKwvPsykK9/HJ4Cxki8lPUsfMgF6REfLL9zkKvYdKa1ubAiVfzp8y/zVt9R+RD+TXc5tDsu1aA/JCygQiXM4J7gjv1TKCqvAo4En203vtDfjlhIVbxoBhR3uAvpx4WE1s/NHLewU= 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=t0mcP4JG; arc=none smtp.client-ip=17.58.63.173 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="t0mcP4JG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734010788; bh=drZPh5V15P2Ut5u+90AJAcXYqSdhgaQY4p1DaIP3Gsg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=t0mcP4JGt+yQ5RIycZNX54R/zpiXhnN3cFQSmIEslGfRMlL2ucoUef8dqNWHJ7Q0D U/xcFsUold8C28e25OD2i2Y+wLtQJF3fIKTdk7inhTxGjLOCRg6znSLXDKBRsL1R31 1TieTEqpOh/6OiRmcCiVcChK6pY6n9t4govLxq0Jsm/2LTWrDfneMCpAVEP9PcY7pT D22Btm6TxwCOri0GPuTufOgCaYfUMMSp1cM5C/kBWhTHptFK1X3+lnhxCVQKyZvYfq gxg7ZNQUdfikIN01XOvv4vPwFA2Z6YGIb6vMAZoSImlDIOn/Srcmpxlq1j/lsYnr85 oUSe0/idXeNaA== Received: from [192.168.1.26] (st43p00im-dlb-asmtp-mailmevip.me.com [17.42.251.41]) by st43p00im-ztfb10071701.me.com (Postfix) with ESMTPSA id D2F97CC0336; Thu, 12 Dec 2024 13:39:39 +0000 (UTC) From: Zijun Hu Date: Thu, 12 Dec 2024 21:38:39 +0800 Subject: [PATCH v3 3/9] driver core: bus: Move true expression out of if condition in API bus_find_device() 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: <20241212-class_fix-v3-3-04e20c4f0971@quicinc.com> References: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> In-Reply-To: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Tejun Heo , Josef Bacik , Jens Axboe , Boris Burkov , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams Cc: Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Proofpoint-GUID: fb8vrTNNLQpsaNJsFTCK1_4fTmMz000u X-Proofpoint-ORIG-GUID: fb8vrTNNLQpsaNJsFTCK1_4fTmMz000u 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-12_09,2024-12-12_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412120098 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu For bus_find_device(), get_device() in the if condition always returns true, move it to if body to make the API's logic more clearer. Signed-off-by: Zijun Hu Reviewed-by: Jonathan Cameron --- drivers/base/bus.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 657c93c38b0dc2a2247e5f482fadd3a9376a58e8..73a56f376d3a05962ce0931a2fe= 8b4d8839157f2 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -402,9 +402,12 @@ struct device *bus_find_device(const struct bus_type *= bus, =20 klist_iter_init_node(&sp->klist_devices, &i, (start ? &start->p->knode_bus : NULL)); - while ((dev =3D next_device(&i))) - if (match(dev, data) && get_device(dev)) + while ((dev =3D next_device(&i))) { + if (match(dev, data)) { + get_device(dev); break; + } + } klist_iter_exit(&i); subsys_put(sp); return dev; --=20 2.34.1 From nobody Wed Dec 17 12:46:24 2025 Received: from st43p00im-ztfb10071701.me.com (st43p00im-ztfb10071701.me.com [17.58.63.173]) (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 745DA2147FE for ; Thu, 12 Dec 2024 13:40:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.63.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010801; cv=none; b=FmWbY5KVg34xzjKOUCqoEppRhrRbc1shUCYjZ1/tBTjnVvw5kEdHNmq2A22ioO7gadPmwlMLxGzPzoR90C9LOfp9JM1Ulgo/Ka7u0G5LqeQyQNV2J+WPD3YJdmEfQDH497n7YLROChWqCJaneAnKWD99CLyAG7iMKp6LW0F2MbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010801; c=relaxed/simple; bh=MpfYSOt0Ypq02pEOaoX882rZBpc3JH29gpuB0mSAjzk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sPUXDEbyvMbhZChOL19N0KWLXwdITZrr0l399JIBQebZ57Aj6DTE3sPRJ6LW6xNJ0RLfLzrhScDJ+k0M+tomeycLIEnnh74+ueLQRnroKWESpBXG/jhQS04S7nHK8TR6KdWv4Xht+eXPjAYULVYpFflWDptX/ok8tgOc+N0bIlU= 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=ujccATt5; arc=none smtp.client-ip=17.58.63.173 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="ujccATt5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734010799; bh=T0BucTNeqdeFW4ea8vuRFEDfGvQqFsZrvBOQltEORx0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=ujccATt573FQggCea4OwX3Tocp+1RtO3tS0Oh4PUc7Q7JkujjwQzJh/9A7PTYYMVG OOS9PAx1c3FYi2JndNgWYumdSi6rgIa4BnxdjjpYUCUXbZvYE1ePdv14foMK+6HQ3I +UvJPJi0jUlnqR+SPoU8wpu7xxcpzTmdjhkcdiM2cJ2EpouChekYEXT2u8/Dx7pxcJ 4wytEVG1qLm2UE7YucN3Z1wjJqktMNILdgN5XqKDsbFnxTyMXiWtI7NehHca1pjFka 7kjgDBJgLvOFsuQMIaxJTsY9BtPYEbYUD7pnRwkmCyvSvDL4HtY3fDz5xkrQBGsCZU uqHG8yOrHwh1Q== Received: from [192.168.1.26] (st43p00im-dlb-asmtp-mailmevip.me.com [17.42.251.41]) by st43p00im-ztfb10071701.me.com (Postfix) with ESMTPSA id AC6CACC01A4; Thu, 12 Dec 2024 13:39:49 +0000 (UTC) From: Zijun Hu Date: Thu, 12 Dec 2024 21:38:40 +0800 Subject: [PATCH v3 4/9] driver core: Move true expression out of if condition in API driver_find_device() 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: <20241212-class_fix-v3-4-04e20c4f0971@quicinc.com> References: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> In-Reply-To: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Tejun Heo , Josef Bacik , Jens Axboe , Boris Burkov , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams Cc: Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Proofpoint-GUID: okDoNSfcrFTO1Uiyr0O5JhWQ4058QbKW X-Proofpoint-ORIG-GUID: okDoNSfcrFTO1Uiyr0O5JhWQ4058QbKW 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-12_09,2024-12-12_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412120098 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu For driver_find_device(), get_device() in the if condition always returns true, move it to if body to make the API's logic more clearer. Signed-off-by: Zijun Hu Reviewed-by: Fan Ni Reviewed-by: Jonathan Cameron --- drivers/base/driver.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/base/driver.c b/drivers/base/driver.c index b4eb5b89c4ee7bc35458fc75730b16a6d1e804d3..6f033a741aa7ce6138d1c61e49e= 72b2a3eb85e06 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -160,9 +160,12 @@ struct device *driver_find_device(const struct device_= driver *drv, =20 klist_iter_init_node(&drv->p->klist_devices, &i, (start ? &start->p->knode_driver : NULL)); - while ((dev =3D next_device(&i))) - if (match(dev, data) && get_device(dev)) + while ((dev =3D next_device(&i))) { + if (match(dev, data)) { + get_device(dev); break; + } + } klist_iter_exit(&i); return dev; } --=20 2.34.1 From nobody Wed Dec 17 12:46:24 2025 Received: from st43p00im-ztfb10071701.me.com (st43p00im-ztfb10071701.me.com [17.58.63.173]) (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 52236214A87 for ; Thu, 12 Dec 2024 13:40:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.63.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010811; cv=none; b=kcZR1Sd+Xb5pIdJsQDdqM759m6qZ+aUN7NnXZm4GtPTjjw72s4D4R2qCqXc2oG6aevBbRKFFBWfDS9ONxHO8QFea5v+fTYFTK1q47K5+zY5rZY7j5yM0ixW2dOoKaG7vmWzfxGVQkcJb3u1XGi7leQ+hoRTmH93BU96ieER4gZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010811; c=relaxed/simple; bh=R8VIFdyqapZyJOl/BHNlTI5vngCzvR6PKVHcwc9zcVI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nwA3ThX68Xw6UyTRcYiLxRwFyKJxr0P51OiQpQqihUuksrVYVC/TamFGpqiERQuuKDy28/CZBDQZccHF54hP8bOL49E4LmgigIXBAPNsZurqkVgkHOaU4DS3lfO1fW4k3AEMh3T+ihmMj7VjiL027UDI4kuvOMIK8OV5gfXdghU= 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=EdhlcaKD; arc=none smtp.client-ip=17.58.63.173 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="EdhlcaKD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734010809; bh=ybt5vh1QaA/axSj+u1J5wKyDXeYgnZy6kLh7TPuQ6Tg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=EdhlcaKDlwBjGmboSo9N7IX33tBRzPxC9/Sax05kB/pjdUj/fq1blxVxXzlB2zGfV f2BDRV5DqsC8NOm0Efzl27MRUnO2bd205kSJdydfvKg0Qj+G9Bz+wmuHgfhHI43vR6 6aHHpo6sHCwoRN3rB02NYbmsMUEeJwE3MtuGHKW4UirnDrO+GcQRZgJQRkhtVkFIXn TLVgYZa1i8Ri9QVPL50t7eoN/4cFOyRmi5J8Nn/Gr2BXXDZeqaK4ty5pSy7MfZ7FjL ZT+BUXKYsU1N1NTGvdUndJYIAj/tUAxNppDe2C3S5CRAqoQYwty+2iigNuGcegvGks RvZeJ9WfQxT1Q== Received: from [192.168.1.26] (st43p00im-dlb-asmtp-mailmevip.me.com [17.42.251.41]) by st43p00im-ztfb10071701.me.com (Postfix) with ESMTPSA id 5857ACC052C; Thu, 12 Dec 2024 13:39:59 +0000 (UTC) From: Zijun Hu Date: Thu, 12 Dec 2024 21:38:41 +0800 Subject: [PATCH v3 5/9] driver core: Move true expression out of if condition in API device_find_child() 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: <20241212-class_fix-v3-5-04e20c4f0971@quicinc.com> References: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> In-Reply-To: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Tejun Heo , Josef Bacik , Jens Axboe , Boris Burkov , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams Cc: Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Proofpoint-GUID: C_R3DRM13jgyUA-8TDHIoyiorACvbERK X-Proofpoint-ORIG-GUID: C_R3DRM13jgyUA-8TDHIoyiorACvbERK 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-12_09,2024-12-12_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412120098 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu For device_find_child(), get_device() in the if condition always returns true, move it to if body to make the API's logic more clearer. Signed-off-by: Zijun Hu Reviewed-by: Fan Ni Reviewed-by: Jonathan Cameron --- drivers/base/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 8bdbc9e657e832a063542391426f570ccb5c18b9..69bb6bf4bd12395226ee3c99e2f= 63d15c7e342a5 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4089,9 +4089,12 @@ struct device *device_find_child(struct device *pare= nt, const void *data, return NULL; =20 klist_iter_init(&parent->p->klist_children, &i); - while ((child =3D next_device(&i))) - if (match(child, data) && get_device(child)) + while ((child =3D next_device(&i))) { + if (match(child, data)) { + get_device(child); break; + } + } klist_iter_exit(&i); return child; } --=20 2.34.1 From nobody Wed Dec 17 12:46:24 2025 Received: from st43p00im-ztfb10071701.me.com (st43p00im-ztfb10071701.me.com [17.58.63.173]) (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 78CCC2153EC for ; Thu, 12 Dec 2024 13:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.63.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010823; cv=none; b=EvVn3wE3Fw2icOjlvbxdkd9r70DtIRryRS+TGga/W24CUmtKDKpZpYJiru3vt7xjjBcycWRBAbhGy4wUEblRdWSoLQfoPptVT1WG7nFHEBjcOnuO51ExuUYLH1dhaD5yOhEigL1YzMAFJiJDS9N+2m13cVoGeZZMSXPSX2fsuiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010823; c=relaxed/simple; bh=xTs0tfRiGxLqlQU1bZPA1WOpD5NDj3sC2kJdgPus4Qw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=affmZL1kf1vLEavrDmULqwUYyWULmWLtFFm1BJcvboEiCsSJN4kaHuXXXIOwiz+xQ1Hqp2FFil+mcQE5dIboVCZKfV+Yh2sonN3WGi6fXhwq30kruZCUNBxSU34bhszoIwCjgHglzl0slAqcE/RLmDme12BFdaIP/yuaRYkntik= 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=RtVUp5Y7; arc=none smtp.client-ip=17.58.63.173 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="RtVUp5Y7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734010820; bh=PJ+USCXikXXOIa5sjtReFqqyn2Z79RPqI/MdeM0TEeQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=RtVUp5Y7CwHrlKUHFRw4PblS7dSf3gZ+tfFnNCWCI0Xr4eRWYZQcdll0m4a5SDypT HcA3ZSvYiPfCU5w28LcWcUbl3lJqBx3qhV6m8X0ZmcgfEAkvRVNQ2GMAIekT3/KyFm 3vczs6AJ2QbP3iCETnT8h8rlY1SFVZEFVlRWWMjMZnuMLBEFSLqTZH9Oxdgm9Ye617 29jvghvmp4HykRDugD5dC/iPazC7elqEtW7wpyhrpClIcrICez0lc+3EPZQ/tI7WXK zoIOu0RhWDZ9VSQ9/avBKAz0MsqhPhXXX7pOB11Nxs519NtS+j9h/QU3xDuFvAlmH7 nQddK34voHR0g== Received: from [192.168.1.26] (st43p00im-dlb-asmtp-mailmevip.me.com [17.42.251.41]) by st43p00im-ztfb10071701.me.com (Postfix) with ESMTPSA id 27A94CC05A8; Thu, 12 Dec 2024 13:40:09 +0000 (UTC) From: Zijun Hu Date: Thu, 12 Dec 2024 21:38:42 +0800 Subject: [PATCH v3 6/9] driver core: Rename declaration parameter name for API device_find_child() cluster 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: <20241212-class_fix-v3-6-04e20c4f0971@quicinc.com> References: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> In-Reply-To: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Tejun Heo , Josef Bacik , Jens Axboe , Boris Burkov , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams Cc: Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Proofpoint-GUID: -X7mVsDv8xUXYZmJRACbgXBbnBOV2epq X-Proofpoint-ORIG-GUID: -X7mVsDv8xUXYZmJRACbgXBbnBOV2epq 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-12_09,2024-12-12_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412120098 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu For APIs: device_find_child() device_for_each_child() device_for_each_child_reverse() Their declaration has parameter name 'dev', but their defination changes the name to 'parent'. Rename declaration name to defination 'parent' to make both have the same name. Signed-off-by: Zijun Hu Reviewed-by: Fan Ni Reviewed-by: Jonathan Cameron --- include/linux/device.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/device.h b/include/linux/device.h index 0e0bc9bfe0d15a8734bf3d34106300f4df6b5364..a9d928398895b062094b94f2c18= 8cbe9951d7ac1 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1074,14 +1074,14 @@ void device_del(struct device *dev); =20 DEFINE_FREE(device_del, struct device *, if (_T) device_del(_T)) =20 -int device_for_each_child(struct device *dev, void *data, +int device_for_each_child(struct device *parent, void *data, int (*fn)(struct device *dev, void *data)); -int device_for_each_child_reverse(struct device *dev, void *data, +int device_for_each_child_reverse(struct device *parent, void *data, int (*fn)(struct device *dev, void *data)); int device_for_each_child_reverse_from(struct device *parent, struct device *from, const void *data, int (*fn)(struct device *, const void *)); -struct device *device_find_child(struct device *dev, const void *data, +struct device *device_find_child(struct device *parent, const void *data, device_match_t match); struct device *device_find_child_by_name(struct device *parent, const char *name); --=20 2.34.1 From nobody Wed Dec 17 12:46:24 2025 Received: from st43p00im-ztfb10071701.me.com (st43p00im-ztfb10071701.me.com [17.58.63.173]) (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 390F22153D9 for ; Thu, 12 Dec 2024 13:40:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.63.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010833; cv=none; b=jfFrQQZ8wBCffJu7I607X98bQ3ZXbxdtb0wycVcrydfVoCYblXb8jh6Jlx4LShxIUyPOPe0bU2jptTt4/AYudnCBqY5gQD8UsBm6a/4GGHQ5V/FGhU5BNQijoxDc3CvbiYTq/KGgDTn58ctmVAaiRLXu+AjR0tckbJNPPScVczU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010833; c=relaxed/simple; bh=9Y0rzZnBTx0M5MQSIP1RwELLmzfYczu0ijWLu1jrY5g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TQS3aORegLbF93YiseJtLIp8r9bjym7xoywizM6VVJL+rDMv/5J8gxelp66D2tOcv17/JxLgi1PHFNHO0jPRSorKiiNBjg/V2sGlpoEY6VWHvGEDr1tN7PqRsu6Ok/dByri4KLMn+0y/QWIS/VmuVH0JSUROQd8O4ckx33dqvbI= 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=nIB8IsdD; arc=none smtp.client-ip=17.58.63.173 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="nIB8IsdD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734010830; bh=VKx9/BEbeYqmaBNZCu91NOLWQRLnn6ACylShMKN74W8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=nIB8IsdDwOoGW46n0TW3vhB1KBisrBiDMPqbp8nCwsLFZZ+k7+Lmlqlj+JG3J8Scr xRgJcHpHL169NI8N5YlFLCjPfdNmGaJhaVaUJHIZ+4gEJTixtMVqeHiGdHmD24qiy0 LJG6t2H4xputS0p5P1XTxU/VCLU1a+51AV5QG8dKpKsOAJhxt0M0F/ab4hwq15wKEi W/CIR/jmYI4dlrX5Vwwj09QD6dju02pQYe9or91JIRbRohM+N7L65jcLLuLCID4fkV nUH2Hwbzqa+O24H5PSbDAXI5pYGR6nE/EXdetQ2lOvopDDyUP/Q28YJHC2jrIr5Cjw vDkRKKpdClxyg== Received: from [192.168.1.26] (st43p00im-dlb-asmtp-mailmevip.me.com [17.42.251.41]) by st43p00im-ztfb10071701.me.com (Postfix) with ESMTPSA id 88487CC01D9; Thu, 12 Dec 2024 13:40:21 +0000 (UTC) From: Zijun Hu Date: Thu, 12 Dec 2024 21:38:43 +0800 Subject: [PATCH v3 7/9] driver core: Correct parameter check for API device_for_each_child_reverse_from() 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: <20241212-class_fix-v3-7-04e20c4f0971@quicinc.com> References: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> In-Reply-To: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Tejun Heo , Josef Bacik , Jens Axboe , Boris Burkov , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams Cc: Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Proofpoint-GUID: tB6raR49I267QBFCsBauAbl4kPrToOFi X-Proofpoint-ORIG-GUID: tB6raR49I267QBFCsBauAbl4kPrToOFi 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-12_09,2024-12-12_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=881 malwarescore=0 bulkscore=0 clxscore=1015 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412120098 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu device_for_each_child_reverse_from() checks (!parent->p) for its parameter @parent, and that is not consistent with other APIs of its cluster as shown below: device_for_each_child_reverse_from() // check (!parent->p) device_for_each_child_reverse() // check (!parent || !parent->p) device_for_each_child() // same above device_find_child() // same above Correct the API's parameter @parent check by (!parent || !parent->p). Signed-off-by: Zijun Hu --- drivers/base/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 69bb6bf4bd12395226ee3c99e2f63d15c7e342a5..34fb13f914b3db47e6a047fdabf= 3c9b18ecc08cc 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4050,7 +4050,7 @@ int device_for_each_child_reverse_from(struct device = *parent, struct device *child; int error =3D 0; =20 - if (!parent->p) + if (!parent || !parent->p) return 0; =20 klist_iter_init_node(&parent->p->klist_children, &i, --=20 2.34.1 From nobody Wed Dec 17 12:46:24 2025 Received: from st43p00im-ztfb10071701.me.com (st43p00im-ztfb10071701.me.com [17.58.63.173]) (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 9A2B22153DD for ; Thu, 12 Dec 2024 13:40:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.63.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010844; cv=none; b=EHnDr1w39E/W5YGFK6xjPNSshxMZd3jjo72TbSsQuYWt4sGA1rxYZ45fK5Isd4NymYwi1+4PAYKTcpFy9IUk8uVsKdHge4WEV0ptuEkPQ3Y1MIxLpCSaGkcMFJHnZSLoUHSZTS6JKPxTmODavcEygHQGQPU9Na1fMyHNTrx0OoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010844; c=relaxed/simple; bh=z/rp7YoB2rkqBPSfvsltazJXGGbsmJYmnRsne4EWvT4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CWrJhTe2wlVDzQQB/GcrsAVvHZ52pbe9AgKsFy168z464CYzu3BGsDuxBTgYtNGIJ/bWMGTinXJnzTCuwuIPfMSzYltkPsXuLEs4QqGgCPmOLsVTRgL7F1CYuXb1L45XDjajJkFjyzbkyx1gTYHPx1ANZe6nn65HQCL34DJwxUs= 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=eKvtZ1kp; arc=none smtp.client-ip=17.58.63.173 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="eKvtZ1kp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734010841; bh=BCeIc0lcTP7COm5/43UbgSARtueD/CLiAEPuqWE662Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=eKvtZ1kpb45ZKo32/3+QuuyRCRfPKGpRLqJ/NaQig4Ei9hVU/BkANO+4EPuOzTTpm FVYaUTppJJh8dc75KE8XX5f4TAxEwSCkH4RTi3QuJS3aE6UJsgKEa9RQNqdsnlEDT9 pazNxbYenw41bXitJHVrGLDjrT5hAkYnlTk6FxovO2mPVqfvFVmciPCZ7rbRH7A2vm zeYer/BJYpa/Zi4jDokQvMtz+pICztu1t9qHmNUPSb42+1l/fDfWOe+ikm6/RrijmN yKoQ+8st9VplbT/fBpvAUjshxYXeCdox9VtSG+p6yjvEEw3wQm9hIdlD8m3yelpVxT SpcCoUgFUnQrg== Received: from [192.168.1.26] (st43p00im-dlb-asmtp-mailmevip.me.com [17.42.251.41]) by st43p00im-ztfb10071701.me.com (Postfix) with ESMTPSA id 6C413CC046B; Thu, 12 Dec 2024 13:40:30 +0000 (UTC) From: Zijun Hu Date: Thu, 12 Dec 2024 21:38:44 +0800 Subject: [PATCH v3 8/9] driver core: Correct API device_for_each_child_reverse_from() prototype 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: <20241212-class_fix-v3-8-04e20c4f0971@quicinc.com> References: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> In-Reply-To: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Tejun Heo , Josef Bacik , Jens Axboe , Boris Burkov , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams Cc: Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Proofpoint-GUID: 7sd0IW7OL1jTIq_U7vaQk7anaYDkdrS4 X-Proofpoint-ORIG-GUID: 7sd0IW7OL1jTIq_U7vaQk7anaYDkdrS4 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-12_09,2024-12-12_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412120098 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu For API device_for_each_child_reverse_from(..., const void *data, int (*fn)(struct device *dev, const void *data)) - Type of @data is const pointer, and means caller's data @*data is not allowed to be modified, but that usually is not proper for such non finding device iterating API. - Types for both @data and @fn are not consistent with all other for_each device iterating APIs device_for_each_child(_reverse)(), bus_for_each_dev() and (driver|class)_for_each_device(). Correct its prototype by removing const from parameter types, then adapt for various existing usages. An dedicated typedef device_iter_t will be introduced as @fn() type for various for_each device interating APIs later. Signed-off-by: Zijun Hu Reviewed-by: Jonathan Cameron --- drivers/base/core.c | 4 ++-- drivers/cxl/core/hdm.c | 2 +- drivers/cxl/core/region.c | 2 +- include/linux/device.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 34fb13f914b3db47e6a047fdabf3c9b18ecc08cc..7be9c732bec1b060a477b362f55= 5c3e87c8c7b91 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4043,8 +4043,8 @@ EXPORT_SYMBOL_GPL(device_for_each_child_reverse); * device_for_each_child_reverse_from(); */ int device_for_each_child_reverse_from(struct device *parent, - struct device *from, const void *data, - int (*fn)(struct device *, const void *)) + struct device *from, void *data, + int (*fn)(struct device *, void *)) { struct klist_iter i; struct device *child; diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index 28edd5822486851912393f066478252b20abc19d..50e6a45b30ba260c066a0781b9e= d3a2f6f3462d7 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -703,7 +703,7 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld) return 0; } =20 -static int commit_reap(struct device *dev, const void *data) +static int commit_reap(struct device *dev, void *data) { struct cxl_port *port =3D to_cxl_port(dev->parent); struct cxl_decoder *cxld; diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index bfecd71040c2f4373645380b4c31327d8b42d095..a4cff4c266e7a7dd6a3feb1513b= f14b7d3f9afa2 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -778,7 +778,7 @@ static size_t show_targetN(struct cxl_region *cxlr, cha= r *buf, int pos) return rc; } =20 -static int check_commit_order(struct device *dev, const void *data) +static int check_commit_order(struct device *dev, void *data) { struct cxl_decoder *cxld =3D to_cxl_decoder(dev); =20 diff --git a/include/linux/device.h b/include/linux/device.h index a9d928398895b062094b94f2c188cbe9951d7ac1..025bac08fca7b2513acb1fbcb66= 6be1dc64f03d1 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1079,8 +1079,8 @@ int device_for_each_child(struct device *parent, void= *data, int device_for_each_child_reverse(struct device *parent, void *data, int (*fn)(struct device *dev, void *data)); int device_for_each_child_reverse_from(struct device *parent, - struct device *from, const void *data, - int (*fn)(struct device *, const void *)); + struct device *from, void *data, + int (*fn)(struct device *, void *)); struct device *device_find_child(struct device *parent, const void *data, device_match_t match); struct device *device_find_child_by_name(struct device *parent, --=20 2.34.1 From nobody Wed Dec 17 12:46:24 2025 Received: from st43p00im-ztfb10071701.me.com (st43p00im-ztfb10071701.me.com [17.58.63.173]) (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 EDF532153DD for ; Thu, 12 Dec 2024 13:40:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.63.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010855; cv=none; b=IrUNynq5fcCvdJn+Oc30bPH2L8/h1jy9oxINmStXHvhNwPwQoR+8nbHhxf9V+c55QDpAvBDm+FTN/YgQNOL+x1Z0i+/O1WIoWJRYsELcO2CuGVnwsLwAVu9lMEIdR9MYxnS7+4MVfdltfoMF5BB1oxul8W02I8csEF5U1E8+GsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010855; c=relaxed/simple; bh=y9RQSXv1X/b7onq26soG95yWCh3wV1nPZhg2N7QA94I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U60/U9qOyg0VwBf1N1Ijl3euOXqMro8dEZFm/w0t7VJqUgJq+TnqzmnaxRsKR4LEprZfxVGvR/FO6fLV0AeEg1HhzAyABrt26dUhy3ltleYHrc0hEOAjvFnp9/9HI9FLTd4tBi9eVicOeC0YY6x90wwDgqDqGd95UV2WL4bLXAw= 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=b9rrj/mn; arc=none smtp.client-ip=17.58.63.173 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="b9rrj/mn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734010852; bh=aNctqcORfAEPE8lIZjnrCUjfsnSedHfS6VRbqUX7SHQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=b9rrj/mnnDVpn3vlwG4EWqSDqJUU/97nO526TwBQD8RIUyUjuaFxzKiuHzPXJUPvz kI080SReAu1u34fJ1G+eJ5bB15vqDHXhXBYiyqRm1cwQ6775oEFhynqGOYrBR8jies hGEMpYLnMW7tw+4lRa7AYVHBGISvdxoJ7oh5cnFAZO3kJ6EHYysf6N20SWA8oRsWb+ Wc7PSHCyaJnduEcSQSh/NWmS1BEvjgYcCHaaZvIQXWNcPobMr4iD4vMzdMNRRUeYaV 9z5ejIh+tFStrDHbIMG2XFBIeZpGDmJqrP50KmeIECFQeZulY9vBl4kB4DxQ89oX8r V20W0afioCW0Q== Received: from [192.168.1.26] (st43p00im-dlb-asmtp-mailmevip.me.com [17.42.251.41]) by st43p00im-ztfb10071701.me.com (Postfix) with ESMTPSA id 5F4E3CC0564; Thu, 12 Dec 2024 13:40:41 +0000 (UTC) From: Zijun Hu Date: Thu, 12 Dec 2024 21:38:45 +0800 Subject: [PATCH v3 9/9] driver core: Introduce device_iter_t for device iterating APIs 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: <20241212-class_fix-v3-9-04e20c4f0971@quicinc.com> References: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> In-Reply-To: <20241212-class_fix-v3-0-04e20c4f0971@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Tejun Heo , Josef Bacik , Jens Axboe , Boris Burkov , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams Cc: Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.2 X-Proofpoint-GUID: dpeo6YlG0e-Juhs4ByQzAKGAmtk4fdQW X-Proofpoint-ORIG-GUID: dpeo6YlG0e-Juhs4ByQzAKGAmtk4fdQW 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-12_09,2024-12-12_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412120098 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu There are several for_each APIs which has parameter with type below: int (*fn)(struct device *dev, void *data) They iterate over various device lists and call @fn() for each device with caller provided data @*data, and they usually need to modify @*data. Give the type an dedicated typedef with advantages shown below: typedef int (*device_iter_t)(struct device *dev, void *data) - Shorter API declarations and definitions - Prevent further for_each APIs from using bad parameter type So introduce device_iter_t and apply it to various existing APIs below: bus_for_each_dev() (class|driver)_for_each_device() device_for_each_child(_reverse|_reverse_from)(). Signed-off-by: Zijun Hu Reviewed-by: Jonathan Cameron --- drivers/base/bus.c | 2 +- drivers/base/class.c | 2 +- drivers/base/core.c | 6 +++--- drivers/base/driver.c | 2 +- include/linux/device.h | 6 +++--- include/linux/device/bus.h | 7 +++++-- include/linux/device/class.h | 4 ++-- include/linux/device/driver.h | 2 +- 8 files changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 73a56f376d3a05962ce0931a2fe8b4d8839157f2..6b9e65a42cd2e12046ddabf2d8d= fb209d513f7da 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -354,7 +354,7 @@ static struct device *next_device(struct klist_iter *i) * count in the supplied callback. */ int bus_for_each_dev(const struct bus_type *bus, struct device *start, - void *data, int (*fn)(struct device *, void *)) + void *data, device_iter_t fn) { struct subsys_private *sp =3D bus_to_subsys(bus); struct klist_iter i; diff --git a/drivers/base/class.c b/drivers/base/class.c index d57f277978dc9033fba3484b4620bcf884a4029f..70ee6a7ba5a3746b5a182c6101b= 5c085b424d01d 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -402,7 +402,7 @@ EXPORT_SYMBOL_GPL(class_dev_iter_exit); * code. There's no locking restriction. */ int class_for_each_device(const struct class *class, const struct device *= start, - void *data, int (*fn)(struct device *, void *)) + void *data, device_iter_t fn) { struct subsys_private *sp =3D class_to_subsys(class); struct class_dev_iter iter; diff --git a/drivers/base/core.c b/drivers/base/core.c index 7be9c732bec1b060a477b362f555c3e87c8c7b91..930e43a970952b20cd1c71856bd= ef889698f51b4 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3980,7 +3980,7 @@ const char *device_get_devnode(const struct device *d= ev, * other than 0, we break out and return that value. */ int device_for_each_child(struct device *parent, void *data, - int (*fn)(struct device *dev, void *data)) + device_iter_t fn) { struct klist_iter i; struct device *child; @@ -4010,7 +4010,7 @@ EXPORT_SYMBOL_GPL(device_for_each_child); * other than 0, we break out and return that value. */ int device_for_each_child_reverse(struct device *parent, void *data, - int (*fn)(struct device *dev, void *data)) + device_iter_t fn) { struct klist_iter i; struct device *child; @@ -4044,7 +4044,7 @@ EXPORT_SYMBOL_GPL(device_for_each_child_reverse); */ int device_for_each_child_reverse_from(struct device *parent, struct device *from, void *data, - int (*fn)(struct device *, void *)) + device_iter_t fn) { struct klist_iter i; struct device *child; diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 6f033a741aa7ce6138d1c61e49e72b2a3eb85e06..8ab010ddf709a2b173cfd0c1861= 0a122e58a2f4c 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -115,7 +115,7 @@ EXPORT_SYMBOL_GPL(driver_set_override); * Iterate over the @drv's list of devices calling @fn for each one. */ int driver_for_each_device(struct device_driver *drv, struct device *start, - void *data, int (*fn)(struct device *, void *)) + void *data, device_iter_t fn) { struct klist_iter i; struct device *dev; diff --git a/include/linux/device.h b/include/linux/device.h index 025bac08fca7b2513acb1fbcb666be1dc64f03d1..36d1a1607712f5a6b0668ac02a6= cf6b2d0651a2d 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1075,12 +1075,12 @@ void device_del(struct device *dev); DEFINE_FREE(device_del, struct device *, if (_T) device_del(_T)) =20 int device_for_each_child(struct device *parent, void *data, - int (*fn)(struct device *dev, void *data)); + device_iter_t fn); int device_for_each_child_reverse(struct device *parent, void *data, - int (*fn)(struct device *dev, void *data)); + device_iter_t fn); int device_for_each_child_reverse_from(struct device *parent, struct device *from, void *data, - int (*fn)(struct device *, void *)); + device_iter_t fn); struct device *device_find_child(struct device *parent, const void *data, device_match_t match); struct device *device_find_child_by_name(struct device *parent, diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index bc3fd74bb763e6d2d862859bd2ec3f0d443f2d7a..3d3517da41a141aeadc8f219a44= fd360cfd931ff 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -139,9 +139,12 @@ int device_match_acpi_dev(struct device *dev, const vo= id *adev); int device_match_acpi_handle(struct device *dev, const void *handle); int device_match_any(struct device *dev, const void *unused); =20 +/* Device iterating function type for various driver core for_each APIs */ +typedef int (*device_iter_t)(struct device *dev, void *data); + /* iterator helpers for buses */ -int bus_for_each_dev(const struct bus_type *bus, struct device *start, voi= d *data, - int (*fn)(struct device *dev, void *data)); +int bus_for_each_dev(const struct bus_type *bus, struct device *start, + void *data, device_iter_t fn); struct device *bus_find_device(const struct bus_type *bus, struct device *= start, const void *data, device_match_t match); /** diff --git a/include/linux/device/class.h b/include/linux/device/class.h index 518c9c83d64bdf85bb5607cea6ea640884ec3460..aa67d473681612f24a4569bf82f= e5f91237d5a50 100644 --- a/include/linux/device/class.h +++ b/include/linux/device/class.h @@ -92,8 +92,8 @@ void class_dev_iter_init(struct class_dev_iter *iter, con= st struct class *class, struct device *class_dev_iter_next(struct class_dev_iter *iter); void class_dev_iter_exit(struct class_dev_iter *iter); =20 -int class_for_each_device(const struct class *class, const struct device *= start, void *data, - int (*fn)(struct device *dev, void *data)); +int class_for_each_device(const struct class *class, const struct device *= start, + void *data, device_iter_t fn); struct device *class_find_device(const struct class *class, const struct d= evice *start, const void *data, device_match_t match); =20 diff --git a/include/linux/device/driver.h b/include/linux/device/driver.h index 5c04b8e3833b995f9fd4d65b8732b3dfce2eba7e..cd8e0f0a634be9ea63ff22e89d6= 6ada3b1a9eaf2 100644 --- a/include/linux/device/driver.h +++ b/include/linux/device/driver.h @@ -154,7 +154,7 @@ void driver_remove_file(const struct device_driver *dri= ver, int driver_set_override(struct device *dev, const char **override, const char *s, size_t len); int __must_check driver_for_each_device(struct device_driver *drv, struct = device *start, - void *data, int (*fn)(struct device *dev, void *)); + void *data, device_iter_t fn); struct device *driver_find_device(const struct device_driver *drv, struct device *start, const void *data, device_match_t match); --=20 2.34.1