From patchwork Sat Aug 24 09:07:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13776390 Received: from pv50p00im-ztdg10021801.me.com (pv50p00im-ztdg10021801.me.com [17.58.6.56]) (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 9A24DA5F for ; Sat, 24 Aug 2024 09:08:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724490502; cv=none; b=g9IRgEa4cs62pjoFwXTZSGsXts9m7yyWOM5kfd0d2p9fBww3XC64lDb17pvtOjWYQCGnSPUsRS3aavyaYk57ZDOYbdNDx9PwhRA97tBlXeWg9xkHoqDdh9fzS0Tt8Fs8sYKxOlqkhYcPYeJmfMXQd558aaWHCyRfoR3NjsRPWUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724490502; c=relaxed/simple; bh=elvKHqhjjIwUWn9YVnt+Gk7VtKMJ0R61OwSPYTTdhv4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GnFdHnzgWPDdFpGHK9DqXiDoIE9fBDvoyHcnnMnB6ejLZl7rqS4qrS6rM4tjkpGm2eFO/t39uLmdDVyOdL9SsAaD/30SGE1B6m+Vn62fpzy8x/dA5kDwh2OujGtcZoGLUVHSz75o/k6hhIXs6Ppb1GceYKdEs3a0F46l8iuuiis= 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=vmSi6ZCk; arc=none smtp.client-ip=17.58.6.56 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="vmSi6ZCk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1724490501; bh=dn8YXMiFaJOgyParJ8bF5Tx5o3Vd6MYrq5djv4110II=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=vmSi6ZCk6p3vGXjXtLYBz2EX1xxO8oUhSZo+TpTYXmCG208m67QFMUDmw3jQA65Hx KOo8dqm41XB02CVutYxI+A8b4mAoRH3vk8DurLLRwrS4ctbRSuaV/doUs6Dqr97G20 5Y+D4upbdUj7lzSDlgNNF3n/9NhWZ2c3uSmUpKN1ILscSsXRkpNmAM2khPdUjCIsda iY3HJhGm6Q6jwHU5Yu/C79i8Nm74IoN21hBpwJM0tHU+3G+1x0pcxJGYsKrLMehuse taV3N3uV1e11hJUjWHMsiHVJv8ViQHxEdIbf3XX3XObtiKBKj4nB2b/7MeZJ3cP2Gx xGSxc7otJonnw== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021801.me.com (Postfix) with ESMTPSA id A194C20102CE; Sat, 24 Aug 2024 09:08:14 +0000 (UTC) From: Zijun Hu Date: Sat, 24 Aug 2024 17:07:43 +0800 Subject: [PATCH v3 1/3] driver core: Make parameter check consistent for API cluster device_(for_each|find)_child() Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240824-const_dfc_prepare-v3-1-32127ea32bba@quicinc.com> References: <20240824-const_dfc_prepare-v3-0-32127ea32bba@quicinc.com> In-Reply-To: <20240824-const_dfc_prepare-v3-0-32127ea32bba@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, netdev@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-GUID: 8hSc9YrUZT0VX9KHJ1CCDRRyjKU4c3tX X-Proofpoint-ORIG-GUID: 8hSc9YrUZT0VX9KHJ1CCDRRyjKU4c3tX 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-24_08,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2408240053 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) which covers both existing checks 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 4bc8b88d697e..c066b581ce34 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3993,7 +3993,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); @@ -4023,7 +4023,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); @@ -4057,7 +4057,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 Sat Aug 24 09:07:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13776391 Received: from pv50p00im-ztdg10021801.me.com (pv50p00im-ztdg10021801.me.com [17.58.6.56]) (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 9E97915382C for ; Sat, 24 Aug 2024 09:08:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724490509; cv=none; b=dPaRaj9Dp1ZzmSwQeGDHbEWsYWOveM5xCUdOLuqMa97qREB3Yhl7pPtKnMClOcscUtO/YMWfBmbDYToj/vkap2eBwJ2J/2p0yvXARGhceM+JRSLR6+qqjz4gdTVBJKhpnY6IszNCRSiIVa/T9bRR+Tb/q6oEpMsYClFTTm6sCk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724490509; c=relaxed/simple; bh=JMVYOcTBf3S+dGruEFca6wb6SUUjWP2EiW1R1R7knF4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cpRhBjwOO/sicvU1JyUO6AEXyUu1ou+53gyleIx0J4PTOb7DHvQrrFfvJMX2ymX+mDqgaNj1vd6kQlTVAjzdVn7UFSxywn9sbItXiTswIHMjHpA3fOK07AHPc1ZBijbAkSWue6gm76vDSJUX3J7/i4KduBlpYBqLTaI9UNxxAi0= 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=zGHq7pkv; arc=none smtp.client-ip=17.58.6.56 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="zGHq7pkv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1724490508; bh=TeTj/Z0lsNk9CHqVVxxeD5P3v0Apo80wz9kpmgkD4A8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=zGHq7pkvUR4mY/OLDzjTU4q742JStfW4I104YmJhQokZZHfEB4pB2b06dJY1Y6u63 laY0690RkqzlDLnpiSoP4tzO6VgJDsWWja6ctxTrubtsvpWS2yYjGNwhdQ+FZF17Di muOkK9UcE2BejQA3UQ6dTxWKXuA0q8WJhC4q/57OnDoFGD+DjqENWvafSPg64HX6U5 h/li3Rk8Hrc0GZOV4lRJmhMsza/QL1VPiouRJDDUoNzVaopKpl16VYxxZfZhlzAKbb KV4CXXTimsJk+aiywJPe1b2fz5PAH+IQJueflHyQrhR1zomh9BOFbNNRX+QH/vXQlU OpiX2UepMKnDw== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021801.me.com (Postfix) with ESMTPSA id B297A2010335; Sat, 24 Aug 2024 09:08:21 +0000 (UTC) From: Zijun Hu Date: Sat, 24 Aug 2024 17:07:44 +0800 Subject: [PATCH v3 2/3] cxl/region: Find free cxl decoder by device_for_each_child() Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240824-const_dfc_prepare-v3-2-32127ea32bba@quicinc.com> References: <20240824-const_dfc_prepare-v3-0-32127ea32bba@quicinc.com> In-Reply-To: <20240824-const_dfc_prepare-v3-0-32127ea32bba@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, netdev@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-GUID: Jvzz9BJiTKOrXbETv76nzUoWpoGSiTW2 X-Proofpoint-ORIG-GUID: Jvzz9BJiTKOrXbETv76nzUoWpoGSiTW2 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-24_08,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2408240053 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, solved by using device_for_each_child() to implement relevant finding free cxl decoder function. Suggested-by: Ira Weiny Signed-off-by: Zijun Hu --- drivers/cxl/core/region.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 21ad5f242875..c2068e90bf2f 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -794,10 +794,15 @@ static size_t show_targetN(struct cxl_region *cxlr, char *buf, int pos) return rc; } +struct cxld_match_data { + int id; + struct device *target_device; +}; + static int match_free_decoder(struct device *dev, void *data) { + struct cxld_match_data *match_data = data; struct cxl_decoder *cxld; - int *id = data; if (!is_switch_decoder(dev)) return 0; @@ -805,17 +810,31 @@ static int match_free_decoder(struct device *dev, void *data) cxld = to_cxl_decoder(dev); /* enforce ordered allocation */ - if (cxld->id != *id) + if (cxld->id != match_data->id) return 0; - if (!cxld->region) + if (!cxld->region) { + match_data->target_device = get_device(dev); return 1; + } - (*id)++; + match_data->id++; return 0; } +/* NOTE: need to drop the reference with put_device() after use. */ +static struct device *find_free_decoder(struct device *parent) +{ + struct cxld_match_data match_data = { + .id = 0, + .target_device = NULL, + }; + + device_for_each_child(parent, &match_data, match_free_decoder); + return match_data.target_device; +} + static int match_auto_decoder(struct device *dev, void *data) { struct cxl_region_params *p = data; @@ -840,7 +859,6 @@ cxl_region_find_decoder(struct cxl_port *port, struct cxl_region *cxlr) { struct device *dev; - int id = 0; if (port == cxled_to_port(cxled)) return &cxled->cxld; @@ -849,7 +867,7 @@ 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 = find_free_decoder(&port->dev); if (!dev) return NULL; /* From patchwork Sat Aug 24 09:07:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13776392 Received: from pv50p00im-ztdg10021801.me.com (pv50p00im-ztdg10021801.me.com [17.58.6.56]) (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 C4C6E155A34 for ; Sat, 24 Aug 2024 09:08:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724490517; cv=none; b=cOV5smTlVIUwF1Ea20v4k85Ui9LdZt9XpHsWjsxyQw8FghI1ME74wEkY8rpsKNBGuleuPha4BL7gZnG0w0u+QH4SsHFWZSMgikBfDz0cc18yrJXMoAi0gkuIi1e07dcKvM8IgYSBFDjjyTBR7upF7QfOKfxXv4Z0N33Isz6YPd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724490517; c=relaxed/simple; bh=6N7PqK9xBFI6iYPFqZ/0q8L0Dbt2mFTNu//UuPHTsR0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HEskrUlhEHSXVoT5c+8LiVtkJlRTMM5OI0CPUz3ofA602OuJ4OkyZkwaQGVzs/chLk5dnsn5dSmXLWuW6mZXzPuSgAVufPWEQ2LKTU8v5pFu+wJ4IaLB2iI8se7ABXX7pIWjjxg8BAmkBU5JqBSZLZspxWHNnwvUken9z76lyZ4= 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=AUaQ7HoJ; arc=none smtp.client-ip=17.58.6.56 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="AUaQ7HoJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1724490515; bh=3ltOxJ7yzq2fygEXUJTTlGgiDR87fnykZ2qH+ljFSB8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=AUaQ7HoJzdlsPS2x/9JZmg7KYdTDwfM2gYrICytEtesPk6ykj6HCgUsTFitc4mPhV fCajqTSLbR/yUnbW7mwFm8sdS1UiI40v/PT1Qh13dtHdA+NZf/VBxUjmvfXWZN31YT tQ42o5a6HZmUEr0GqBbAyKZO4cN3HHNk2dVw4yUef9zRxNHlPaWtSEAAUoK6i9ptx4 8yiGJr4jLvPZaDCZUIPO9oh0dh6zmTaopIVWFmU0OgC+2GmncpLluEfry/zvEBscVF 2giCaXz5mPQQxOrOOpGU9H9erIc512+OEsPVJ0Zevu5L4HSX+aCJf71Gayvc167SxB JhmsjyqKJxJww== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021801.me.com (Postfix) with ESMTPSA id A7D1720102FF; Sat, 24 Aug 2024 09:08:28 +0000 (UTC) From: Zijun Hu Date: Sat, 24 Aug 2024 17:07:45 +0800 Subject: [PATCH v3 3/3] net: qcom/emac: Prevent device_find_child() from modifying caller's match data Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240824-const_dfc_prepare-v3-3-32127ea32bba@quicinc.com> References: <20240824-const_dfc_prepare-v3-0-32127ea32bba@quicinc.com> In-Reply-To: <20240824-const_dfc_prepare-v3-0-32127ea32bba@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, netdev@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-GUID: V18wEW-gUmWrD26jVLEKnIiwehUGNeQt X-Proofpoint-ORIG-GUID: V18wEW-gUmWrD26jVLEKnIiwehUGNeQt 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-24_08,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2408240053 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 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, solved by using device_for_each_child() to implement relevant functions. Signed-off-by: Zijun Hu --- drivers/net/ethernet/qualcomm/emac/emac-sgmii.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c b/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c index e4bc18009d08..29392c63d115 100644 --- a/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c +++ b/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c @@ -293,6 +293,11 @@ static struct sgmii_ops qdf2400_ops = { }; #endif +struct emac_match_data { + struct sgmii_ops **sgmii_ops; + struct device *target_device; +}; + static int emac_sgmii_acpi_match(struct device *dev, void *data) { #ifdef CONFIG_ACPI @@ -303,7 +308,7 @@ static int emac_sgmii_acpi_match(struct device *dev, void *data) {} }; const struct acpi_device_id *id = acpi_match_device(match_table, dev); - struct sgmii_ops **ops = data; + struct emac_match_data *match_data = data; if (id) { acpi_handle handle = ACPI_HANDLE(dev); @@ -324,10 +329,12 @@ static int emac_sgmii_acpi_match(struct device *dev, void *data) switch (hrv) { case 1: - *ops = &qdf2432_ops; + *match_data->sgmii_ops = &qdf2432_ops; + match_data->target_device = get_device(dev); return 1; case 2: - *ops = &qdf2400_ops; + *match_data->sgmii_ops = &qdf2400_ops; + match_data->target_device = get_device(dev); return 1; } } @@ -356,10 +363,15 @@ int emac_sgmii_config(struct platform_device *pdev, struct emac_adapter *adpt) int ret; if (has_acpi_companion(&pdev->dev)) { + struct emac_match_data match_data = { + .sgmii_ops = &phy->sgmii_ops, + .target_device = NULL, + }; struct device *dev; - dev = device_find_child(&pdev->dev, &phy->sgmii_ops, - emac_sgmii_acpi_match); + device_for_each_child(&pdev->dev, &match_data, emac_sgmii_acpi_match); + /* Need to put_device(@dev) after use */ + dev = match_data.target_device; if (!dev) { dev_warn(&pdev->dev, "cannot find internal phy node\n");