From patchwork Thu Aug 15 14:58:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13764869 Received: from pv50p00im-zteg10011401.me.com (pv50p00im-zteg10011401.me.com [17.58.6.41]) (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 C04BD1A00CF for ; Thu, 15 Aug 2024 14:58:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723733910; cv=none; b=Qpo1gBZFw7J7nrc7qXulcO711oJAMrfBIjFKgPNr6IuchZdkPs4ExG5V3SW3Jdh4eWjlTTfe619nZtwso1Q+8C2/LNpAfc3ae3Sa4vhxvvBklzXI3oGRhdIacqo027R6/F34Og8ANPMy5UklXTCciAx3b2NhmGixSiDGwZxO18M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723733910; c=relaxed/simple; bh=B4x40oAtN3LNjRkWVAGnXINEU93Q9RDP/QrLRF5fUqQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LR2XxsyqhhL4nuB7DVFv80QUUuOmaWfE8yVkTpn1wIAxTKAg6/q13Xw0DUOrJxihldMRGwxYhCiFkEwv9H6/ZID+ShP5IU9iF2O59RIJwiTiSbmNt/OlnNvXj555LoLdGZKzwdrj3lMcAIsH+TNCHpc/YTofNI1ET5bGuJ2Ge+M= 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=UPve46qa; arc=none smtp.client-ip=17.58.6.41 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="UPve46qa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1723733908; bh=ZXU3cWDb11tHaaxZwCe9tTzxZAMgqOg1R8ukq9Z1Q2k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=UPve46qam1EvWqmlAaywRYn/ARiWoMJXHxgopKDxRqMAtdkbGlYZY5non5TdYnIFH olqNtCdlaYaEjeMjX5pfT7i3XMQ5lgIGabllr88HG0WR2G3hY3/B3yOsB2R59CvxtQ njfeFvMtVj1mlhaQyg/991ZDdStSK9Mp1pwy11D93jcAd/jCcXrvk6xNWSSLuFmsK7 vNfp5Cnp5F6ZCMnmB8gXshnRbiU705cTm+3ulRSCIXSdzXQFMvOz80/vZRknNyKon3 tX33iAEHIJi33qnnzHnnFKKCBlyGheKIzA2MgHt3eJg3ui3rEfglDPOeoU0cm8TYmf RkmG9MrmSzMRQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011401.me.com (Postfix) with ESMTPSA id 55895DC00F3; Thu, 15 Aug 2024 14:58:22 +0000 (UTC) From: Zijun Hu Date: Thu, 15 Aug 2024 22:58:02 +0800 Subject: [PATCH v2 1/4] driver core: Make parameter check consistent for API cluster device_(for_each|find)_child() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240815-const_dfc_prepare-v2-1-8316b87b8ff9@quicinc.com> References: <20240815-const_dfc_prepare-v2-0-8316b87b8ff9@quicinc.com> In-Reply-To: <20240815-const_dfc_prepare-v2-0-8316b87b8ff9@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Takashi Sakamoto , Timur Tabi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Zijun Hu , linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, linux1394-devel@lists.sourceforge.net, netdev@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: VrYAmKVDJ4rTV2tMUm6A8awsDrCjVss8 X-Proofpoint-GUID: VrYAmKVDJ4rTV2tMUm6A8awsDrCjVss8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-15_07,2024-08-15_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 mlxscore=0 adultscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2408150109 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu The following API cluster takes the same type parameter list, but do not have consistent parameter check as shown below. device_for_each_child(struct device *parent, ...) // check (!parent->p) device_for_each_child_reverse(struct device *parent, ...) // same as above device_find_child(struct device *parent, ...) // check (!parent) Fixed by using consistent check (!parent || !parent->p) for the cluster. Signed-off-by: Zijun Hu --- drivers/base/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 1688e76cb64b..b1dd8c5590dc 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4004,7 +4004,7 @@ int device_for_each_child(struct device *parent, void *data, struct device *child; int error = 0; - if (!parent->p) + if (!parent || !parent->p) return 0; klist_iter_init(&parent->p->klist_children, &i); @@ -4034,7 +4034,7 @@ int device_for_each_child_reverse(struct device *parent, void *data, struct device *child; int error = 0; - if (!parent->p) + if (!parent || !parent->p) return 0; klist_iter_init(&parent->p->klist_children, &i); @@ -4068,7 +4068,7 @@ struct device *device_find_child(struct device *parent, void *data, struct klist_iter i; struct device *child; - if (!parent) + if (!parent || !parent->p) return NULL; klist_iter_init(&parent->p->klist_children, &i); From patchwork Thu Aug 15 14:58:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13764870 Received: from pv50p00im-zteg10011401.me.com (pv50p00im-zteg10011401.me.com [17.58.6.41]) (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 337031A2C35 for ; Thu, 15 Aug 2024 14:58:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723733917; cv=none; b=mAWVqCccNpgdlvui2HZAWx6nqgX5exUygRaAHLL89JJR/TxxYaF6Ik7SSYguiDbK446ZkHp/IYmtey166mY1VLkbJmSQj15dJ1MdAmYscsFLMUIqxbINak67tLuTCI9wOwFIGRXwvaCrdB6Bx3ozlLnl14Ldu5H7QK3/0XHJm5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723733917; c=relaxed/simple; bh=dT0ukvA+zU4wNtKsB/FiwQeJ/RGEty86CFCosBSgOh4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uIeb2xdivOOPOBrHikDptpaUfZx/mIxjmqNlApLHjG4zJM9H8E9y/t78rc2zkBNMaEIi/w0tqBGb63ntW5wov/GdLwKWMvvRuWX5XqsKvbOmG8hHrgdl7XG9FvcGidlvTcS9rXnw2vpR8TUb+y0dg8DLz4VGG6uMrqeJ0ZLBQ9k= 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=evObj0f9; arc=none smtp.client-ip=17.58.6.41 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="evObj0f9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1723733914; bh=EzEGrFwK5bZRgf2GaqF4F9k0F8niO9ojTfM21NwUx3A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=evObj0f9MvFRfRXcHTO7XpqOQXr3+0aE+miUy05aF/mSoLfQIwh4IXJBEvEyIZbpQ lip8EWDEegSzDcNPGO43gyUZ39v/EAJJtXn0BB4esvXroQ4C/7fgWQ8IbOyaysO3lL WxEN06/iBx3+JWkRj94r6jsS8LRH/wAdy5BDfYxfDYIgNeioFOBLQ1pXMezyFHkgwT r+X/1HQeuSD+53wZLYYj8+czpTRba2W5wxDW01kzZ9FqTr29bFftoP1qt57QXQ3oq6 fj5FuPvrlz2aRh/0xdkJGSxF/A4TPb2WZDs/YMaWP+UUNDab6rfA0NIzSNO5VyRhWT LQPlwLPaMDFUQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011401.me.com (Postfix) with ESMTPSA id DC009DC011F; Thu, 15 Aug 2024 14:58:28 +0000 (UTC) From: Zijun Hu Date: Thu, 15 Aug 2024 22:58:03 +0800 Subject: [PATCH v2 2/4] cxl/region: Prevent device_find_child() from modifying caller's match data Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240815-const_dfc_prepare-v2-2-8316b87b8ff9@quicinc.com> References: <20240815-const_dfc_prepare-v2-0-8316b87b8ff9@quicinc.com> In-Reply-To: <20240815-const_dfc_prepare-v2-0-8316b87b8ff9@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Takashi Sakamoto , Timur Tabi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Zijun Hu , linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, linux1394-devel@lists.sourceforge.net, netdev@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: rj4UkMdIoUGg833V9nlg1BBGYQroUINv X-Proofpoint-GUID: rj4UkMdIoUGg833V9nlg1BBGYQroUINv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-15_07,2024-08-15_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 mlxscore=0 adultscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2408150109 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu To prepare for constifying the following old driver core API: struct device *device_find_child(struct device *dev, void *data, int (*match)(struct device *dev, void *data)); to new: struct device *device_find_child(struct device *dev, const void *data, int (*match)(struct device *dev, const void *data)); The new API does not allow its match function (*match)() to modify caller's match data @*data, but match_free_decoder() as the old API's match function indeed modifies relevant match data, so it is not suitable for the new API any more, fixed by implementing a equivalent cxl_device_find_child() instead of the old API usage. Signed-off-by: Zijun Hu --- drivers/cxl/core/region.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 21ad5f242875..8d8f0637f7ac 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -134,6 +134,39 @@ static const struct attribute_group *get_cxl_region_access1_group(void) return &cxl_region_access1_coordinate_group; } +struct cxl_dfc_data { + int (*match)(struct device *dev, void *data); + void *data; + struct device *target_device; +}; + +static int cxl_dfc_match_modify(struct device *dev, void *data) +{ + struct cxl_dfc_data *dfc_data = data; + int res; + + res = dfc_data->match(dev, dfc_data->data); + if (res && get_device(dev)) { + dfc_data->target_device = dev; + return res; + } + + return 0; +} + +/* + * I have the same function as device_find_child() but allow to modify + * caller's match data @*data. + */ +static struct device *cxl_device_find_child(struct device *parent, void *data, + int (*match)(struct device *dev, void *data)) +{ + struct cxl_dfc_data dfc_data = {match, data, NULL}; + + device_for_each_child(parent, &dfc_data, cxl_dfc_match_modify); + return dfc_data.target_device; +} + static ssize_t uuid_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -849,7 +882,8 @@ cxl_region_find_decoder(struct cxl_port *port, dev = device_find_child(&port->dev, &cxlr->params, match_auto_decoder); else - dev = device_find_child(&port->dev, &id, match_free_decoder); + dev = cxl_device_find_child(&port->dev, &id, + match_free_decoder); if (!dev) return NULL; /* From patchwork Thu Aug 15 14:58:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13764871 Received: from pv50p00im-zteg10011401.me.com (pv50p00im-zteg10011401.me.com [17.58.6.41]) (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 D6BE81AD9F5 for ; Thu, 15 Aug 2024 14:58:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723733923; cv=none; b=iUKCLJNak8GStuo8C6IaHOODlsSJ7Jvie6TYe5i4z+uwtuO801UFjcGFwGk6kQm3Cpdds0VIhJBxf1kWFZn2KEhvwtHRER8ppOGHpZulm3RbvsA83ELyhaYBBEPZ6kwKDi2+2YH0IRlOdNhfaGLkpYz07qvq7tnTku5QgXztoII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723733923; c=relaxed/simple; bh=3c7muOJco0XYRcBkqVaEVu5D1tl8bbCjKSw9/5bLDS8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iCZdebhnb4LEPI8/k2YWWI58KDgOTUK6W+RMx+G5aHMwaH+a5IGGkXSMiSKdUCOO/V2FCmXCEX4P3Z8Bu1VPENFB87WGQEK/GY5Bv6DZYvSdNsiwhcZd8/plkE5UvCl/nQkTqGRBaaEv9068YG3nwWDG/ahTWdZ6x4swfdQY8mc= 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=CwzPlQUF; arc=none smtp.client-ip=17.58.6.41 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="CwzPlQUF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1723733921; bh=s4C9QAW99bVsLoaRILt/9k69aTTHnvsxsmd55qmj+Wo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=CwzPlQUF6889iOqf3/nb3qRTEIYBrWvIdSjLpOOwO5xll9xOaRKhf6rIK5BSe/RWh YSny7OP7EbZOJi+BWKkEDqZcgHjVXU+fUPAHPWgzvecFCX228ArNfCFcamDOMUx9Bq rH69o3g96qVW1Fe5d4asfS6d2yFStVM+52x6+eFBgRgcZ/PqscthsIVYC9tGlUQPU4 vJdKc/WLoZYIoDf0U1A/oRQe8IrZRfRygKwm4vK1G2QGo2XSmnS7iOciOn+axgHKe2 O7dB1Wq8eYAvxnxzu0/mpPptpBXuKUwRnQiLWAUNSnKrhhZc/VHjDFb2TOFAqoFKdd HzRwOoDc0mEDw== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011401.me.com (Postfix) with ESMTPSA id 73427DC0360; Thu, 15 Aug 2024 14:58:35 +0000 (UTC) From: Zijun Hu Date: Thu, 15 Aug 2024 22:58:04 +0800 Subject: [PATCH v2 3/4] firewire: core: Prevent device_find_child() from modifying caller's match data Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240815-const_dfc_prepare-v2-3-8316b87b8ff9@quicinc.com> References: <20240815-const_dfc_prepare-v2-0-8316b87b8ff9@quicinc.com> In-Reply-To: <20240815-const_dfc_prepare-v2-0-8316b87b8ff9@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Takashi Sakamoto , Timur Tabi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Zijun Hu , linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, linux1394-devel@lists.sourceforge.net, netdev@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: KnVKOxQuiErZzQhL2cWqcfypDdhY7jEe X-Proofpoint-GUID: KnVKOxQuiErZzQhL2cWqcfypDdhY7jEe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-15_07,2024-08-15_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 mlxscore=0 adultscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2408150109 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu To prepare for constifying the following old driver core API: struct device *device_find_child(struct device *dev, void *data, int (*match)(struct device *dev, void *data)); to new: struct device *device_find_child(struct device *dev, const void *data, int (*match)(struct device *dev, const void *data)); The new API does not allow its match function (*match)() to modify caller's match data @*data, but lookup_existing_device() as the old API's match function indeed modifies relevant match data, so it is not suitable for the new API any more, fixed by implementing a equivalent fw_device_find_child() instead of the old API usage. Signed-off-by: Zijun Hu --- drivers/firewire/core-device.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index 00e9a13e6c45..7fbccb113d54 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c @@ -33,6 +33,39 @@ #define ROOT_DIR_OFFSET 5 +struct fw_dfc_data { + int (*match)(struct device *dev, void *data); + void *data; + struct device *target_device; +}; + +static int fw_dfc_match_modify(struct device *dev, void *data) +{ + struct fw_dfc_data *dfc_data = data; + int res; + + res = dfc_data->match(dev, dfc_data->data); + if (res && get_device(dev)) { + dfc_data->target_device = dev; + return res; + } + + return 0; +} + +/* + * I have the same function as device_find_child() but allow to modify + * caller's match data @*data. + */ +static struct device *fw_device_find_child(struct device *parent, void *data, + int (*match)(struct device *dev, void *data)) +{ + struct fw_dfc_data dfc_data = {match, data, NULL}; + + device_for_each_child(parent, &dfc_data, fw_dfc_match_modify); + return dfc_data.target_device; +} + void fw_csr_iterator_init(struct fw_csr_iterator *ci, const u32 *p) { ci->p = p + 1; @@ -1087,8 +1120,8 @@ static void fw_device_init(struct work_struct *work) return; } - revived_dev = device_find_child(card->device, - device, lookup_existing_device); + revived_dev = fw_device_find_child(card->device, device, + lookup_existing_device); if (revived_dev) { put_device(revived_dev); fw_device_release(&device->device); From patchwork Thu Aug 15 14:58:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13764872 X-Patchwork-Delegate: kuba@kernel.org Received: from pv50p00im-zteg10011401.me.com (pv50p00im-zteg10011401.me.com [17.58.6.41]) (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 420B01AAE1F for ; Thu, 15 Aug 2024 14:58:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723733929; cv=none; b=QXUiSDSOH0oqHw2I/xvWR7GUE1v6MB3v6bt0KCDhGfUADucAIXq942Dgjhzic2r8E5heJNgAzE+sNjM+hlqOVukGHhJls85gXcKWrTofD5OkF3+ARR62uyj9Z4i1j+w/UrJEDUkfhaeLMEAfBg/ksDmilloo2qapEqX8x2NzCiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723733929; c=relaxed/simple; bh=yvVO0QvdWcYAFtBy/YbNF+E0L38p9jPnzwSQU5oxBHM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aGk1eafA5CTYSPQWTsh8UEvTPY90xj3EaxngGOu/X5Gdp16VD6PYTkfEw0CuJSG5dLSco9XL/d9q8QvcS5HzJYJba7SHy1cq/mDICzaRF60oJzOxLNZXus+U9TGTxj2XejaJZaH2c/Zc4wqcZ8khY2DZIUtJ7LugKitEEvUeISU= 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=VwXDwBnT; arc=none smtp.client-ip=17.58.6.41 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="VwXDwBnT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1723733928; bh=DrUrmHv0UoPw51ZXQ5s6DePgbIVDIOtNvbxuTR6F7Kk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=VwXDwBnTbW96xoubjySmJEqPDGvI8f3A7iHeEpJ/2FBRDmUtV9TNi4nJicQGzTVnR KocOQEQhwFQygBm055WwG/p4902tiE4A3NNl9o74ojJPyB8Sd8Bn8bJPenHZt+aJXp b5WhRVa+45ojn/5kbNde0Ksdr6VA1AKQzramxB0+wkRkmcnhGt2vJNirvxOHjBb1Mv otK/6zQ3u11HcJx3q+ucKYF9vmpJahLGDITiOot9NXDrpJSx5kaYkIUa496/WOX8GZ 0xX3sqO88GEcebmE3RmG4wB+8hITen7IMq5kJWJ565b48IZOT5ddt6gnrAy/qYNKZo U4wx+43bozEDA== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10011401.me.com (Postfix) with ESMTPSA id 049EDDC0341; Thu, 15 Aug 2024 14:58:41 +0000 (UTC) From: Zijun Hu Date: Thu, 15 Aug 2024 22:58:05 +0800 Subject: [PATCH v2 4/4] net: qcom/emac: Prevent device_find_child() from modifying caller's match data Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240815-const_dfc_prepare-v2-4-8316b87b8ff9@quicinc.com> References: <20240815-const_dfc_prepare-v2-0-8316b87b8ff9@quicinc.com> In-Reply-To: <20240815-const_dfc_prepare-v2-0-8316b87b8ff9@quicinc.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Takashi Sakamoto , Timur Tabi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Zijun Hu , linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, linux1394-devel@lists.sourceforge.net, netdev@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: qdBgT0uEoUogARD1oGfQeX0cJKwj_4Uj X-Proofpoint-GUID: qdBgT0uEoUogARD1oGfQeX0cJKwj_4Uj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-15_07,2024-08-15_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 mlxscore=0 adultscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2408150109 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 X-Patchwork-Delegate: kuba@kernel.org From: Zijun Hu To prepare for constifying the following old driver core API: struct device *device_find_child(struct device *dev, void *data, int (*match)(struct device *dev, void *data)); to new: struct device *device_find_child(struct device *dev, const void *data, int (*match)(struct device *dev, const void *data)); The new API does not allow its match function (*match)() to modify caller's match data @*data, but emac_sgmii_acpi_match() as the old API's match function indeed modifies relevant match data, so it is not suitable for the new API any more, fixed by implementing a equivalent emac_device_find_child() instead of the old API usage. Signed-off-by: Zijun Hu --- drivers/net/ethernet/qualcomm/emac/emac-sgmii.c | 36 +++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c b/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c index e4bc18009d08..1c799be77d99 100644 --- a/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c +++ b/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c @@ -47,6 +47,38 @@ #define SERDES_START_WAIT_TIMES 100 +struct emac_dfc_data { + int (*match)(struct device *dev, void *data); + void *data; + struct device *target_device; +}; + +static int emac_dfc_match_modify(struct device *dev, void *data) +{ + struct emac_dfc_data *dfc_data = data; + int res; + + res = dfc_data->match(dev, dfc_data->data); + if (res && get_device(dev)) { + dfc_data->target_device = dev; + return res; + } + + return 0; +} + +/* I have the same function as device_find_child() but allow to modify + * caller's match data @*data. + */ +static struct device *emac_device_find_child(struct device *parent, void *data, + int (*match)(struct device *dev, void *data)) +{ + struct emac_dfc_data dfc_data = {match, data, NULL}; + + device_for_each_child(parent, &dfc_data, emac_dfc_match_modify); + return dfc_data.target_device; +} + int emac_sgmii_init(struct emac_adapter *adpt) { if (!(adpt->phy.sgmii_ops && adpt->phy.sgmii_ops->init)) @@ -358,8 +390,8 @@ int emac_sgmii_config(struct platform_device *pdev, struct emac_adapter *adpt) if (has_acpi_companion(&pdev->dev)) { struct device *dev; - dev = device_find_child(&pdev->dev, &phy->sgmii_ops, - emac_sgmii_acpi_match); + dev = emac_device_find_child(&pdev->dev, &phy->sgmii_ops, + emac_sgmii_acpi_match); if (!dev) { dev_warn(&pdev->dev, "cannot find internal phy node\n");