net: of_get_phy_mode: Change API to solve int/unit warnings
Subsystems (36)
Andrew Lunn
maintainerPATCH 1/1 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.
--- drivers/net/dsa/bcm_sf2.c | 7 ++++--- drivers/net/dsa/microchip/ksz_common.c | 7 ++++--- drivers/net/dsa/mt7530.c | 4 ++-- drivers/net/dsa/qca8k.c | 9 +++++---- drivers/net/dsa/sja1105/sja1105_main.c | 7 ++++--- drivers/net/ethernet/altera/altera_tse_main.c | 6 +++--- drivers/net/ethernet/arc/emac_arc.c | 7 ++++--- drivers/net/ethernet/arc/emac_rockchip.c | 7 +++++-- drivers/net/ethernet/atheros/ag71xx.c | 5 ++--- drivers/net/ethernet/aurora/nb8800.c | 4 ++-- drivers/net/ethernet/aurora/nb8800.h | 2 +- drivers/net/ethernet/broadcom/bcmsysport.c | 4 ++-- drivers/net/ethernet/broadcom/genet/bcmmii.c | 8 ++++---- drivers/net/ethernet/cadence/macb_main.c | 7 ++++--- drivers/net/ethernet/faraday/ftgmac100.c | 6 +++--- drivers/net/ethernet/freescale/enetc/enetc_pf.c | 4 ++-- drivers/net/ethernet/freescale/fec_main.c | 7 ++++--- drivers/net/ethernet/freescale/fman/mac.c | 6 +++--- drivers/net/ethernet/freescale/gianfar.c | 7 ++++--- drivers/net/ethernet/hisilicon/hip04_eth.c | 7 +++---- drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 5 ++--- drivers/net/ethernet/ibm/emac/core.c | 5 +++-- drivers/net/ethernet/marvell/mv643xx_eth.c | 7 ++++--- drivers/net/ethernet/marvell/mvneta.c | 7 +++---- drivers/net/ethernet/marvell/pxa168_eth.c | 2 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 ++++---- drivers/net/ethernet/mscc/ocelot_board.c | 6 +++--- drivers/net/ethernet/ni/nixge.c | 5 ++--- drivers/net/ethernet/renesas/ravb_main.c | 2 +- drivers/net/ethernet/renesas/sh_eth.c | 7 ++++--- drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c | 2 +- drivers/net/ethernet/socionext/sni_ave.c | 6 +++--- drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c | 8 ++++++-- drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c | 5 +++-- .../net/ethernet/stmicro/stmmac/dwmac-mediatek.c | 9 +++++---- drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c | 5 ++--- drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 4 ++-- drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 4 ++-- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 7 ++++--- drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c | 4 ++-- .../net/ethernet/stmicro/stmmac/stmmac_platform.c | 6 +++--- drivers/net/ethernet/ti/cpsw.c | 5 ++--- drivers/net/ethernet/ti/cpsw_priv.h | 2 +- drivers/net/ethernet/ti/netcp_ethss.c | 5 +++-- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 6 ++---- drivers/of/of_mdio.c | 4 ++-- drivers/of/of_net.c | 13 ++++++++----- include/linux/of_net.h | 7 +++++-- include/linux/stmmac.h | 3 ++- include/linux/sxgbe_platform.h | 4 +++- net/dsa/port.c | 13 +++++++------ net/dsa/slave.c | 7 ++++--- 52 files changed, 164 insertions(+), 140 deletions(-)
drivers/net/dsa/bcm_sf2.c +4 -3
@@ -375,8 +375,9 @@ static void bcm_sf2_identify_ports(struct bcm_sf2_priv *priv, struct device_node *dn) {struct device_node *port; -int mode; +phy_interface_t mode;unsigned int port_num; +int err; priv->moca_port =-1 ;
@@ -389,8 +390,8 @@ static void bcm_sf2_identify_ports(struct bcm_sf2_priv *priv,* has completed, since they might be turned off at that * time */ - mode =of_get_phy_mode (port); -if (mode <0 ) + err =of_get_phy_mode (port, &mode); +if (err)continue ;if (mode ==PHY_INTERFACE_MODE_INTERNAL )
drivers/net/dsa/microchip/ksz_common.c +4 -3
@@ -419,6 +419,7 @@ EXPORT_SYMBOL(ksz_switch_alloc);int ksz_switch_register (struct ksz_device *dev,const struct ksz_dev_ops *ops) { +phy_interface_t interface;int ret;if (dev->pdata)
@@ -453,9 +454,9 @@ int ksz_switch_register(struct ksz_device *dev,* device tree. */ if (dev->dev->of_node) { - ret =of_get_phy_mode (dev->dev->of_node); -if (ret >=0 ) - dev->interface = ret; + ret =of_get_phy_mode (dev->dev->of_node, &interface); +if (ret ==0 ) + dev->interface = interface; dev->synclko_125 =of_property_read_bool (dev->dev->of_node,"microchip,synclko-125" ); }
drivers/net/dsa/mt7530.c +2 -2
@@ -1340,7 +1340,7 @@ mt7530_setup(struct dsa_switch *ds)if (!dsa_is_unused_port (ds,5 )) { priv->p5_intf_sel =P5_INTF_SEL_GMAC5 ; - interface =of_get_phy_mode (ds->ports[5 ].dn); +of_get_phy_mode (ds->ports[5 ].dn, &interface); }else {/* Scan the ethernet nodes. look for GMAC1, lookup used phy */ for_each_child_of_node (dn, mac_np) {
@@ -1354,7 +1354,7 @@ mt7530_setup(struct dsa_switch *ds) phy_node =of_parse_phandle (mac_np,"phy-handle" ,0 );if (phy_node->parent == priv->dev->of_node->parent) { - interface =of_get_phy_mode (mac_np); +of_get_phy_mode (mac_np, &interface); id =of_mdio_parse_addr (ds->dev, phy_node);if (id ==0 ) priv->p5_intf_sel =P5_INTF_SEL_PHY_P0 ;
drivers/net/dsa/qca8k.c +5 -4
@@ -639,7 +639,8 @@ static int qca8k_setup(struct dsa_switch *ds) {struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; -int ret, i, phy_mode =-1 ; +phy_interface_t phy_mode =PHY_INTERFACE_MODE_NA ; +int ret, i;u32 mask;/* Make sure that port 0 is the cpu port */
@@ -661,10 +662,10 @@ qca8k_setup(struct dsa_switch *ds)return ret;/* Initialize CPU port pad mode (xMII type, delays...) */ - phy_mode =of_get_phy_mode (ds->ports[QCA8K_CPU_PORT ].dn); -if (phy_mode <0 ) { + ret =of_get_phy_mode (ds->ports[QCA8K_CPU_PORT ].dn, &phy_mode); +if (ret) {pr_err ("Can't find phy-mode for master device\n" ); -return phy_mode; +return ret; } ret =qca8k_set_pad_ctrl (priv,QCA8K_CPU_PORT , phy_mode);if (ret <0 )
drivers/net/dsa/sja1105/sja1105_main.c +4 -3
@@ -584,8 +584,9 @@ static int sja1105_parse_ports_node(struct sja1105_private *priv,for_each_child_of_node (ports_node, child) {struct device_node *phy_node; -int phy_mode; +phy_interface_t phy_mode;u32 index; +int err;/* Get switch port number from DT */ if (of_property_read_u32 (child,"reg" , &index) <0 ) {
@@ -596,8 +597,8 @@ static int sja1105_parse_ports_node(struct sja1105_private *priv, }/* Get PHY mode from DT */ - phy_mode =of_get_phy_mode (child); -if (phy_mode <0 ) { + err =of_get_phy_mode (child, &phy_mode); +if (err) {dev_err (dev,"Failed to read phy-mode or " "phy-interface-type property for port %d\n" , index);
drivers/net/ethernet/altera/altera_tse_main.c +3 -3
@@ -730,12 +730,12 @@ static int altera_tse_phy_get_addr_mdio_create(struct net_device *dev) {struct altera_tse_private *priv =netdev_priv (dev);struct device_node *np = priv->device->of_node; -int ret =0 ; +int ret; - priv->phy_iface =of_get_phy_mode (np); + ret =of_get_phy_mode (np, &priv->phy_iface);/* Avoid get phy addr and create mdio if no phy is present */ -if (!priv->phy_iface) +if (ret)return 0 ;/* try to get PHY address from device tree, use PHY autodetection if
drivers/net/ethernet/arc/emac_arc.c +4 -3
@@ -20,9 +20,10 @@static int emac_arc_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; +phy_interface_t interface;struct net_device *ndev;struct arc_emac_priv *priv; -int interface, err; +int err;if (!dev->of_node)return -ENODEV ;
@@ -37,8 +38,8 @@ static int emac_arc_probe(struct platform_device *pdev) priv->drv_name =DRV_NAME ; priv->drv_version =DRV_VERSION ; - interface =of_get_phy_mode (dev->of_node); -if (interface <0 ) + err =of_get_phy_mode (dev->of_node, &interface); +if (err) interface =PHY_INTERFACE_MODE_MII ; priv->clk =devm_clk_get (dev,"hclk" );
drivers/net/ethernet/arc/emac_rockchip.c +5 -2
@@ -97,8 +97,9 @@ static int emac_rockchip_probe(struct platform_device *pdev)struct net_device *ndev;struct rockchip_priv_data *priv;const struct of_device_id *match; +phy_interface_t interface;u32 data; -int err, interface; +int err;if (!pdev->dev.of_node)return -ENODEV ;
@@ -114,7 +115,9 @@ static int emac_rockchip_probe(struct platform_device *pdev) priv->emac.drv_version =DRV_VERSION ; priv->emac.set_mac_speed = emac_rockchip_set_mac_speed; - interface =of_get_phy_mode (dev->of_node); + err =of_get_phy_mode (dev->of_node, &interface); +if (err) + goto out_netdev;/* RK3036/RK3066/RK3188 SoCs only support RMII */ if (interface !=PHY_INTERFACE_MODE_RMII ) {
drivers/net/ethernet/atheros/ag71xx.c +2 -3
@@ -1744,10 +1744,9 @@ static int ag71xx_probe(struct platform_device *pdev)eth_random_addr (ndev->dev_addr); } - ag->phy_if_mode =of_get_phy_mode (np); -if (ag->phy_if_mode <0 ) { + err =of_get_phy_mode (np, ag->phy_if_mode); +if (err) {netif_err (ag, probe, ndev,"missing phy-mode property in DT\n" ); - err = ag->phy_if_mode; goto err_free; }
drivers/net/ethernet/aurora/nb8800.c +2 -2
@@ -1371,8 +1371,8 @@ static int nb8800_probe(struct platform_device *pdev) priv =netdev_priv (dev); priv->base = base; - priv->phy_mode =of_get_phy_mode (pdev->dev.of_node); -if (priv->phy_mode <0 ) + ret =of_get_phy_mode (pdev->dev.of_node, &priv->phy_mode); +if (ret) priv->phy_mode =PHY_INTERFACE_MODE_RGMII ; priv->clk =devm_clk_get (&pdev->dev,NULL );
drivers/net/ethernet/aurora/nb8800.h +1 -1
@@ -287,7 +287,7 @@ struct nb8800_priv {struct device_node *phy_node;/* PHY connection type from DT */ -int phy_mode; +phy_interface_t phy_mode;/* Current link status */ int speed;
drivers/net/ethernet/broadcom/bcmsysport.c +2 -2
@@ -2479,9 +2479,9 @@ static int bcm_sysport_probe(struct platform_device *pdev) priv->netdev = dev; priv->pdev = pdev; - priv->phy_interface =of_get_phy_mode (dn); + ret =of_get_phy_mode (dn, &priv->phy_interface);/* Default to GMII interface mode */ -if ((int )priv->phy_interface <0 ) +if (ret) priv->phy_interface =PHY_INTERFACE_MODE_GMII ;/* In the case of a fixed PHY, the DT node associated
drivers/net/ethernet/broadcom/genet/bcmmii.c +4 -4
@@ -441,7 +441,7 @@ static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv)struct device_node *dn = priv->pdev->dev.of_node;struct device *kdev = &priv->pdev->dev;struct phy_device *phydev; -int phy_mode; +phy_interface_t phy_mode;int ret;/* Fetch the PHY phandle */
@@ -459,10 +459,10 @@ static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv) }/* Get the link mode */ - phy_mode =of_get_phy_mode (dn); -if (phy_mode <0 ) { + ret =of_get_phy_mode (dn, &phy_mode); +if (ret) {dev_err (kdev,"invalid PHY mode property\n" ); -return phy_mode; +return ret; } priv->phy_interface = phy_mode;
drivers/net/ethernet/cadence/macb_main.c +4 -3
@@ -4182,6 +4182,7 @@ static int macb_probe(struct platform_device *pdev)unsigned int queue_mask, num_queues;bool native_io;struct phy_device *phydev; +phy_interface_t interface;struct net_device *dev;struct resource *regs;void __iomem *mem;
@@ -4308,12 +4309,12 @@ static int macb_probe(struct platform_device *pdev)macb_get_hwaddr (bp); } - err =of_get_phy_mode (np); -if (err <0 ) + err =of_get_phy_mode (np, &interface); +if (err)/* not found in DT, MII by default */ bp->phy_interface =PHY_INTERFACE_MODE_MII ;else - bp->phy_interface = err; + bp->phy_interface = interface;/* IP specific init */ err =init (pdev);
drivers/net/ethernet/faraday/ftgmac100.c +3 -3
@@ -1613,7 +1613,7 @@ static int ftgmac100_setup_mdio(struct net_device *netdev) {struct ftgmac100 *priv =netdev_priv (netdev);struct platform_device *pdev =to_platform_device (priv->dev); -int phy_intf =PHY_INTERFACE_MODE_RGMII ; +phy_interface_t phy_intf =PHY_INTERFACE_MODE_RGMII ;struct device_node *np = pdev->dev.of_node;int i, err =0 ;u32 reg;
@@ -1638,8 +1638,8 @@ static int ftgmac100_setup_mdio(struct net_device *netdev)/* Get PHY mode from device-tree */ if (np) {/* Default to RGMII. It's a gigabit part after all */ - phy_intf =of_get_phy_mode (np); -if (phy_intf <0 ) + err =of_get_phy_mode (np, &phy_intf); +if (err) phy_intf =PHY_INTERFACE_MODE_RGMII ;/* Aspeed only supports these. I don't know about other IP
drivers/net/ethernet/freescale/enetc/enetc_pf.c +2 -2
@@ -784,8 +784,8 @@ static int enetc_of_get_phy(struct enetc_ndev_priv *priv) } } - priv->if_mode =of_get_phy_mode (np); -if ((int )priv->if_mode <0 ) { + err =of_get_phy_mode (np, &priv->if_mode); +if (err) {dev_err (priv->dev,"missing phy type\n" );of_node_put (priv->phy_node);if (of_phy_is_fixed_link (np))
drivers/net/ethernet/freescale/fec_main.c +4 -3
@@ -3394,6 +3394,7 @@ fec_probe(struct platform_device *pdev) {struct fec_enet_private *fep;struct fec_platform_data *pdata; +phy_interface_t interface;struct net_device *ndev;int i, irq, ret =0 ;const struct of_device_id *of_id;
@@ -3466,15 +3467,15 @@ fec_probe(struct platform_device *pdev) } fep->phy_node = phy_node; - ret =of_get_phy_mode (pdev->dev.of_node); -if (ret <0 ) { + ret =of_get_phy_mode (pdev->dev.of_node, &interface); +if (ret) { pdata =dev_get_platdata (&pdev->dev);if (pdata) fep->phy_interface = pdata->phy;else fep->phy_interface =PHY_INTERFACE_MODE_MII ; }else { - fep->phy_interface = ret; + fep->phy_interface = interface; } fep->clk_ipg =devm_clk_get (&pdev->dev,"ipg" );
drivers/net/ethernet/freescale/fman/mac.c +3 -3
@@ -608,7 +608,7 @@ static int mac_probe(struct platform_device *_of_dev)const u8 *mac_addr;u32 val;u8 fman_id; -int phy_if; +phy_interface_t phy_if; dev = &_of_dev->dev; mac_node = dev->of_node;
@@ -776,8 +776,8 @@ static int mac_probe(struct platform_device *_of_dev) }/* Get the PHY connection type */ - phy_if =of_get_phy_mode (mac_node); -if (phy_if <0 ) { + err =of_get_phy_mode (mac_node, &phy_if); +if (err) {dev_warn (dev,"of_get_phy_mode() for %pOF failed. Defaulting to SGMII\n" , mac_node);
drivers/net/ethernet/freescale/gianfar.c +4 -3
@@ -641,6 +641,7 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)const char *model;const void *mac_addr;int err =0 , i; +phy_interface_t interface;struct net_device *dev =NULL ;struct gfar_private *priv =NULL ;struct device_node *np = ofdev->dev.of_node;
@@ -805,9 +806,9 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)* rgmii-id really needs to be specified. Other types can be * detected by hardware */ - err =of_get_phy_mode (np); -if (err >=0 ) - priv->interface = err; + err =of_get_phy_mode (np, &interface); +if (!err) + priv->interface = interface;else priv->interface =gfar_get_interface (dev);
drivers/net/ethernet/hisilicon/hip04_eth.c +3 -4
@@ -211,7 +211,7 @@ struct hip04_priv {#if defined(CONFIG_HI13X1_GMAC )void __iomem *sysctrl_base;#endif -int phy_mode; +phy_interface_t phy_mode;int chan;unsigned int port;unsigned int group;
@@ -958,10 +958,9 @@ static int hip04_mac_probe(struct platform_device *pdev) goto init_fail; } - priv->phy_mode =of_get_phy_mode (node); -if (priv->phy_mode <0 ) { + ret =of_get_phy_mode (node, &priv->phy_mode); +if (ret) {dev_warn (d,"not find phy-mode\n" ); - ret = -EINVAL ; goto init_fail; }
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +2 -3
@@ -1193,10 +1193,9 @@ static int hix5hd2_dev_probe(struct platform_device *pdev)if (ret) goto err_free_mdio; - priv->phy_mode =of_get_phy_mode (node); -if ((int )priv->phy_mode <0 ) { + ret =of_get_phy_mode (node, &priv->phy_mode); +if (ret) {netdev_err (ndev,"not find phy-mode\n" ); - ret = -EINVAL ; goto err_mdiobus; }
drivers/net/ethernet/ibm/emac/core.c +3 -2
@@ -2849,6 +2849,7 @@ static int emac_init_config(struct emac_instance *dev) {struct device_node *np = dev->ofdev->dev.of_node;const void *p; +int err;/* Read config from device-tree */ if (emac_read_uint_prop (np,"mal-device" , &dev->mal_ph,1 ))
@@ -2897,8 +2898,8 @@ static int emac_init_config(struct emac_instance *dev) dev->mal_burst_size =256 ;/* PHY mode needs some decoding */ - dev->phy_mode =of_get_phy_mode (np); -if (dev->phy_mode <0 ) + err =of_get_phy_mode (np, &dev->phy_mode); +if (err) dev->phy_mode =PHY_INTERFACE_MODE_NA ;/* Check EMAC version */
drivers/net/ethernet/marvell/mv643xx_eth.c +4 -3
@@ -2959,15 +2959,16 @@ static void set_params(struct mv643xx_eth_private *mp,static int get_phy_mode (struct mv643xx_eth_private *mp) {struct device *dev = mp->dev->dev.parent; -int iface =-1 ; +phy_interface_t iface; +int err;if (dev->of_node) - iface =of_get_phy_mode (dev->of_node); + err =of_get_phy_mode (dev->of_node, &iface);/* Historical default if unspecified. We could also read/write * the interface state in the PSC1 */ -if (iface <0 ) +if (err || !dev->of_node) iface =PHY_INTERFACE_MODE_GMII ;return iface; }
drivers/net/ethernet/marvell/mvneta.c +3 -4
@@ -4477,9 +4477,9 @@ static int mvneta_probe(struct platform_device *pdev)struct phy *comphy;const char *dt_mac_addr;char hw_mac_addr[ETH_ALEN ]; +phy_interface_t phy_mode;const char *mac_from;int tx_csum_limit; -int phy_mode;int err;int cpu;
@@ -4492,10 +4492,9 @@ static int mvneta_probe(struct platform_device *pdev)if (dev->irq ==0 )return -EINVAL ; - phy_mode =of_get_phy_mode (dn); -if (phy_mode <0 ) { + err =of_get_phy_mode (dn, &phy_mode); +if (err) {dev_err (&pdev->dev,"incorrect phy-mode\n" ); - err = -EINVAL ; goto err_free_irq; }
drivers/net/ethernet/marvell/pxa168_eth.c +1 -1
@@ -1489,7 +1489,7 @@ static int pxa168_eth_probe(struct platform_device *pdev) goto err_netdev; }of_property_read_u32 (np,"reg" , &pep->phy_addr); - pep->phy_intf =of_get_phy_mode (pdev->dev.of_node); +of_get_phy_mode (pdev->dev.of_node, &pep->phy_intf);of_node_put (np); }
drivers/net/ethernet/mediatek/mtk_eth_soc.c +4 -4
@@ -2757,8 +2757,9 @@ static const struct net_device_ops mtk_netdev_ops = {static int mtk_add_mac (struct mtk_eth *eth,struct device_node *np) {const __be32 *_id =of_get_property (np,"reg" ,NULL ); +phy_interface_t phy_mode;struct phylink *phylink; -int phy_mode, id, err; +int id, err;struct mtk_mac *mac;if (!_id) {
@@ -2804,10 +2805,9 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np) mac->hw_stats->reg_offset = id *MTK_STAT_OFFSET ;/* phylink create */ - phy_mode =of_get_phy_mode (np); -if (phy_mode <0 ) { + err =of_get_phy_mode (np, &phy_mode); +if (err) {dev_err (eth->dev,"incorrect phy-mode\n" ); - err = -EINVAL ; goto free_netdev; }
drivers/net/ethernet/mscc/ocelot_board.c +3 -3
@@ -364,12 +364,12 @@ static int mscc_ocelot_probe(struct platform_device *pdev)for_each_available_child_of_node (ports, portnp) {struct device_node *phy_node; +phy_interface_t phy_mode;struct phy_device *phy;struct resource *res;struct phy *serdes;void __iomem *regs;char res_name[8 ]; -int phy_mode;u32 port;if (of_property_read_u32 (portnp,"reg" , &port))
@@ -398,8 +398,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev) goto out_put_ports; } - phy_mode =of_get_phy_mode (portnp); -if (phy_mode <0 ) + err =of_get_phy_mode (portnp, &phy_mode); +if (err) ocelot->ports[port]->phy_mode =PHY_INTERFACE_MODE_NA ;else ocelot->ports[port]->phy_mode = phy_mode;
drivers/net/ethernet/ni/nixge.c +2 -3
@@ -1346,10 +1346,9 @@ static int nixge_probe(struct platform_device *pdev) } } - priv->phy_mode =of_get_phy_mode (pdev->dev.of_node); -if ((int )priv->phy_mode <0 ) { + err =of_get_phy_mode (pdev->dev.of_node, &priv->phy_mode); +if (err) {netdev_err (ndev,"not find \"phy-mode\" property\n" ); - err = -EINVAL ; goto unregister_mdio; }
drivers/net/ethernet/renesas/ravb_main.c +1 -1
@@ -2046,7 +2046,7 @@ static int ravb_probe(struct platform_device *pdev)spin_lock_init (&priv->lock);INIT_WORK (&priv->work, ravb_tx_timeout_work); - priv->phy_interface =of_get_phy_mode (np); + error =of_get_phy_mode (np, &priv->phy_interface); priv->no_avb_link =of_property_read_bool (np,"renesas,no-ether-link" ); priv->avb_link_active_low =
drivers/net/ethernet/renesas/sh_eth.c +4 -3
@@ -3183,6 +3183,7 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) {struct device_node *np = dev->of_node;struct sh_eth_plat_data *pdata; +phy_interface_t interface;const char *mac_addr;int ret;
@@ -3190,10 +3191,10 @@ static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)if (!pdata)return NULL ; - ret =of_get_phy_mode (np); -if (ret <0 ) + ret =of_get_phy_mode (np, &interface); +if (ret)return NULL ; - pdata->phy_interface = ret; + pdata->phy_interface = interface; mac_addr =of_get_mac_address (np);if (!IS_ERR (mac_addr))
drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c +1 -1
@@ -35,7 +35,7 @@ static int sxgbe_probe_config_dt(struct platform_device *pdev,return -ENODEV ; *mac =of_get_mac_address (np); - plat->interface =of_get_phy_mode (np); +of_get_phy_mode (np, &plat->interface); plat->bus_id =of_alias_get_id (np,"ethernet" );if (plat->bus_id <0 )
drivers/net/ethernet/socionext/sni_ave.c +3 -3
@@ -1565,10 +1565,10 @@ static int ave_probe(struct platform_device *pdev)return -EINVAL ; np = dev->of_node; - phy_mode =of_get_phy_mode (np); -if ((int )phy_mode <0 ) { + ret =of_get_phy_mode (np, &phy_mode); +if (ret) {dev_err (dev,"phy-mode not found\n" ); -return -EINVAL ; +return ret; } irq =platform_get_irq (pdev,0 );
drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c +6 -2
@@ -61,9 +61,10 @@ static void anarion_gmac_exit(struct platform_device *pdev, void *priv)static struct anarion_gmac *anarion_config_dt (struct platform_device *pdev) { -int phy_mode; +phy_interface_t phy_mode;void __iomem *ctl_block;struct anarion_gmac *gmac; +int err; ctl_block =devm_platform_ioremap_resource (pdev,1 );if (IS_ERR (ctl_block)) {
@@ -78,7 +79,10 @@ static struct anarion_gmac *anarion_config_dt(struct platform_device *pdev) gmac->ctl_block = (uintptr_t )ctl_block; - phy_mode =of_get_phy_mode (pdev->dev.of_node); + err =of_get_phy_mode (pdev->dev.of_node, &phy_mode); +if (err) +return ERR_PTR (err); +switch (phy_mode) {case PHY_INTERFACE_MODE_RGMII :/* Fall through */ case PHY_INTERFACE_MODE_RGMII_ID /* Fall through */ :
drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c +3 -2
@@ -189,9 +189,10 @@ static int ipq806x_gmac_set_speed(struct ipq806x_gmac *gmac, unsigned int speed)static int ipq806x_gmac_of_parse (struct ipq806x_gmac *gmac) {struct device *dev = &gmac->pdev->dev; +int ret; - gmac->phy_mode =of_get_phy_mode (dev->of_node); -if ((int )gmac->phy_mode <0 ) { + ret =of_get_phy_mode (dev->of_node, &gmac->phy_mode); +if (ret) {dev_err (dev,"missing phy mode property\n" );return -EINVAL ; }
drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c +5 -4
@@ -54,7 +54,7 @@ struct mediatek_dwmac_plat_data {struct device_node *np;struct regmap *peri_regmap;struct device *dev; -int phy_mode; +phy_interface_t phy_mode;bool rmii_rxc; };
@@ -243,6 +243,7 @@ static int mediatek_dwmac_config_dt(struct mediatek_dwmac_plat_data *plat) {struct mac_delay_struct *mac_delay = &plat->mac_delay;u32 tx_delay_ps, rx_delay_ps; +int err; plat->peri_regmap =syscon_regmap_lookup_by_phandle (plat->np,"mediatek,pericfg" );if (IS_ERR (plat->peri_regmap)) {
@@ -250,10 +251,10 @@ static int mediatek_dwmac_config_dt(struct mediatek_dwmac_plat_data *plat)return PTR_ERR (plat->peri_regmap); } - plat->phy_mode =of_get_phy_mode (plat->np); -if (plat->phy_mode <0 ) { + err =of_get_phy_mode (plat->np, &plat->phy_mode); +if (err) {dev_err (plat->dev,"not find phy-mode\n" ); -return -EINVAL ; +return err; }if (!of_property_read_u32 (plat->np,"mediatek,tx-delay-ps" , &tx_delay_ps)) {
drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c +2 -3
@@ -338,10 +338,9 @@ static int meson8b_dwmac_probe(struct platform_device *pdev) } dwmac->dev = &pdev->dev; - dwmac->phy_mode =of_get_phy_mode (pdev->dev.of_node); -if ((int )dwmac->phy_mode <0 ) { + ret =of_get_phy_mode (pdev->dev.of_node, &dwmac->phy_mode); +if (ret) {dev_err (&pdev->dev,"missing phy-mode property\n" ); - ret = -EINVAL ; goto err_remove_config_dt; }
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +2 -2
@@ -37,7 +37,7 @@ struct rk_gmac_ops {struct rk_priv_data {struct platform_device *pdev; -int phy_iface; +phy_interface_t phy_iface;struct regulator *regulator;bool suspended;const struct rk_gmac_ops *ops;
@@ -1224,7 +1224,7 @@ static struct rk_priv_data *rk_gmac_setup(struct platform_device *pdev,if (!bsp_priv)return ERR_PTR (-ENOMEM ); - bsp_priv->phy_iface =of_get_phy_mode (dev->of_node); +of_get_phy_mode (dev->of_node, &bsp_priv->phy_iface); bsp_priv->ops = ops; bsp_priv->regulator =devm_regulator_get_optional (dev,"phy" );
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c +2 -2
@@ -116,7 +116,7 @@#define ETH_PHY_SEL_MII 0x0struct sti_dwmac { -int interface;/* MII interface */ +phy_interface_t interface;/* MII interface */ bool ext_phyclk;/* Clock from external PHY */ u32 tx_retime_src;/* TXCLK Retiming*/ struct clk *clk;/* PHY clock */
@@ -269,7 +269,7 @@ static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,return err; } - dwmac->interface =of_get_phy_mode (np); +of_get_phy_mode (np, &dwmac->interface); dwmac->regmap = regmap; dwmac->gmac_en =of_property_read_bool (np,"st,gmac_en" ); dwmac->ext_phyclk =of_property_read_bool (np,"st,ext-phyclk" );
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +4 -3
@@ -1104,6 +1104,7 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)struct stmmac_resources stmmac_res;struct sunxi_priv_data *gmac;struct device *dev = &pdev->dev; +phy_interface_t interface;int ret;struct stmmac_priv *priv;struct net_device *ndev;
@@ -1177,10 +1178,10 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)return ret; } - ret =of_get_phy_mode (dev->of_node); -if (ret <0 ) + ret =of_get_phy_mode (dev->of_node, &interface); +if (ret)return -EINVAL ; - plat_dat->interface = ret; + plat_dat->interface = interface;/* platform data specifying hardware features and callbacks. * hardware features were copied from Allwinner drivers.
drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c +2 -2
@@ -18,7 +18,7 @@#include "stmmac_platform.h" struct sunxi_priv_data { -int interface; +phy_interface_t interface;int clk_enabled;struct clk *tx_clk;struct regulator *regulator;
@@ -118,7 +118,7 @@ static int sun7i_gmac_probe(struct platform_device *pdev) goto err_remove_config_dt; } - gmac->interface =of_get_phy_mode (dev->of_node); +of_get_phy_mode (dev->of_node, &gmac->interface); gmac->tx_clk =devm_clk_get (dev,"allwinner_gmac_tx" );if (IS_ERR (gmac->tx_clk)) {
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +3 -3
@@ -412,9 +412,9 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) *mac =NULL ; } - plat->phy_interface =of_get_phy_mode (np); -if (plat->phy_interface <0 ) -return ERR_PTR (plat->phy_interface); + rc =of_get_phy_mode (np, &plat->phy_interface); +if (rc) +return ERR_PTR (rc); plat->interface =stmmac_of_get_mac_mode (np);if (plat->interface <0 )
drivers/net/ethernet/ti/cpsw.c +2 -3
@@ -2619,11 +2619,10 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data, i); goto no_phy_slave; } - slave_data->phy_if =of_get_phy_mode (slave_node); -if (slave_data->phy_if <0 ) { + ret =of_get_phy_mode (slave_node, &slave_data->phy_if); +if (ret) {dev_err (&pdev->dev,"Missing or malformed slave[%d] phy-mode property\n" , i); - ret = slave_data->phy_if; goto err_node_put; }
drivers/net/ethernet/ti/cpsw_priv.h +1 -1
@@ -275,7 +275,7 @@ struct cpsw_slave_data {struct device_node *slave_node;struct device_node *phy_node;char phy_id[MII_BUS_ID_SIZE ]; -int phy_if; +phy_interface_t phy_if;u8 mac_addr[ETH_ALEN ];u16 dual_emac_res_vlan;/* Reserved VLAN for DualEMAC */ struct phy *ifphy;
drivers/net/ethernet/ti/netcp_ethss.c +3 -2
@@ -2291,6 +2291,7 @@ static int gbe_slave_open(struct gbe_intf *gbe_intf)struct gbe_slave *slave = gbe_intf->slave;phy_interface_t phy_mode;bool has_phy = false; +int err;void (*hndlr)(struct net_device *) = gbe_adjust_link;
@@ -2320,11 +2321,11 @@ static int gbe_slave_open(struct gbe_intf *gbe_intf) slave->phy_port_t =PORT_MII ; }else if (slave->link_interface ==RGMII_LINK_MAC_PHY ) { has_phy = true; - phy_mode =of_get_phy_mode (slave->node); + err =of_get_phy_mode (slave->node, &phy_mode);/* if phy-mode is not present, default to * PHY_INTERFACE_MODE_RGMII */ -if (phy_mode <0 ) +if (err) phy_mode =PHY_INTERFACE_MODE_RGMII ;if (!phy_interface_mode_is_rgmii (phy_mode)) {
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -4
@@ -1761,11 +1761,9 @@ static int axienet_probe(struct platform_device *pdev) goto free_netdev; } }else { - lp->phy_mode =of_get_phy_mode (pdev->dev.of_node); -if ((int )lp->phy_mode <0 ) { - ret = -EINVAL ; + ret =of_get_phy_mode (pdev->dev.of_node, &lp->phy_mode); +if (ret) goto free_netdev; - } }/* Find the DMA node, map the DMA registers, and decode the DMA IRQs */
drivers/of/of_mdio.c +2 -2
@@ -361,8 +361,8 @@ struct phy_device *of_phy_get_and_connect(struct net_device *dev,struct phy_device *phy;int ret; - iface =of_get_phy_mode (np); -if ((int )iface <0 ) + ret =of_get_phy_mode (np, &iface); +if (ret)return NULL ;if (of_phy_is_fixed_link (np)) { ret =of_phy_register_fixed_link (np);
drivers/of/of_net.c +8 -5
@@ -15,12 +15,13 @@/** * of_get_phy_mode - Get phy mode for given device_node * @np: Pointer to the given device_node +* @interface: Pointer to the result * * The function gets phy interface string from property 'phy-mode' or -* 'phy-connection-type', and return its index in phy_modes table, or errno in -* error case. +* 'phy-connection-type', and return its index in phy_modes table in +* interface and returns, or returns an errno in the error case. */ -int of_get_phy_mode (struct device_node *np) +int of_get_phy_mode (struct device_node *np,phy_interface_t *interface) {const char *pm;int err, i;
@@ -32,8 +33,10 @@ int of_get_phy_mode(struct device_node *np)return err;for (i =0 ; i <PHY_INTERFACE_MODE_MAX ; i++) -if (!strcasecmp (pm,phy_modes (i))) -return i; +if (!strcasecmp (pm,phy_modes (i))) { + *interface = i; +return 0 ; + }return -ENODEV ; }
include/linux/of_net.h +5 -2
@@ -6,15 +6,18 @@#ifndef __LINUX_OF_NET_H#define __LINUX_OF_NET_H +#include <linux/phy.h> +#ifdef CONFIG_OF_NET #include <linux/of.h> struct net_device ; -extern int of_get_phy_mode (struct device_node *np); +extern int of_get_phy_mode (struct device_node *np,phy_interface_t *interface);extern const void *of_get_mac_address (struct device_node *np);extern struct net_device *of_find_net_device_by_node (struct device_node *np);#else -static inline int of_get_phy_mode (struct device_node *np) +static inline int of_get_phy_mode (struct device_node *np, +phy_interface_t *interface) {return -ENODEV ; }
include/linux/stmmac.h +2 -1
@@ -13,6 +13,7 @@#define __STMMAC_PLATFORM_DATA#include <linux/platform_device.h> +#include <linux/phy.h> #define MTL_MAX_RX_QUEUES 8#define MTL_MAX_TX_QUEUES 8
@@ -132,7 +133,7 @@ struct plat_stmmacenet_data {int bus_id;int phy_addr;int interface; -int phy_interface; +phy_interface_t phy_interface;struct stmmac_mdio_bus_data *mdio_bus_data;struct device_node *phy_node;struct device_node *phylink_node;
include/linux/sxgbe_platform.h +3 -1
@@ -10,6 +10,8 @@#ifndef __SXGBE_PLATFORM_H__#define __SXGBE_PLATFORM_H__ +#include <linux/phy.h> +/* MDC Clock Selection define*/ #define SXGBE_CSR_100_150M 0x0/* MDC = clk_scr_i/62 */ #define SXGBE_CSR_150_250M 0x1/* MDC = clk_scr_i/102 */
@@ -38,7 +40,7 @@ struct sxgbe_plat_data {char *phy_bus_name;int bus_id;int phy_addr; -int interface; +phy_interface_t interface;struct sxgbe_mdio_bus_data *mdio_bus_data;struct sxgbe_dma_cfg *dma_cfg;int clk_csr;
net/dsa/port.c +7 -6
@@ -561,7 +561,7 @@ static int dsa_port_fixed_link_register_of(struct dsa_port *dp)struct dsa_switch *ds = dp->ds;struct phy_device *phydev;int port = dp->index; -int mode; +phy_interface_t mode;int err; err =of_phy_register_fixed_link (dn);
@@ -574,8 +574,8 @@ static int dsa_port_fixed_link_register_of(struct dsa_port *dp) phydev =of_phy_find_device (dn); - mode =of_get_phy_mode (dn); -if (mode <0 ) + err =of_get_phy_mode (dn, &mode); +if (err) mode =PHY_INTERFACE_MODE_NA ; phydev->interface = mode;
@@ -593,10 +593,11 @@ static int dsa_port_phylink_register(struct dsa_port *dp) {struct dsa_switch *ds = dp->ds;struct device_node *port_dn = dp->dn; -int mode, err; +phy_interface_t mode; +int err; - mode =of_get_phy_mode (port_dn); -if (mode <0 ) + err =of_get_phy_mode (port_dn, &mode); +if (err) mode =PHY_INTERFACE_MODE_NA ; dp->pl_config.dev = ds->dev;
net/dsa/slave.c +4 -3
@@ -1295,11 +1295,12 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)struct dsa_port *dp =dsa_slave_to_port (slave_dev);struct device_node *port_dn = dp->dn;struct dsa_switch *ds = dp->ds; +phy_interface_t mode;u32 phy_flags =0 ; -int mode, ret; +int ret; - mode =of_get_phy_mode (port_dn); -if (mode <0 ) + ret =of_get_phy_mode (port_dn, &mode); +if (ret) mode =PHY_INTERFACE_MODE_NA ; dp->pl_config.dev = &slave_dev->dev;
Signature · 1 line
2.24.0.rc0
David Miller
maintainerFrom: Andrew Lunn <[email protected]>
Date: Tue, 22 Oct 2019 03:18:17 +0200
Quoted 6 lines
Before this change
of_get_phy_mode()returned an enum,phy_interface_t. On error,-ENODEVetc, is returned. If the result of the function is stored in a variable of typephy_interface_t, and the compiler has decided to represent this as an unsigned int, comparision with-ENODEVetc, is a signed vs unsigned comparision.
Quoted 6 lines
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.Reported-by Dan Carpenter <[email protected]>Signed-off-by Andrew Lunn <[email protected]>
So now we have code that uses the 'interface' value without checking the error return value which means it's potentially uninitialized.
There are also a bunch of reverse christmas tree violations created by this patch as well :-) :-) :-)
Andrew Lunn
maintainerQuoted 13 lines · David Miller
From: Andrew Lunn <[email protected]>
Date: Tue, 22 Oct 2019 03:18:17 +0200Quoted 10 lines
Before this change
of_get_phy_mode()returned an enum,phy_interface_t. On error,-ENODEVetc, is returned. If the result of the function is stored in a variable of typephy_interface_t, and the compiler has decided to represent this as an unsigned int, comparision with-ENODEVetc, 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.
Quoted 5 lines
Quoted 2 lines
Reported-by Dan Carpenter <[email protected]>Signed-off-by Andrew Lunn <[email protected]>So now we have code that uses the 'interface' value without checking the error return value which means it's potentially uninitialized.
Hi David
If it did not check before, it was passing -ENODEV to something. So it was already broken. But an uninitialized value is worse. I can see about adding error checking where there are none.
Quoted 2 lines
There are also a bunch of reverse christmas tree violations created by this patch as well :-) :-) :-)
I tried to avoid that, but a lot of drivers are not reverse christmas to start with. In which case i tried to not break it any more. But i can review my changes.
Andrew
David Miller
maintainerFrom: Andrew Lunn <[email protected]>
Date: Thu, 24 Oct 2019 04:49:35 +0200
Quoted 3 lines
I tried to avoid that, but a lot of drivers are not reverse christmas to start with. In which case i tried to not break it any more. But i can review my changes.
Please give it a shot, thank you.
I guess I can live with the cases that don't cheeck for errors now remaining that way.
Quoted 17 lines · Andrew Lunn
Quoted 16 lines · David Miller
From: Andrew Lunn <[email protected]>
Date: Tue, 22 Oct 2019 03:18:17 +0200Quoted 12 lines
Before this change
of_get_phy_mode()returned an enum,phy_interface_t. On error,-ENODEVetc, is returned. If the result of the function is stored in a variable of typephy_interface_t, and the compiler has decided to represent this as an unsigned int, comparision with-ENODEVetc, 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.Reported-by Dan Carpenter <[email protected]>Signed-off-by Andrew Lunn <[email protected]>
Quoted 9 lines
Quoted 2 lines
So now we have code that uses the 'interface' value without checking the error return value which means it's potentially uninitialized.
Hi David
If it did not check before, it was passing
-ENODEVto something. So it was already broken. But an uninitialized value is worse. I can see about adding error checking where there are none.
We could make it __must_check. We don't use that annotation much outside of core functions, but I don't see a downside to it. Smatch and 0day bot will hopefully catch most of the uninitialized variables as is.
regards,
dan carpenter