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

phy: mediatek: xsphy: Simplify with scoped for each OF child loop

Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240826-phy-of-node-scope-v1-6-5b4d82582644@linaro.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Krzysztof Kozlowski and committed by
Vinod Koul
77df35ac d2714416

+9 -18
+9 -18
drivers/phy/mediatek/phy-mtk-xsphy.c
··· 432 432 { 433 433 struct device *dev = &pdev->dev; 434 434 struct device_node *np = dev->of_node; 435 - struct device_node *child_np; 436 435 struct phy_provider *provider; 437 436 struct resource *glb_res; 438 437 struct mtk_xsphy *xsphy; 439 438 struct resource res; 440 - int port, retval; 439 + int port; 441 440 442 441 xsphy = devm_kzalloc(dev, sizeof(*xsphy), GFP_KERNEL); 443 442 if (!xsphy) ··· 470 471 device_property_read_u32(dev, "mediatek,src-coef", &xsphy->src_coef); 471 472 472 473 port = 0; 473 - for_each_child_of_node(np, child_np) { 474 + for_each_child_of_node_scoped(np, child_np) { 474 475 struct xsphy_instance *inst; 475 476 struct phy *phy; 477 + int retval; 476 478 477 479 inst = devm_kzalloc(dev, sizeof(*inst), GFP_KERNEL); 478 - if (!inst) { 479 - retval = -ENOMEM; 480 - goto put_child; 481 - } 480 + if (!inst) 481 + return -ENOMEM; 482 482 483 483 xsphy->phys[port] = inst; 484 484 485 485 phy = devm_phy_create(dev, child_np, &mtk_xsphy_ops); 486 486 if (IS_ERR(phy)) { 487 487 dev_err(dev, "failed to create phy\n"); 488 - retval = PTR_ERR(phy); 489 - goto put_child; 488 + return PTR_ERR(phy); 490 489 } 491 490 492 491 retval = of_address_to_resource(child_np, 0, &res); 493 492 if (retval) { 494 493 dev_err(dev, "failed to get address resource(id-%d)\n", 495 494 port); 496 - goto put_child; 495 + return retval; 497 496 } 498 497 499 498 inst->port_base = devm_ioremap_resource(&phy->dev, &res); 500 499 if (IS_ERR(inst->port_base)) { 501 500 dev_err(dev, "failed to remap phy regs\n"); 502 - retval = PTR_ERR(inst->port_base); 503 - goto put_child; 501 + return PTR_ERR(inst->port_base); 504 502 } 505 503 506 504 inst->phy = phy; ··· 508 512 inst->ref_clk = devm_clk_get(&phy->dev, "ref"); 509 513 if (IS_ERR(inst->ref_clk)) { 510 514 dev_err(dev, "failed to get ref_clk(id-%d)\n", port); 511 - retval = PTR_ERR(inst->ref_clk); 512 - goto put_child; 515 + return PTR_ERR(inst->ref_clk); 513 516 } 514 517 } 515 518 516 519 provider = devm_of_phy_provider_register(dev, mtk_phy_xlate); 517 520 return PTR_ERR_OR_ZERO(provider); 518 - 519 - put_child: 520 - of_node_put(child_np); 521 - return retval; 522 521 } 523 522 524 523 static struct platform_driver mtk_xsphy_driver = {