Skip to content

Commit 163d389

Browse files
lunnclaudiubeznea
authored andcommitted
net: of_get_phy_mode: Change API to solve int/unit warnings
Before this change of_get_phy_mode() returned an enum, phy_interface_t. On error, -ENODEV etc, is returned. If the result of the function is stored in a variable of type phy_interface_t, and the compiler has decided to represent this as an unsigned int, comparision with -ENODEV etc, is a signed vs unsigned comparision. Fix this problem by changing the API. Make the function return an error, or 0 on success, and pass a pointer, of type phy_interface_t, where the phy mode should be stored. v2: Return with *interface set to PHY_INTERFACE_MODE_NA on error. Add error checks to all users of of_get_phy_mode() Fixup a few reverse christmas tree errors Fixup a few slightly malformed reverse christmas trees v3: Fix 0-day reported errors. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net> [claudiu.beznea@microchip.com: fix conflicts] Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
1 parent ba19874 commit 163d389

53 files changed

Lines changed: 499 additions & 146 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

drivers/net/dsa/bcm_sf2.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,9 @@ static void bcm_sf2_identify_ports(struct bcm_sf2_priv *priv,
381381
struct device_node *dn)
382382
{
383383
struct device_node *port;
384-
int mode;
385384
unsigned int port_num;
385+
phy_interface_t mode;
386+
int err;
386387

387388
priv->moca_port = -1;
388389

@@ -395,8 +396,8 @@ static void bcm_sf2_identify_ports(struct bcm_sf2_priv *priv,
395396
* has completed, since they might be turned off at that
396397
* time
397398
*/
398-
mode = of_get_phy_mode(port);
399-
if (mode < 0)
399+
err = of_get_phy_mode(port, &mode);
400+
if (err)
400401
continue;
401402

402403
if (mode == PHY_INTERFACE_MODE_INTERNAL)

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ EXPORT_SYMBOL(ksz_switch_alloc);
419419
int ksz_switch_register(struct ksz_device *dev,
420420
const struct ksz_dev_ops *ops)
421421
{
422+
phy_interface_t interface;
422423
int ret;
423424

424425
if (dev->pdata)
@@ -453,9 +454,9 @@ int ksz_switch_register(struct ksz_device *dev,
453454
* device tree.
454455
*/
455456
if (dev->dev->of_node) {
456-
ret = of_get_phy_mode(dev->dev->of_node);
457-
if (ret >= 0)
458-
dev->interface = ret;
457+
ret = of_get_phy_mode(dev->dev->of_node, &interface);
458+
if (ret == 0)
459+
dev->interface = interface;
459460
dev->synclko_125 = of_property_read_bool(dev->dev->of_node,
460461
"microchip,synclko-125");
461462
}

drivers/net/dsa/mt7530.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,9 @@ mt7530_setup(struct dsa_switch *ds)
13401340

13411341
if (!dsa_is_unused_port(ds, 5)) {
13421342
priv->p5_intf_sel = P5_INTF_SEL_GMAC5;
1343-
interface = of_get_phy_mode(ds->ports[5].dn);
1343+
ret = of_get_phy_mode(ds->ports[5].dn, &interface);
1344+
if (ret && ret != -ENODEV)
1345+
return ret;
13441346
} else {
13451347
/* Scan the ethernet nodes. look for GMAC1, lookup used phy */
13461348
for_each_child_of_node(dn, mac_np) {
@@ -1354,7 +1356,9 @@ mt7530_setup(struct dsa_switch *ds)
13541356

13551357
phy_node = of_parse_phandle(mac_np, "phy-handle", 0);
13561358
if (phy_node->parent == priv->dev->of_node->parent) {
1357-
interface = of_get_phy_mode(mac_np);
1359+
ret = of_get_phy_mode(mac_np, &interface);
1360+
if (ret && ret != -ENODEV)
1361+
return ret;
13581362
id = of_mdio_parse_addr(ds->dev, phy_node);
13591363
if (id == 0)
13601364
priv->p5_intf_sel = P5_INTF_SEL_PHY_P0;

drivers/net/dsa/qca8k.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,8 @@ static int
639639
qca8k_setup(struct dsa_switch *ds)
640640
{
641641
struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
642-
int ret, i, phy_mode = -1;
642+
phy_interface_t phy_mode = PHY_INTERFACE_MODE_NA;
643+
int ret, i;
643644
u32 mask;
644645

645646
/* Make sure that port 0 is the cpu port */
@@ -661,10 +662,10 @@ qca8k_setup(struct dsa_switch *ds)
661662
return ret;
662663

663664
/* Initialize CPU port pad mode (xMII type, delays...) */
664-
phy_mode = of_get_phy_mode(ds->ports[QCA8K_CPU_PORT].dn);
665-
if (phy_mode < 0) {
665+
ret = of_get_phy_mode(ds->ports[QCA8K_CPU_PORT].dn, &phy_mode);
666+
if (ret) {
666667
pr_err("Can't find phy-mode for master device\n");
667-
return phy_mode;
668+
return ret;
668669
}
669670
ret = qca8k_set_pad_ctrl(priv, QCA8K_CPU_PORT, phy_mode);
670671
if (ret < 0)

drivers/net/dsa/sja1105/sja1105_main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,9 @@ static int sja1105_parse_ports_node(struct sja1105_private *priv,
621621

622622
for_each_child_of_node(ports_node, child) {
623623
struct device_node *phy_node;
624-
int phy_mode;
624+
phy_interface_t phy_mode;
625625
u32 index;
626+
int err;
626627

627628
/* Get switch port number from DT */
628629
if (of_property_read_u32(child, "reg", &index) < 0) {
@@ -633,8 +634,8 @@ static int sja1105_parse_ports_node(struct sja1105_private *priv,
633634
}
634635

635636
/* Get PHY mode from DT */
636-
phy_mode = of_get_phy_mode(child);
637-
if (phy_mode < 0) {
637+
err = of_get_phy_mode(child, &phy_mode);
638+
if (err) {
638639
dev_err(dev, "Failed to read phy-mode or "
639640
"phy-interface-type property for port %d\n",
640641
index);

drivers/net/ethernet/altera/altera_tse_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,12 +730,12 @@ static int altera_tse_phy_get_addr_mdio_create(struct net_device *dev)
730730
{
731731
struct altera_tse_private *priv = netdev_priv(dev);
732732
struct device_node *np = priv->device->of_node;
733-
int ret = 0;
733+
int ret;
734734

735-
priv->phy_iface = of_get_phy_mode(np);
735+
ret = of_get_phy_mode(np, &priv->phy_iface);
736736

737737
/* Avoid get phy addr and create mdio if no phy is present */
738-
if (!priv->phy_iface)
738+
if (ret)
739739
return 0;
740740

741741
/* try to get PHY address from device tree, use PHY autodetection if

drivers/net/ethernet/arc/emac_arc.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
static int emac_arc_probe(struct platform_device *pdev)
2121
{
2222
struct device *dev = &pdev->dev;
23-
struct net_device *ndev;
2423
struct arc_emac_priv *priv;
25-
int interface, err;
24+
phy_interface_t interface;
25+
struct net_device *ndev;
26+
int err;
2627

2728
if (!dev->of_node)
2829
return -ENODEV;
@@ -37,9 +38,13 @@ static int emac_arc_probe(struct platform_device *pdev)
3738
priv->drv_name = DRV_NAME;
3839
priv->drv_version = DRV_VERSION;
3940

40-
interface = of_get_phy_mode(dev->of_node);
41-
if (interface < 0)
42-
interface = PHY_INTERFACE_MODE_MII;
41+
err = of_get_phy_mode(dev->of_node, &interface);
42+
if (err) {
43+
if (err == -ENODEV)
44+
interface = PHY_INTERFACE_MODE_MII;
45+
else
46+
goto out_netdev;
47+
}
4348

4449
priv->clk = devm_clk_get(dev, "hclk");
4550
if (IS_ERR(priv->clk)) {

drivers/net/ethernet/arc/emac_rockchip.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ static int emac_rockchip_probe(struct platform_device *pdev)
9797
struct net_device *ndev;
9898
struct rockchip_priv_data *priv;
9999
const struct of_device_id *match;
100+
phy_interface_t interface;
100101
u32 data;
101-
int err, interface;
102+
int err;
102103

103104
if (!pdev->dev.of_node)
104105
return -ENODEV;
@@ -114,7 +115,9 @@ static int emac_rockchip_probe(struct platform_device *pdev)
114115
priv->emac.drv_version = DRV_VERSION;
115116
priv->emac.set_mac_speed = emac_rockchip_set_mac_speed;
116117

117-
interface = of_get_phy_mode(dev->of_node);
118+
err = of_get_phy_mode(dev->of_node, &interface);
119+
if (err)
120+
goto out_netdev;
118121

119122
/* RK3036/RK3066/RK3188 SoCs only support RMII */
120123
if (interface != PHY_INTERFACE_MODE_RMII) {

drivers/net/ethernet/atheros/ag71xx.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,10 +1744,9 @@ static int ag71xx_probe(struct platform_device *pdev)
17441744
eth_random_addr(ndev->dev_addr);
17451745
}
17461746

1747-
ag->phy_if_mode = of_get_phy_mode(np);
1748-
if (ag->phy_if_mode < 0) {
1747+
err = of_get_phy_mode(np, ag->phy_if_mode);
1748+
if (err) {
17491749
netif_err(ag, probe, ndev, "missing phy-mode property in DT\n");
1750-
err = ag->phy_if_mode;
17511750
goto err_free;
17521751
}
17531752

drivers/net/ethernet/aurora/nb8800.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,8 +1371,8 @@ static int nb8800_probe(struct platform_device *pdev)
13711371
priv = netdev_priv(dev);
13721372
priv->base = base;
13731373

1374-
priv->phy_mode = of_get_phy_mode(pdev->dev.of_node);
1375-
if (priv->phy_mode < 0)
1374+
ret = of_get_phy_mode(pdev->dev.of_node, &priv->phy_mode);
1375+
if (ret)
13761376
priv->phy_mode = PHY_INTERFACE_MODE_RGMII;
13771377

13781378
priv->clk = devm_clk_get(&pdev->dev, NULL);

0 commit comments

Comments
 (0)