Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: qcom/emac: Find sgmii_ops by device_for_each_child()

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 implementing the same
finding sgmii_ops function by correcting the function and using it
as parameter of device_for_each_child() instead of device_find_child().

By the way, this commit does not change any existing logic.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Link: https://patch.msgid.link/20241003-qcom_emac_fix-v6-1-0658e3792ca4@quicinc.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Zijun Hu and committed by
Paolo Abeni
138d21b6 f95b4725

+17 -5
+17 -5
drivers/net/ethernet/qualcomm/emac/emac-sgmii.c
··· 293 293 }; 294 294 #endif 295 295 296 + struct emac_match_data { 297 + struct sgmii_ops **sgmii_ops; 298 + struct device *target_device; 299 + }; 300 + 296 301 static int emac_sgmii_acpi_match(struct device *dev, void *data) 297 302 { 298 303 #ifdef CONFIG_ACPI ··· 308 303 {} 309 304 }; 310 305 const struct acpi_device_id *id = acpi_match_device(match_table, dev); 311 - struct sgmii_ops **ops = data; 306 + struct emac_match_data *match_data = data; 312 307 313 308 if (id) { 314 309 acpi_handle handle = ACPI_HANDLE(dev); ··· 329 324 330 325 switch (hrv) { 331 326 case 1: 332 - *ops = &qdf2432_ops; 327 + *match_data->sgmii_ops = &qdf2432_ops; 328 + match_data->target_device = dev; 333 329 return 1; 334 330 case 2: 335 - *ops = &qdf2400_ops; 331 + *match_data->sgmii_ops = &qdf2400_ops; 332 + match_data->target_device = dev; 336 333 return 1; 337 334 } 338 335 } ··· 363 356 int ret; 364 357 365 358 if (has_acpi_companion(&pdev->dev)) { 359 + struct emac_match_data match_data = { 360 + .sgmii_ops = &phy->sgmii_ops, 361 + .target_device = NULL, 362 + }; 366 363 struct device *dev; 367 364 368 - dev = device_find_child(&pdev->dev, &phy->sgmii_ops, 369 - emac_sgmii_acpi_match); 365 + device_for_each_child(&pdev->dev, &match_data, emac_sgmii_acpi_match); 366 + dev = match_data.target_device; 370 367 371 368 if (!dev) { 372 369 dev_warn(&pdev->dev, "cannot find internal phy node\n"); 373 370 return 0; 374 371 } 375 372 373 + get_device(dev); 376 374 sgmii_pdev = to_platform_device(dev); 377 375 } else { 378 376 const struct of_device_id *match;