From patchwork Tue Dec 24 13:37:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13920120 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 CA03F1D79A6 for ; Tue, 24 Dec 2024 13:38:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047491; cv=none; b=H7wWSw+J3cmQG1ifHGBgLFoFkYwWU8F49Vpg079ASstm8pzfUL5Vy+2vbD3PArFUNZooTQD4+JyQgv2Zy9YwO7fH0KeBfrMwCpXIrDr/8yhkgSmR/Ve16o4iKW6I3NcitS1R9738rzWUDLqs0VdZ+DwCKzAoNs+X/Xq6q0/i2n4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047491; c=relaxed/simple; bh=8mn6t+QHjDaf7J6kc9SMk308hna52jlveGFlyTvTj3U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gXSU08HRC9OpKBnVp8gn9Cv4A+/nb/4LBVHV2tHA1pC2S/5EFfrKiNOVU1p3F5pOcAOYNtgIDwTmmFV3+iqqKg2nkukhc2n/VdZkd9GheNsnzLNrtaUqml8CZy8cdFU5yAO1aJtGa5LCUD5ApkRVTH7/FB/h/KsT9t5WZR8TvBY= 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=B/Z/8utH; arc=none smtp.client-ip=17.58.6.47 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="B/Z/8utH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1735047489; bh=P8XwY4in8iMuG1/djQ6xOUQq3gJGLhNX0HGYx/Z+xcU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=B/Z/8utHrGZwwEic+ee9MMqCX12ODCZB6bTRKJ+pAKE0x2mdScRc20ZeJ/g01JZyj IT25QKU7Rdko2Eq+jPgjhThPjIoYdoZvY2Xa9/WuTSTFFx7YiyWqiwoMkU1MgFvdfp LCBl593HsLv61n7Y/5cY7O1xVG4Yj8LZsxNaEJmfr9Apkn0gwDwRP6oVHGA+GLHum9 gXYBzBd2r4MBwCS2mXLFMEKPRoPxKGPPKgA6+zaE3jhCnZSa05kTeM1onfDJzaIxao rmgqp5FR66Z4vkW0NVnUZ0JyWuLwVqfQqool4c/sY1/svURoSE8nOZvtSMqFjg2dvC pms6nuo7cltOg== Received: from [192.168.1.25] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id 4D5348E041E; Tue, 24 Dec 2024 13:38:00 +0000 (UTC) From: Zijun Hu Date: Tue, 24 Dec 2024 21:37:20 +0800 Subject: [PATCH v5 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: <20241224-class_fix-v5-1-9eaaf7abe843@quicinc.com> References: <20241224-class_fix-v5-0-9eaaf7abe843@quicinc.com> In-Reply-To: <20241224-class_fix-v5-0-9eaaf7abe843@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 , Jonathan Cameron X-Mailer: b4 0.14.2 X-Proofpoint-GUID: IzoVIQ--U7gM-T2Mb4w_I5gy9epyeW2P X-Proofpoint-ORIG-GUID: IzoVIQ--U7gM-T2Mb4w_I5gy9epyeW2P 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-24_05,2024-12-24_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412240118 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 Tue Dec 24 13:37:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13920121 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 6956D1C1F0F for ; Tue, 24 Dec 2024 13:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047500; cv=none; b=eBJ0KEWvey7gywAeUbVALHMVl7tP9Dr+6/3OZ03R2+jiCyPbneTgBJGKo0+F54TX+oUbdHeMFOZRAn6H8n6LW5nhTk09bUhzjaVx5YfdNsTWRKu4aSMLXIEEczDPGM9RROCnI3GMqC1N0d+KRGbR1SyGtbXq0icC5lP+05ilvak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047500; c=relaxed/simple; bh=zMjsz7jAuZ/kQmW7w3lfAwa1gsUcolqTbT99cffmGys=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pHGoPW+TQvSD7K/282EQ9cGoxnq0kyf5iIOQHXjhQlyP9FPePmzoPp6Qp+RtmDHbj4inQGGFWjvtpNwZAvvK4V2TsurOsuouL5yqt9259A3/cO01KWF2xCu6LC46/TxwUyq3WaCctPdApi4chevDTYpxESm6KPxVl9fik/vE+ss= 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=DTkI+qi7; arc=none smtp.client-ip=17.58.6.47 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="DTkI+qi7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1735047499; bh=kn+rsGruQx2pm0qQwtoirYg6DzCwThWomNn9G8Daxpo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=DTkI+qi7m2SjRclnlZnr7hKk4vcWZea5PVDWLSEuupRbO27Qy89815Spjsp+z6rWT Ss/KchKoJI9c7/BHIRXQc1e+UbrhSYC1534oyTBTDVGNPhiB6EC2nRS8uA38jJCIAu lZxYjybPgnIuG97mau33SDm9ObDWcLJBbsmir16dHaXE0FT/CC1Kj+WHrnHp9qId2O OYmrtcrLasZdFrcBWC4tbRODa/bEiGJhjmp2mpGVjeU3z/LFO9RpF/sVNO0ph7OAdA 9UgfumRWwXEHgJY2A9a+P39ZOvG5YrcPAO+P3ZawUF/sWyjj2eaOey+nRXM4YQgFnb +7LU0XcY5Kxxw== Received: from [192.168.1.25] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id 240558E04AD; Tue, 24 Dec 2024 13:38:09 +0000 (UTC) From: Zijun Hu Date: Tue, 24 Dec 2024 21:37:21 +0800 Subject: [PATCH v5 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: <20241224-class_fix-v5-2-9eaaf7abe843@quicinc.com> References: <20241224-class_fix-v5-0-9eaaf7abe843@quicinc.com> In-Reply-To: <20241224-class_fix-v5-0-9eaaf7abe843@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 , =?utf-8?q?M?= =?utf-8?q?ichal_Koutn=C3=BD?= , stable@vger.kernel.org X-Mailer: b4 0.14.2 X-Proofpoint-GUID: nSnhKvYpzhjTcrD7NiJ5ZdG4NMq4wFeM X-Proofpoint-ORIG-GUID: nSnhKvYpzhjTcrD7NiJ5ZdG4NMq4wFeM 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-24_05,2024-12-24_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412240118 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 e68c725cf8d975f53703ecf6e6c50594076204c8..fb9858efdfe9443704cb9a239def0e08addf2518 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 Tue Dec 24 13:37:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13920122 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 5C0A91DAC89 for ; Tue, 24 Dec 2024 13:38:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047510; cv=none; b=sQJx541zHdah2z/KZHOvHzrc3rSB3D6UQ8OghvL72Ji/S4nOwHti/jGDEKbs9um4BPBS6Z8+x21HljBL267wQ8pKyyHIS7xbCVDvf+nLDUjApPo4AlcCLmLVHtu7iTmmKFA0zU5naRlmyrjGpCZvCQemM7XSK0QCR4dZ26TwHAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047510; c=relaxed/simple; bh=G49zBKYjNI4Lr2O92y6LMZppduNJ4fYsvssXA+rD8DU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cxVwQD2ScrwqgytGJVTiSvKxuQwIe+4XK+YBayWAo9vfD1owiD9c9kwEtPLT5UhEJEmJA/qrlR8oB+kzi5KoD0QTNbuOfF1yzRVOaKQ9jN59zOkj+pwxd0vdPLYHj++p66+kBA3UUzpXhzGGXnWuYE/POv+D56n2ddjK8WJIVAY= 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=kGv9gI/z; arc=none smtp.client-ip=17.58.6.47 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="kGv9gI/z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1735047508; bh=cOPHgek+7txVXNgAZKPNrM641zXSkIkTh3Riom+d1rc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=kGv9gI/zocbRw/35SsPmt/h9nCbU+JL+fuSrL9h39uE8GY7XbE3S4sYHu5RZffn1A 1krsfGcWgy9THUVyFz0vlY/u2LQgc4v3x4Vc0jIIi06rnFRV8wwcIk/otlWx6VxSwF o9z4IXX8mbtsHEbswXC/wFZbyPH5NAmywkfP6VLgKoCS5YR/RE3yQLTPxTu7GRohJc okmhmxZYgb1O1jGT01zhfMDJgNFhnwTlFwpK94YvA2Ov4pG6u06Mtzwy5rFZAHLfRp He8fTQiDfwI8i/Q3pY1lQxnJcl3K7FNoEUydIIkcQnL6JO5CSxdeHBFANlw3L3qf3j m+O/tKjAyX9tA== Received: from [192.168.1.25] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id CFD8D8E0537; Tue, 24 Dec 2024 13:38:19 +0000 (UTC) From: Zijun Hu Date: Tue, 24 Dec 2024 21:37:22 +0800 Subject: [PATCH v5 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: <20241224-class_fix-v5-3-9eaaf7abe843@quicinc.com> References: <20241224-class_fix-v5-0-9eaaf7abe843@quicinc.com> In-Reply-To: <20241224-class_fix-v5-0-9eaaf7abe843@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 , Fan Ni , Jonathan Cameron X-Mailer: b4 0.14.2 X-Proofpoint-GUID: UAyJ86HnSM2NvFEe9fRubnMoiClTUazR X-Proofpoint-ORIG-GUID: UAyJ86HnSM2NvFEe9fRubnMoiClTUazR 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-24_05,2024-12-24_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412240118 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 8bdbc9e657e832a063542391426f570ccb5c18b9..69bb6bf4bd12395226ee3c99e2f63d15c7e342a5 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 Tue Dec 24 13:37:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13920123 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 7CDDB1C4A24 for ; Tue, 24 Dec 2024 13:38:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047519; cv=none; b=qg+dpTuuWj3v7XF/HcybmhbzMOv8QnK9nzxChwcIXMPzhfuXn8FfyCgn47lDbrRW7uKCXE18tpYAZrkKJv6T1wvnoFTl5f2nSMcLrjko6tB/fE7Wp6xuYIKk84DAXWaUd9hW0FwEgYWCEYtixqkMcDoPjGCX50ut4Q8RTnl2cow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047519; c=relaxed/simple; bh=r1myTHTt6RqQBq+qIcrBHUm5l/c3S1IeRV2Ch3Esx2E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Kt6OpI0hlEdGtqXBWudrEOCWXtX9iFN0oOEPU0ZHWsLedsle33uJ084EJRRdXWXaQgZJCopujAqG70Hyrld1Yhk3q7vgj68HkeWfDY7YJUDTsSAiA1zg/c1uxuXXxyo5jsNeMuxM4hlsimJJyJRxhRQzP3ceIsLDCOhYCYoB8oc= 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=CaFTa2Wl; arc=none smtp.client-ip=17.58.6.47 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="CaFTa2Wl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1735047517; bh=bpdPHGVvsNjPbtVeiARlh6UhJFtwCfTalqRar5MzOl4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=CaFTa2Wlbw9lV6LEwAi2rskMcM+IoWn9FIs1+ZFJerRaIk7HWLfQRgBUlOe3Tx/F+ ANu0OfSPhYumY3zEHI1yGNvC+QprK57LVxLDxLBzvMERPUGVzUCuBJaFIWTVPHYAcF bWTEKleMoMvywMZKGTjaF2mhwwQjXPc1B+L8AGPmisSm1thPj5LlwJUNryysW14y2M vW3Wp11vCCRbL6GFBILPVyUvyb4ybLNqkt26XzYPifqieAzkt2IaxVWphzJe7cSdk2 bKUM9j5n8eWbHNQ8EDXVcjB+Asa0jcHaROBXr9NSQsYyCnrFAwdQxnkRd0SxMWzuWh qtB6wtx3xlhPg== Received: from [192.168.1.25] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id B5CC58E0085; Tue, 24 Dec 2024 13:38:28 +0000 (UTC) From: Zijun Hu Date: Tue, 24 Dec 2024 21:37:23 +0800 Subject: [PATCH v5 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: <20241224-class_fix-v5-4-9eaaf7abe843@quicinc.com> References: <20241224-class_fix-v5-0-9eaaf7abe843@quicinc.com> In-Reply-To: <20241224-class_fix-v5-0-9eaaf7abe843@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 , Fan Ni , Jonathan Cameron X-Mailer: b4 0.14.2 X-Proofpoint-GUID: 1l8w1MO6zxw4B9ZtsAu3MdKxjmZ8fBGg X-Proofpoint-ORIG-GUID: 1l8w1MO6zxw4B9ZtsAu3MdKxjmZ8fBGg 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-24_05,2024-12-24_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412240118 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 Tue Dec 24 13:37:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13920124 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 5C6751C5F2D for ; Tue, 24 Dec 2024 13:38:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047527; cv=none; b=fxTSPZPOow+4Kcnba7hpgDRM5okRLYHp3tSLywOzfa1VcjLEBUi9ykb4KUUdiJoRiSOTBdXt/oOTNiDm7taaBHMuumap8WLmgoO1dqNdFI0M4YD7x+6O4X+p3vkiJTuJymt6JpQjyIc8RMhRcZeP8YfjKuk9IfaL4lSG8PkIyg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047527; c=relaxed/simple; bh=9Y0rzZnBTx0M5MQSIP1RwELLmzfYczu0ijWLu1jrY5g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=esMiOn3P12QzyUsP4GwBoIAZ3isR+IiX1JAKTT6xgkGW98tgBgms6wbe3HJzjoQR/rhZYScreKpy0S2PFDP6GFl5dsCvlx2e39HiyFNF+od5q6mzAIFd3eAiBa3rH9ZbO8SvUv+K/DnKxwq4c6cCfR3oQlSHCnPh75ITeAvc1V4= 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=05j2rkJi; arc=none smtp.client-ip=17.58.6.47 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="05j2rkJi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1735047526; bh=VKx9/BEbeYqmaBNZCu91NOLWQRLnn6ACylShMKN74W8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=05j2rkJiZmrEtB/hjXW6uQ68Gx95yipkAoAmir2FtrippHpd8MzntYVoZKuyb3r3d QRZRie695fTkFWJitaNv3J/KkHmMb4BlmBe6qHRa0Ta02uxJgP+9i//kYAHLMU43Du AqZ2eOYNkXDMBljB09UQRP5ptVbTW3puNyVv1PEJEziY8ZBB50L1gB9/H2lmYJWXug CjG0IPmQVOrqWe0QF/GLk9y58MHU9nLvtsxewtpEsaiUwSgzXmOSPSSxNsZR20575S 9ZN7+0ztpSCAPxdBNPwi2YDJ0lN5t6e3//SjrHS2+nnOoVg9/srMve+UkHGpxTFG2H zVN7fk1zV5BVQ== Received: from [192.168.1.25] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id F284B8E04BB; Tue, 24 Dec 2024 13:38:37 +0000 (UTC) From: Zijun Hu Date: Tue, 24 Dec 2024 21:37:24 +0800 Subject: [PATCH v5 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: <20241224-class_fix-v5-5-9eaaf7abe843@quicinc.com> References: <20241224-class_fix-v5-0-9eaaf7abe843@quicinc.com> In-Reply-To: <20241224-class_fix-v5-0-9eaaf7abe843@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: l6LvHSUmMmOtqtG7zqS75V_bnCNiilQC X-Proofpoint-ORIG-GUID: l6LvHSUmMmOtqtG7zqS75V_bnCNiilQC 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-24_05,2024-12-24_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=882 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412240118 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 Reviewed-by: Jonathan Cameron --- 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..34fb13f914b3db47e6a047fdabf3c9b18ecc08cc 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 Tue Dec 24 13:37:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13920125 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 0E06D1D79B3 for ; Tue, 24 Dec 2024 13:38:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047537; cv=none; b=l/2tGJjp2n+VBVLpaK1LqHSD+4T4d3+VomfcuXpqjHInjE4xgcd+wMX2/DgJb0dN7z6kaaMYeGxJcBsBVQKoka3GDx8gr2D8RxAPI9U8yaM/ipgx8fHtBWH1DtiR0eMvKjNDfSSa/pv9jQWI4m/CpbZhBikfPmaRXLdi4zOtARY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047537; c=relaxed/simple; bh=DwQV+1u1k+MMC8p20XB/ThrvufR22TR7sB4o/3ThFnI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B62CcXtFJR3qUf0xfReY1rsUL1LFALtQW7SPdvltcWxOqkHIc8Ker9vyEfj3zdZxe1xLsffDdr04+65ez1P6pG2KUzBSzn9fy/UQtcPZf8MPTWdiCtR0Hcr87X+p+kBz1M4em6xYa9ispwdyCZ+yDIsgnXM0S+X0zw/V24B1hqQ= 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=nA0ar0qM; arc=none smtp.client-ip=17.58.6.47 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="nA0ar0qM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1735047535; bh=hSVqi/9cLAHS96j0Wuyjns8MrivpzIzzYpGb9TI00yE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=nA0ar0qMaea+PxSEdQtrbGs+Oesa1V7ezXqbPh5HOOP75Cdsf47p4yyuNDwETzMAy /KydHHoBaBGS4vUoRR1gWNAZH1m4mxju37l5gbIKxwpWiCiuu3pnH1w03IGDvTb2fm WCVAEVa39w7qO+pCNrnIR6ZauuQh8MCShInHHRyyOP7eiI4wrnGUE9Ac5UU+z5v3SA 0i9MY6xw1oszd73g4l7sBEHepP6ctxplGZGZ4Btrzw9djhPW16XBc5fXLlSp9+Tmyn Ar4sarybM2Nie2ViqPm568V/U38om4ji2ZklEWxUio9dXy8s2aAvRkjicls91Tphv1 h1rnMfywP9poA== Received: from [192.168.1.25] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id E8B868E0537; Tue, 24 Dec 2024 13:38:46 +0000 (UTC) From: Zijun Hu Date: Tue, 24 Dec 2024 21:37:25 +0800 Subject: [PATCH v5 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: <20241224-class_fix-v5-6-9eaaf7abe843@quicinc.com> References: <20241224-class_fix-v5-0-9eaaf7abe843@quicinc.com> In-Reply-To: <20241224-class_fix-v5-0-9eaaf7abe843@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 , Jonathan Cameron X-Mailer: b4 0.14.2 X-Proofpoint-GUID: eay42OfFhrevYmP5HBdveklan6yB_5Cd X-Proofpoint-ORIG-GUID: eay42OfFhrevYmP5HBdveklan6yB_5Cd 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-24_05,2024-12-24_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=965 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412240118 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 34fb13f914b3db47e6a047fdabf3c9b18ecc08cc..7be9c732bec1b060a477b362f555c3e87c8c7b91 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 Tue Dec 24 13:37:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13920133 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 B88361DDC19 for ; Tue, 24 Dec 2024 13:39:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047547; cv=none; b=eZhYWUcuMgndUPrImtclaVmptS8a4fgOL6bohmmEy3j1pAM1aYUafLmqyQEVYZTltVpf6sKfBxsZpqznkfqOwB6S9ENBAi7NWhyWQDregkrSxhfg6ggDx3cHx53PnScnMAvs7O/9Zm0TukFPWSBBzqY1gPIg/neFBBQzbqvie7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047547; c=relaxed/simple; bh=uLh0iwbx+bHSkqf31NJfzOKrZYjwuqeeVtQOgp32dKo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A0m2OvqhLENOjinBTWVL9p1LteKoLNtVfXjIb2AGXCraoLHN86S73r66FphJPcQPRtaPTcWffr98sa3FXQNVbpROVBqDgq/VuKqVzGd6GG+kJxtbfxrQ0GTBWrnLfz6IYhXXOWhyhx0XH75cjoY/HFRzY5aMXg/6z9wKhquQ5vE= 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=Z6v0JnKO; arc=none smtp.client-ip=17.58.6.47 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="Z6v0JnKO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1735047544; bh=D+LGXKD45T7pkrXMj16PMStlutJQBRuIDizc9g023YQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=Z6v0JnKOJPzs8uAdxAoebSjVa0ymHtdhHpCYShcwKK2mlbEhp2bCKUpdlfQuxAOJn HFo8HNEl+1Xtw90wsRZmtzIDntvQPdTH6s1QfggjO0QDLF/XObzeGDjhcHQ4wfoQNc mlhDPvKZMC9CTx/zulZpfrfOmqDlkTWoOwnx8eHci8KarxwEBnHl36MJZN6Hy50nOG hsxmh02N0Mn/JXVvMnXezs13x6LWxo+iIYwenkC+vgVAcIdeycpO1ClT+rWCZfCHTz gAU6CMiduS0ZmV+5P1X3IyYokvHAmd+kc712cWjBgMBjQsER2dv6iObd1EAUZJKEN6 zss7WfGiKYflA== Received: from [192.168.1.25] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id 66EA18E045E; Tue, 24 Dec 2024 13:38:55 +0000 (UTC) From: Zijun Hu Date: Tue, 24 Dec 2024 21:37:26 +0800 Subject: [PATCH v5 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: <20241224-class_fix-v5-7-9eaaf7abe843@quicinc.com> References: <20241224-class_fix-v5-0-9eaaf7abe843@quicinc.com> In-Reply-To: <20241224-class_fix-v5-0-9eaaf7abe843@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 , Jonathan Cameron X-Mailer: b4 0.14.2 X-Proofpoint-GUID: sTsJRH0_rcCc7wD6Bm61cjc2n_t0Z2UA X-Proofpoint-ORIG-GUID: sTsJRH0_rcCc7wD6Bm61cjc2n_t0Z2UA 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-24_05,2024-12-24_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412240118 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 7be9c732bec1b060a477b362f555c3e87c8c7b91..930e43a970952b20cd1c71856bdef889698f51b4 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 Tue Dec 24 13:37:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13920134 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 E22E61D9665 for ; Tue, 24 Dec 2024 13:39:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047555; cv=none; b=rmF89tgELZYPeLDniKeXaYopkkbJLAbzwQ94r8kncL9NxD5rNj5IyLqoiwyG/pUufUyyPt2hCp9OzRAJDnymPXUI1sM1P5+45JPtTEC6pKQ5DawAIJNuahQ/XAH3ecVBZlWTQeYrWQrpQx8m0ZtVPHbgqim+lb7DgRJyPeRXH8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735047555; c=relaxed/simple; bh=9OlOZtXEbqGDafFrZXxpWZoE10b9+aoTMAN++XcN9U8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TaKLF1KWTekjkqrRt3WjjUaFfiAME+VQw3wMGGelAETdap/VAq84LjeF/UHOZsO3B/od0DYnV/hbYdCKMNR0pRT721ZNujFBpEVhy4frkMpyxc4WtmjhSc5w8VCUSspx9TSzkg/91oZRhDqUCuvu2+j5vnbFKcYbFL4R85JQGGg= 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=kUSViKL0; arc=none smtp.client-ip=17.58.6.47 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="kUSViKL0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1735047553; bh=iiStYWBmczJf5murnV+QgTCZ+TDHGEX9li4ZnS/xVFw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=kUSViKL0Uk7p7VXqqfQCo+0O8GEotMEgnPZnhS4/wmpr2thyvemREuJmp1TEjc9Dy GGublyV8Gq+luHiiuzkxNA9Ttpt6aojWPZaJsIRo6/EvunTHNlU7i681PSrqG7ahwL seJaXKyji9lXsrZiVwycYQ8DPnLLeghTEt9vvHq9yDa++KuyhSoXzEMXCwt2riFj/T wacnjB89J8fDuQylAVErJxpsX7s6ArVQGJnjdewBcWpN8WpedED7MT7b7CuBCRe00p iZ3OqnrGgyDr/e3wg2RXzL9M91XYkyblu4Rx+Z4hOrqzds5SfL02tr4dgjXSpoDcCx BI0P/fZGv0cnA== Received: from [192.168.1.25] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id 33EA48E02DB; Tue, 24 Dec 2024 13:39:04 +0000 (UTC) From: Zijun Hu Date: Tue, 24 Dec 2024 21:37:27 +0800 Subject: [PATCH v5 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: <20241224-class_fix-v5-8-9eaaf7abe843@quicinc.com> References: <20241224-class_fix-v5-0-9eaaf7abe843@quicinc.com> In-Reply-To: <20241224-class_fix-v5-0-9eaaf7abe843@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: 6UkNEWO_zjk_Wu-HE4N4px_kOlmCRv8K X-Proofpoint-ORIG-GUID: 6UkNEWO_zjk_Wu-HE4N4px_kOlmCRv8K 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-24_05,2024-12-24_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412240118 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. Signed-off-by: Zijun Hu Reviewed-by: Jonathan Cameron --- 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 930e43a970952b20cd1c71856bdef889698f51b4..3f37a2aecb1d11561f4edd72e973a1c43368de04 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,