From patchwork Sun Jan 5 08:34:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13926438 Received: from pv50p00im-zteg10011501.me.com (pv50p00im-zteg10011501.me.com [17.58.6.42]) (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 BFCBD13665A for ; Sun, 5 Jan 2025 08:34:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066101; cv=none; b=VEXkUmGKpTXmK1av9IowYpRxXmDjcwIjhS4Y1zCQkdpE7QtQph0lalRJuuw+ZpYHqOJiYJALEJhaLN2ThXKy7yllkZO5XkdoniUhOcGQhQnFnGBqq3jYFzDV7x9uQywLyne5KLowKlqcV1LZai/IdPA0JKy3n2i5+rlC3IgVO4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066101; c=relaxed/simple; bh=8mn6t+QHjDaf7J6kc9SMk308hna52jlveGFlyTvTj3U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=owknvM1bHGjkZJ6eEPPuG0cAhra/eo5O1UHXMyo/LFdzKIYTsaqqSh6bmRphDTVSnZ+xxZf/M2dGQiN3dgHXj96ht0H/C905om7zVT4g7m6CXP8zw5IXI5lyJhV5ab/yI03oCqY1QtRNE4GtsAF2GJ2AngnGId0p11lercuFnRo= 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=bzdvFp3x; arc=none smtp.client-ip=17.58.6.42 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="bzdvFp3x" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1736066099; bh=P8XwY4in8iMuG1/djQ6xOUQq3gJGLhNX0HGYx/Z+xcU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=bzdvFp3xCqWY8Yf/alIXR2a5RlUyNeBDIUV11A2Io62XphNFZ0WKaKau6Qs2tgohI VLg5EZYajlYFgWm3sVHRjii09acIYnDCtuK2QiiscAB5Ygl+OHYeZprMpsRX7q3CYH z42Zk6wuGhicXp8JI4aY7UhwdxHHu871rvJ/yP2sagOqowdwffczEUlJs+vbSRNkLn gfnO4YFCL6UotOD6HKDYaqtIPpib7TLSv03o6Empm5bxQV/niX7nn+9ATAPVvblA3w IB0vxgoNtH/mr+zuQkaejS9UkkjSW63V9Xl9wAbn7wrukLVJW/zrCniMQbZt0NkJ7e nG9cQGBv7Gz3Q== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011501.me.com (Postfix) with ESMTPSA id 662BF4A046F; Sun, 5 Jan 2025 08:34:48 +0000 (UTC) From: Zijun Hu Date: Sun, 05 Jan 2025 16:34:02 +0800 Subject: [PATCH v6 1/8] driver core: class: Fix wild pointer dereferences in API class_dev_iter_next() Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250105-class_fix-v6-1-3a2f1768d4d4@quicinc.com> References: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> In-Reply-To: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> To: Greg Kroah-Hartman Cc: "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 , Danilo Krummrich , Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu , Jonathan Cameron X-Mailer: b4 0.14.2 X-Proofpoint-GUID: lOP8nsuFbAq0B-ytUJPIZvF9wJO83EQR X-Proofpoint-ORIG-GUID: lOP8nsuFbAq0B-ytUJPIZvF9wJO83EQR 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=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=951 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050078 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 = 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_subsys") Reviewed-by: Jonathan Cameron 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..d57f277978dc9033fba3484b4620bcf884a4029f 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 = class_to_subsys(class); struct klist_node *start_knode = NULL; - if (!sp) + memset(iter, 0, sizeof(*iter)); + if (!sp) { + pr_crit("%s: class %p was not registered yet\n", + __func__, class); return; + } if (start) start_knode = &start->p->knode_class; @@ -351,6 +355,9 @@ struct device *class_dev_iter_next(struct class_dev_iter *iter) struct klist_node *knode; struct device *dev; + if (!iter->sp) + return NULL; + while (1) { knode = klist_next(&iter->ki); if (!knode) From patchwork Sun Jan 5 08:34:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13926439 Received: from pv50p00im-zteg10011501.me.com (pv50p00im-zteg10011501.me.com [17.58.6.42]) (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 CF56013DDD3 for ; Sun, 5 Jan 2025 08:35:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066113; cv=none; b=khVN0lFQBzAowU7MPNfIk2A4JUIws/3U4DLrrLXePpSBKGiyKedPjOLQ0JinF0umxwsrpjHfIgnBbd2OrekVL0qqp9t4rjM2U0EcHaC+e9HwTitrPvc0ADBE9GKu3l0q6lLoyyZQp3vc6yKKy2dpdq1q6horp44tdQTRzHfsbFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066113; c=relaxed/simple; bh=zSgsbc2+Pi+ODyhW3qjEswcLb/PTSbNrr4ZLFp6ATx4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q+hGV5nkV0DcxOaPIsID5woZfhaBFiWZ+SAKZIvwgjXWUQWO1b8P1+9FGsrexmqkMyyMDteVStpV6nJAKsoj7prBomMUM42BC+dVUKa7YnLJ3MI7PVcBfZEt9uuLd1cb46LAeFay2+dH16ZnkW2NzSSH9ZQeXyWgmgMb2yb8Yig= 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=fNqtJsOU; arc=none smtp.client-ip=17.58.6.42 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="fNqtJsOU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1736066110; bh=lGL3paFjtP/XxIRaogpvMdvoANfFZCRy3MMPglF6rwE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=fNqtJsOUzo2XKcy6Rl9qmJU1Tpa/2/bwOycIuwsk18SjymNRvauuHRsJrAMTt1dOU XvCOctvdIK4fLP9eSg9M4VbYnqYX+FEHJqLTDQljrf7m98ZKIO5/6SwZX4hUYR0HhC qmrVCq+WGWchf8WUd19VonTfqpoUh5nrCwtrmmHSXaze5Pd6jCzbvKQpkxuoKESYwP Zw+q6bKm7/m5Gbx2YFhs6P1xysi8+OFgAN+n83ihMjb0ZKkiZl5N5bWQFBIXBUq3LJ xxOTj0J31avPuWdNlmICZO9k5O8j7W2YAs+WaE9QNIvghojGmvdTQ3PSMl1tQx5j8f 5/ppgj1GrGF+Q== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011501.me.com (Postfix) with ESMTPSA id 2CCA74A0349; Sun, 5 Jan 2025 08:34:59 +0000 (UTC) From: Zijun Hu Date: Sun, 05 Jan 2025 16:34:03 +0800 Subject: [PATCH v6 2/8] blk-cgroup: Fix class @block_class's subsystem refcount leakage Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250105-class_fix-v6-2-3a2f1768d4d4@quicinc.com> References: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> In-Reply-To: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> To: Greg Kroah-Hartman Cc: "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 , Danilo Krummrich , Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu , =?utf-8?q?M?= =?utf-8?q?ichal_Koutn=C3=BD?= , stable@vger.kernel.org X-Mailer: b4 0.14.2 X-Proofpoint-GUID: 1x07iJu_72U2SUGVbMN69LyUMf05-4MV X-Proofpoint-ORIG-GUID: 1x07iJu_72U2SUGVbMN69LyUMf05-4MV 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=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050078 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") Reviewed-by: Michal Koutný Cc: Greg Kroah-Hartman Cc: stable@vger.kernel.org Acked-by: Tejun Heo Signed-off-by: Zijun Hu --- block/blk-cgroup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 45a395862fbc88f448fe281eeac620710bc1587d..f1cf7f2909f3a74f245ece8bc2fa918776ffbc55 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); } static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s) From patchwork Sun Jan 5 08:34:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13926440 Received: from pv50p00im-zteg10011501.me.com (pv50p00im-zteg10011501.me.com [17.58.6.42]) (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 C3A54145A0F for ; Sun, 5 Jan 2025 08:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066123; cv=none; b=Z3L1SOUOIpG5U4QCh9o3rF7sEAiauFw05sEZeSDeladwCjH5t1LIRX/jhC14exFpRKpDKaTorTmZjvIvx66IEp6BwBwWy/2gSyxK5+UmxbnRCf9bHeCwNZvAqOwzobKojiYOV8XHPocmuEiYECd2eGBLXoNMrCpeq5ffa4/V9vQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066123; c=relaxed/simple; bh=nHUKjtCa84MPYL+GlDf95K/i7UhG7yvj3y1scXIZ0aM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lDFcDuTdv88C+L3VnYzoP2xchaCwfhoP/faa823KXg7a+4LWRW2Rlvgj5OUJaEV6SFO+DzI3oTE1upfM8x8Zxaw/MTkfdQYNSLGrmvqUrkUPk4vqomO97jNIXtr26D4XNA+NsNvvPBOOV01ZrEpRoAvLGRWn7qrI6+lOQPqBplE= 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=nfoXIRM6; arc=none smtp.client-ip=17.58.6.42 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="nfoXIRM6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1736066121; bh=IFL4sqkTU02o6bt1eHtOI9QlAEJv+Hc92FiAS7SV86Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=nfoXIRM6+N3YTu3fDz2lKFbV2AjxC8eDDQU/Vr1YoioB1Ai/dl3o+92ZYYiNJEKVM ElNlsMfim24Hgs+rqvhD5n9LGkm1KrAWmksZLKx9GzWi+iIm/Hr1NaYZuBvme1xfYa I2kIGVmS3p9Bxhyz1FkaKpYJw8zsF5MKlsHhYfQwsbUtl/DxBucwzdUo6G9bncwYJX 3LEFHK07PNYzuHSetyDV32mz3yUf474DYCEDZ1QGW03up9QceQSbakjMgFRADDiDyd pAjZZ9pS/ZJZtI9u880V2/6hZX8XF9ug4H9EFGTHQ08xJDAEV68b7Dtig/O6k1DgKB SgO96LSrnY08A== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011501.me.com (Postfix) with ESMTPSA id 471924A049A; Sun, 5 Jan 2025 08:35:10 +0000 (UTC) From: Zijun Hu Date: Sun, 05 Jan 2025 16:34:04 +0800 Subject: [PATCH v6 3/8] driver core: Move true expression out of if condition in 3 device finding APIs Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250105-class_fix-v6-3-3a2f1768d4d4@quicinc.com> References: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> In-Reply-To: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> To: Greg Kroah-Hartman Cc: "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 , Danilo Krummrich , Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu , Fan Ni , Jonathan Cameron X-Mailer: b4 0.14.2 X-Proofpoint-GUID: EDQToYwsTqdg8GcAexXi0X55ZHrCcmKW X-Proofpoint-ORIG-GUID: EDQToYwsTqdg8GcAexXi0X55ZHrCcmKW 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=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050078 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu For bus_find_device(), driver_find_device(), and device_find_child(), all of their function body have pattern below: { struct klist_iter i; struct device *dev; ... while ((dev = next_device(&i))) if (match(dev, data) && get_device(dev)) break; ... } The expression 'get_device(dev)' in the if condition always returns true since @dev != NULL. Move the expression to if body to make logic of these APIs more clearer. Reviewed-by: Fan Ni Reviewed-by: Jonathan Cameron Signed-off-by: Zijun Hu --- drivers/base/bus.c | 7 +++++-- drivers/base/core.c | 7 +++++-- drivers/base/driver.c | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 657c93c38b0dc2a2247e5f482fadd3a9376a58e8..73a56f376d3a05962ce0931a2fe8b4d8839157f2 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, klist_iter_init_node(&sp->klist_devices, &i, (start ? &start->p->knode_bus : NULL)); - while ((dev = next_device(&i))) - if (match(dev, data) && get_device(dev)) + while ((dev = next_device(&i))) { + if (match(dev, data)) { + get_device(dev); break; + } + } klist_iter_exit(&i); subsys_put(sp); return dev; diff --git a/drivers/base/core.c b/drivers/base/core.c index d4c20e9b23da71e9afb11108cf4353ed1b47f591..a83a1350fb5b2baa5e4ee0f5e5805a5bee536ec7 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4089,9 +4089,12 @@ struct device *device_find_child(struct device *parent, const void *data, return NULL; klist_iter_init(&parent->p->klist_children, &i); - while ((child = next_device(&i))) - if (match(child, data) && get_device(child)) + while ((child = next_device(&i))) { + if (match(child, data)) { + get_device(child); break; + } + } klist_iter_exit(&i); return child; } diff --git a/drivers/base/driver.c b/drivers/base/driver.c index b4eb5b89c4ee7bc35458fc75730b16a6d1e804d3..6f033a741aa7ce6138d1c61e49e72b2a3eb85e06 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, klist_iter_init_node(&drv->p->klist_devices, &i, (start ? &start->p->knode_driver : NULL)); - while ((dev = next_device(&i))) - if (match(dev, data) && get_device(dev)) + while ((dev = next_device(&i))) { + if (match(dev, data)) { + get_device(dev); break; + } + } klist_iter_exit(&i); return dev; } From patchwork Sun Jan 5 08:34:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13926441 Received: from pv50p00im-zteg10011501.me.com (pv50p00im-zteg10011501.me.com [17.58.6.42]) (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 1643D136E3F for ; Sun, 5 Jan 2025 08:35:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066135; cv=none; b=ZqUw7wIoz4IfGQ3Xq5LSldfxezvUxLkVpILs4pzCE5pJSRcr4PCZux/ssmY1JqvRgaV67mw74flgFizkCBMQK3GI9Q4Y8u2K41fuQ9qXHzB0rfIqDcszdye46+eZtsn96FttvPsZb7GqiOtyrl9f7KBsXYdYZW0+Z4xT5yMN7n4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066135; c=relaxed/simple; bh=r1myTHTt6RqQBq+qIcrBHUm5l/c3S1IeRV2Ch3Esx2E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s2Ed6YZ9hYKifuKcI9lULNM66pgfTwAdkTyxibaZdKDB+k4qxaTsYv7G5hd9i1zlcxeVl7hyM8VtwWqK5+6Yi/YyJRPPQEsTGzft+5t2DdM2oiHnwlROesOiyO/7VFgvpGpT2I+LSO+QTcU0hhuyjKynNwuEHYtwZNMEQGCXYhQ= 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=eaCBSM2G; arc=none smtp.client-ip=17.58.6.42 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="eaCBSM2G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1736066132; bh=bpdPHGVvsNjPbtVeiARlh6UhJFtwCfTalqRar5MzOl4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=eaCBSM2G+TeHwDF09uDQGvbhZ7n1Hc8o1kKaxNfNXbMGSEYmmqiG+cWPkKNapf+QA xgkYLn5aOKygXgdAISBQF39wHvFRwICVRet/74loPtk9K3K1dxr+ZwlpT7E3n69v/L rgjt4jqzvHSa+ZKf1lymo+85RhtTy4Hkq2/+PM8O44iRN1O8x3HGsfqh5qEQ6GFM79 2zyEfBPl3BH5za5trVhoT26lPbJfP8QYIdgJLPPUTRuR6bMUTu5KHBw8tb7yBQnuME kcvjdxc4KXlm8nZtubyyCvBuUeDyLSu2//5B+W7uRJ6uWlLxgNYZJ+NYyZq2vNbnrD 5M8yvBBYmJXXA== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011501.me.com (Postfix) with ESMTPSA id 571724A01FE; Sun, 5 Jan 2025 08:35:21 +0000 (UTC) From: Zijun Hu Date: Sun, 05 Jan 2025 16:34:05 +0800 Subject: [PATCH v6 4/8] driver core: Rename declaration parameter name for API device_find_child() cluster Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250105-class_fix-v6-4-3a2f1768d4d4@quicinc.com> References: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> In-Reply-To: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> To: Greg Kroah-Hartman Cc: "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 , Danilo Krummrich , Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu , Fan Ni , Jonathan Cameron X-Mailer: b4 0.14.2 X-Proofpoint-GUID: _7sbAjSMV71f8--LJCaWVvr4sQagM1Ue X-Proofpoint-ORIG-GUID: _7sbAjSMV71f8--LJCaWVvr4sQagM1Ue 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=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050078 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. Reviewed-by: Fan Ni Reviewed-by: Jonathan Cameron Signed-off-by: Zijun Hu --- 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..a9d928398895b062094b94f2c188cbe9951d7ac1 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1074,14 +1074,14 @@ void device_del(struct device *dev); DEFINE_FREE(device_del, struct device *, if (_T) device_del(_T)) -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); From patchwork Sun Jan 5 08:34:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13926442 Received: from pv50p00im-zteg10011501.me.com (pv50p00im-zteg10011501.me.com [17.58.6.42]) (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 D46831474C9 for ; Sun, 5 Jan 2025 08:35:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066147; cv=none; b=s3ZbJfxRGp3FmV5wCAxx8cfVjs/ZLv9xZ+wc3cnJssfpb70xIYeYJfzSZ4GWfvqrxR5qjmnRhbuHnsGj9Fuwo6zQ1qf4HZqH4Bp4Tycgzxg5Kl5Y7lmJE52Sj+UJuGYSpuHfzetP0O3XMYVGuZ4qq4Axo5zeWio246lB7kJouv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066147; c=relaxed/simple; bh=gCtVgE/p6B7cb/mIY4S5SzULQWHKTBzF14LVzxG8qd4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DZF3S10ytcIiO8M0cH44Vf4tyEq1GOsz57ub6lsVS9TwmrY9oSCp9tE11+BSbl+L8kOqUunjZ6xt5Hkn6lj86dg8yaPuCKwVkm2ommpMVbfa6uwgFMeM2ZrPRrfb9QHfS8Y6gmrSkRz/DEMVXM0aAUd3d2fGFb6U/Ylfj/EpHsk= 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=f5W8D8Bj; arc=none smtp.client-ip=17.58.6.42 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="f5W8D8Bj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1736066143; bh=v7TY2cXo1rPKtE2u6WFZ8DXwANe3uGTSZ6dUA30jYLw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=f5W8D8BjofRPSSLCnjULS1vEQX0Php5sHsMwl6eTPWnhuKEjud4OqI/ISbb6jhJzi J3hIJ4BUM9IR6uJpF8pZzxlMiYiGNn8DcNru3ZvVGbfWZxNdfTt8cqcNB1Q1BN3f7o TkwqTo3AD19uPMLTw/45ByJ0xg0zm6LQCqIIZPpf23eKd/Af9b2N1elmb6n7M0d/47 oDb3q4C3yHaeoFbEM/v3p6TGtxYKaTBH+jigUHMC47EPIB9oY2+icme8T2nsT/Xra1 fhpvgYZzVHV1HhAXthU91g8VG/JKqBGNgh/nJbOkp1w6d0nTFXgmnPfzViQ+nOCpXA zykVjLJ+DKyAw== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011501.me.com (Postfix) with ESMTPSA id 642214A02C4; Sun, 5 Jan 2025 08:35:32 +0000 (UTC) From: Zijun Hu Date: Sun, 05 Jan 2025 16:34:06 +0800 Subject: [PATCH v6 5/8] driver core: Correct parameter check for API device_for_each_child_reverse_from() Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250105-class_fix-v6-5-3a2f1768d4d4@quicinc.com> References: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> In-Reply-To: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> To: Greg Kroah-Hartman Cc: "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 , Danilo Krummrich , Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu , Jonathan Cameron X-Mailer: b4 0.14.2 X-Proofpoint-GUID: 7RSf8dCEIok0jeq83oKz6VFGuEeF6iUQ X-Proofpoint-ORIG-GUID: 7RSf8dCEIok0jeq83oKz6VFGuEeF6iUQ 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=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=710 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050078 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). Reviewed-by: Jonathan Cameron 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 a83a1350fb5b2baa5e4ee0f5e5805a5bee536ec7..d3800f0dc5bbd2a7de80bd58b50e31038265da03 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 = 0; - if (!parent->p) + if (!parent || !parent->p) return 0; klist_iter_init_node(&parent->p->klist_children, &i, From patchwork Sun Jan 5 08:34:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13926443 Received: from pv50p00im-zteg10011501.me.com (pv50p00im-zteg10011501.me.com [17.58.6.42]) (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 39133145B3E for ; Sun, 5 Jan 2025 08:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066156; cv=none; b=q7S8Zy0pkXEPOcB8H/KQRGEE6ewVTcHAHnLTcp4Fv84JSnBGwna01CfHUfOUx4vvb2UEckqsja/ipudYC6mXDkHf7Mr9brW8Z/UVdW/wBOa5IvTXs+t0Oxoj/WYg/Ny2uFtfaFV77dBspiPdbVFug7Gr/IMHlAPybYJLn3Fr9Ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066156; c=relaxed/simple; bh=YvTwIFgTC/LWB3xoEjTly9oluEvizWxESpju05AN3zY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FL/zwSdJXQB7irY7oQqUafPRaPZDCyNpxEIvSy/8IeRZ/pv8z+iFmwot+jwoIEMXZeTu5G+bEjuYGRCfY8GaKpmxdo7n10nzrsQ5sLCBkKcxKnqS/hmorjGbioEi7RI28An+5tBs0N1ZG/ftLJHt6+c7FAnsvMyM7ABMpaXCEU0= 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=QITSaLyC; arc=none smtp.client-ip=17.58.6.42 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="QITSaLyC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1736066154; bh=GWyxZJvp+QefrwRwUKuyaovvJfEK4jbeqXubth0Rhss=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=QITSaLyCaQHCO5/cx1y4M9euWrtaSPdjV8scxiPI2Etas/kQME9gPiF5P+e6q2hns 82NNONa7quQVGaxZ+lkrNEglNoEghhlKBgsNA7W3ir8KIE6Fu7mKlvvJbTj9Pc1ebI BEGTnbRJ/CfIhaqocO8hCKMHWn/GXW1bYxWJiyJqGQHRWW3xnegQ0yqLGTQH1NVml/ gzlHz2G3J5ytrDb+wcRWMboh3JSE4kMEaeZ5hPg5Fc24aUxJIH7DUzJkYnzTSQcXx8 uJpEmgAkEC0MLtaAxLKa2JhXyafM2Zl29vm+23DkzOdtTGoBMxLjfaIDmbHZhsTRxp Q5Jl+ZOrGbcww== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011501.me.com (Postfix) with ESMTPSA id 072064A035B; Sun, 5 Jan 2025 08:35:43 +0000 (UTC) From: Zijun Hu Date: Sun, 05 Jan 2025 16:34:07 +0800 Subject: [PATCH v6 6/8] driver core: Correct API device_for_each_child_reverse_from() prototype Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250105-class_fix-v6-6-3a2f1768d4d4@quicinc.com> References: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> In-Reply-To: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> To: Greg Kroah-Hartman Cc: "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 , Danilo Krummrich , Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu , Jonathan Cameron X-Mailer: b4 0.14.2 X-Proofpoint-GUID: ZDKzlXVJGiCGPnlnrANJbdIvS6hgwJdu X-Proofpoint-ORIG-GUID: ZDKzlXVJGiCGPnlnrANJbdIvS6hgwJdu 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=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=879 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050078 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. Reviewed-by: Jonathan Cameron Signed-off-by: Zijun Hu --- 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 d3800f0dc5bbd2a7de80bd58b50e31038265da03..5ee53b3bca6a4b4e1fa3cc3c8acd63ed7fd01b63 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..50e6a45b30ba260c066a0781b9ed3a2f6f3462d7 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; } -static int commit_reap(struct device *dev, const void *data) +static int commit_reap(struct device *dev, void *data) { struct cxl_port *port = 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..a4cff4c266e7a7dd6a3feb1513bf14b7d3f9afa2 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, char *buf, int pos) return rc; } -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 = to_cxl_decoder(dev); diff --git a/include/linux/device.h b/include/linux/device.h index a9d928398895b062094b94f2c188cbe9951d7ac1..025bac08fca7b2513acb1fbcb666be1dc64f03d1 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, From patchwork Sun Jan 5 08:34:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13926444 Received: from pv50p00im-zteg10011501.me.com (pv50p00im-zteg10011501.me.com [17.58.6.42]) (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 DFC4F145B1B for ; Sun, 5 Jan 2025 08:36:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066168; cv=none; b=MrUdKyq7nnjjDSh9CsztRWn3gx9C6su8iONZcUIMtdvF1e0RlpaWOOFUysfUBJNJz5NmCQMKSWgtZCQU7veHxcucIN9lgXsLalTrLDq676Yb6YVYjmdn+L5Jb5+fibKpxLxXq05ZjoHJLr2krB05EW/mY4IPHPNVr3ngFZElyUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066168; c=relaxed/simple; bh=+c9TZmPh04rE16gDqqHrxut385V3/n7zCquQuNVLy+w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dko5GmcFcR6lDQvB+4iRsm8RqkyKEPny9TLV01o/ElQ6owQmj/F1caryyiHo1ajX1yMfUk5keQphV8nnR0YV8RBMI6nPn4yuEGvLm/yY9IvDFnBS3q2VLJ3iJJpbjQGc3dJrMroehqFHt/rWosOzeEqiztMwkittvWhccITNrkk= 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=XlkpuupH; arc=none smtp.client-ip=17.58.6.42 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="XlkpuupH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1736066164; bh=PiAv5BOHu8VoDkScQbA1zOtSEi5oMSZCHfxz8xRr84w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=XlkpuupHVpC/5PqiTpQfWKfi61u+LSJCiN+ZNP55BUBp3/5+R71bC7YVUPQOONRd0 Aia4aHKCB6S8mDlHPaQGcA4KClCRiyredQD+oW41q2pWtB7NKim28I3SppqNm+ZHpG JbNe22dA8ex+yoUrEl5ixCOv0RXWSb6ZaNaFVsTU+ZxRx9LBDW+yODcHSNor/AsQQh tYL27WX9OAeDtXzrN0++FaC7ksViRvUsGpLa/JqmvLSAn5WYQVkMBFbPjmwxcEeJ+Z 49BdHmPfxv06mmAoE5OJuB3WRnQnk2PtBOsjg8P3MWemJct7NEkjSPzmH88kSLaiag yzQqLmTlvLZLQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011501.me.com (Postfix) with ESMTPSA id C0E314A02B4; Sun, 5 Jan 2025 08:35:54 +0000 (UTC) From: Zijun Hu Date: Sun, 05 Jan 2025 16:34:08 +0800 Subject: [PATCH v6 7/8] driver core: Introduce device_iter_t for device iterating APIs Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250105-class_fix-v6-7-3a2f1768d4d4@quicinc.com> References: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> In-Reply-To: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> To: Greg Kroah-Hartman Cc: "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 , Danilo Krummrich , Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu , Jonathan Cameron X-Mailer: b4 0.14.2 X-Proofpoint-GUID: qrSn2kltzWuiU6NeTzcSFFskHe6-EEDZ X-Proofpoint-ORIG-GUID: qrSn2kltzWuiU6NeTzcSFFskHe6-EEDZ 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=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050078 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)(). Reviewed-by: Jonathan Cameron Signed-off-by: Zijun Hu --- 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..6b9e65a42cd2e12046ddabf2d8dfb209d513f7da 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 = bus_to_subsys(bus); struct klist_iter i; diff --git a/drivers/base/class.c b/drivers/base/class.c index d57f277978dc9033fba3484b4620bcf884a4029f..70ee6a7ba5a3746b5a182c6101b5c085b424d01d 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 = class_to_subsys(class); struct class_dev_iter iter; diff --git a/drivers/base/core.c b/drivers/base/core.c index 5ee53b3bca6a4b4e1fa3cc3c8acd63ed7fd01b63..7d79a0549ac7bdaeb18e8c5ded11e10578460fcf 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3980,7 +3980,7 @@ const char *device_get_devnode(const struct device *dev, * 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..8ab010ddf709a2b173cfd0c18610a122e58a2f4c 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..36d1a1607712f5a6b0668ac02a6cf6b2d0651a2d 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)) 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..3d3517da41a141aeadc8f219a44fd360cfd931ff 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 void *adev); int device_match_acpi_handle(struct device *dev, const void *handle); int device_match_any(struct device *dev, const void *unused); +/* 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, void *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..aa67d473681612f24a4569bf82fe5f91237d5a50 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, const struct class *class, struct device *class_dev_iter_next(struct class_dev_iter *iter); void class_dev_iter_exit(struct class_dev_iter *iter); -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 device *start, const void *data, device_match_t match); diff --git a/include/linux/device/driver.h b/include/linux/device/driver.h index 5c04b8e3833b995f9fd4d65b8732b3dfce2eba7e..cd8e0f0a634be9ea63ff22e89d66ada3b1a9eaf2 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 *driver, 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); From patchwork Sun Jan 5 08:34:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13926445 Received: from pv50p00im-zteg10011501.me.com (pv50p00im-zteg10011501.me.com [17.58.6.42]) (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 D568414831D for ; Sun, 5 Jan 2025 08:36:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066178; cv=none; b=C/tel40Q2mpp9n+BqmAnRHeZwBl74zyqmkW6zyHMDtIWBfwCTN+FehfPHarFBUwfjSGDQlmw0RzWwk7gkfw8WJEEGG1CAACKthSml7pkLLV1f1WH4PBGCslnbF/UOFWYK3ERWGY2pwfy2GPhNzDZr3k1D/pENwrEgD16LuIHjxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736066178; c=relaxed/simple; bh=kix07/ATA0RCVGyR9CMY/mpudQLlSvHm/p3QFF31A1g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jhd77fvIs/Rh6wRKZh7Lr0H4B4gSsOgLJKEYUojZY9owOikUxp7IvLOOY/dxa5Tw39yRIe6+bo51uNRH7ikKNK+5UNGaubGBi9RvvkMl+NZdkLd3lWGwasrdiYVycCwRpLaNR8ATEwbk65Tjodt3+P0fN6RcFah1e6S4DKTLayI= 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=uNlvC6dd; arc=none smtp.client-ip=17.58.6.42 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="uNlvC6dd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1736066175; bh=A9B07nUyN5uJwukRlcamTQt7ZH+BiUzxshMG2DrZvBk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=uNlvC6ddxQF/8s1E4qRpjorG5DSFlDkZUldZzFgo53IecJusO2CWMEniF9Cl9cWHV Il/tjiPZevVHlx172CNH2hEfIUT6I3b75lUUgMMdf+ihqqNVLX9NpK4ewt3vP9IWm+ smNL+6KSuUWMlEY6etZl7usEp2zPGBvkVlTJ4kgLLJXVMm6NqlU1/V8gLVp5Lr19hI 9VA+F+UIphfC92rGBL16QogQEG6df3XN2BJyFHnExQ966uk90fCClZLzTzouj5OcoN z8Y/ac8Zio413f5ysUgS9BIBnIxs70tNDW8oTEVjbfcWaLeJv3PH5ip5wcc6F56/fq qU+dOrvq43rUQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011501.me.com (Postfix) with ESMTPSA id 9D0BC4A039E; Sun, 5 Jan 2025 08:36:05 +0000 (UTC) From: Zijun Hu Date: Sun, 05 Jan 2025 16:34:09 +0800 Subject: [PATCH v6 8/8] driver core: Move two simple APIs for finding child device to header Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250105-class_fix-v6-8-3a2f1768d4d4@quicinc.com> References: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> In-Reply-To: <20250105-class_fix-v6-0-3a2f1768d4d4@quicinc.com> To: Greg Kroah-Hartman Cc: "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 , Danilo Krummrich , Zijun Hu , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-cxl@vger.kernel.org, Zijun Hu , Jonathan Cameron X-Mailer: b4 0.14.2 X-Proofpoint-GUID: Sl6ULH1Q5gEpDGYq26JTHxCP8ve_x9HD X-Proofpoint-ORIG-GUID: Sl6ULH1Q5gEpDGYq26JTHxCP8ve_x9HD 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=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=907 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050078 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu The following two APIs are for finding child device, and both only have one line code in function body. device_find_child_by_name() device_find_any_child() Move them to header as static inline function. Reviewed-by: Jonathan Cameron Signed-off-by: Zijun Hu --- drivers/base/core.c | 32 -------------------------------- include/linux/device.h | 32 +++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 7d79a0549ac7bdaeb18e8c5ded11e10578460fcf..5a1f051981149dc5b5eee4fb69c0ab748a85956d 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4100,38 +4100,6 @@ struct device *device_find_child(struct device *parent, const void *data, } EXPORT_SYMBOL_GPL(device_find_child); -/** - * device_find_child_by_name - device iterator for locating a child device. - * @parent: parent struct device - * @name: name of the child device - * - * This is similar to the device_find_child() function above, but it - * returns a reference to a device that has the name @name. - * - * NOTE: you will need to drop the reference with put_device() after use. - */ -struct device *device_find_child_by_name(struct device *parent, - const char *name) -{ - return device_find_child(parent, name, device_match_name); -} -EXPORT_SYMBOL_GPL(device_find_child_by_name); - -/** - * device_find_any_child - device iterator for locating a child device, if any. - * @parent: parent struct device - * - * This is similar to the device_find_child() function above, but it - * returns a reference to a child device, if any. - * - * NOTE: you will need to drop the reference with put_device() after use. - */ -struct device *device_find_any_child(struct device *parent) -{ - return device_find_child(parent, NULL, device_match_any); -} -EXPORT_SYMBOL_GPL(device_find_any_child); - int __init devices_init(void) { devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL); diff --git a/include/linux/device.h b/include/linux/device.h index 36d1a1607712f5a6b0668ac02a6cf6b2d0651a2d..1e9aded9a0869e8f140b508a64df1f8141c9e8c7 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1083,9 +1083,35 @@ int device_for_each_child_reverse_from(struct device *parent, 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, - const char *name); -struct device *device_find_any_child(struct device *parent); +/** + * device_find_child_by_name - device iterator for locating a child device. + * @parent: parent struct device + * @name: name of the child device + * + * This is similar to the device_find_child() function above, but it + * returns a reference to a device that has the name @name. + * + * NOTE: you will need to drop the reference with put_device() after use. + */ +static inline struct device *device_find_child_by_name(struct device *parent, + const char *name) +{ + return device_find_child(parent, name, device_match_name); +} + +/** + * device_find_any_child - device iterator for locating a child device, if any. + * @parent: parent struct device + * + * This is similar to the device_find_child() function above, but it + * returns a reference to a child device, if any. + * + * NOTE: you will need to drop the reference with put_device() after use. + */ +static inline struct device *device_find_any_child(struct device *parent) +{ + return device_find_child(parent, NULL, device_match_any); +} int device_rename(struct device *dev, const char *new_name); int device_move(struct device *dev, struct device *new_parent,