All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] dpaa2-eth: small cleanup
@ 2022-01-06 13:59 Ioana Ciornei
  2022-01-06 13:59 ` [PATCH net-next 1/3] dpaa2-mac: bail if the dpmacs fwnode is not found Ioana Ciornei
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ioana Ciornei @ 2022-01-06 13:59 UTC (permalink / raw)
  To: davem, kuba; +Cc: netdev, robert-ionut.alexa, Ioana Ciornei

These 3 patches are just part of a small cleanup on the dpaa2-eth and
the dpaa2-switch drivers.

In case we are hitting a case in which the fwnode of the root dprc
device we initiate a deferred probe. On the dpaa2-switch side, if we are
on the remove path, make sure that we check for a non-NULL pointer
before accessing the port private structure.

Ioana Ciornei (2):
  dpaa2-mac: return -EPROBE_DEFER from dpaa2_mac_open in case the fwnode
    is not set
  dpaa2-switch: check if the port priv is valid

Robert-Ionut Alexa (1):
  dpaa2-mac: bail if the dpmacs fwnode is not found

 .../net/ethernet/freescale/dpaa2/dpaa2-mac.c  | 20 +++++++++++++++++--
 .../ethernet/freescale/dpaa2/dpaa2-switch.c   |  9 ++++++---
 2 files changed, 24 insertions(+), 5 deletions(-)

-- 
2.33.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next 1/3] dpaa2-mac: bail if the dpmacs fwnode is not found
  2022-01-06 13:59 [PATCH net-next 0/3] dpaa2-eth: small cleanup Ioana Ciornei
@ 2022-01-06 13:59 ` Ioana Ciornei
  2022-01-06 13:59 ` [PATCH net-next 2/3] dpaa2-mac: return -EPROBE_DEFER from dpaa2_mac_open in case the fwnode is not set Ioana Ciornei
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ioana Ciornei @ 2022-01-06 13:59 UTC (permalink / raw)
  To: davem, kuba; +Cc: netdev, robert-ionut.alexa

From: Robert-Ionut Alexa <robert-ionut.alexa@nxp.com>

The parent pointer node handler must be declared with a NULL
initializer. Before using it, a check must be performed to make
sure that a valid address has been assigned to it.

Signed-off-by: Robert-Ionut Alexa <robert-ionut.alexa@nxp.com>
---
 drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
index 7f509f427e3d..e80376c6e55e 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
@@ -41,7 +41,7 @@ static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode)
 static struct fwnode_handle *dpaa2_mac_get_node(struct device *dev,
 						u16 dpmac_id)
 {
-	struct fwnode_handle *fwnode, *parent, *child  = NULL;
+	struct fwnode_handle *fwnode, *parent = NULL, *child  = NULL;
 	struct device_node *dpmacs = NULL;
 	int err;
 	u32 id;
@@ -56,6 +56,9 @@ static struct fwnode_handle *dpaa2_mac_get_node(struct device *dev,
 		parent = fwnode;
 	}
 
+	if (!parent)
+		return NULL;
+
 	fwnode_for_each_child_node(parent, child) {
 		err = -EINVAL;
 		if (is_acpi_device_node(child))
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net-next 2/3] dpaa2-mac: return -EPROBE_DEFER from dpaa2_mac_open in case the fwnode is not set
  2022-01-06 13:59 [PATCH net-next 0/3] dpaa2-eth: small cleanup Ioana Ciornei
  2022-01-06 13:59 ` [PATCH net-next 1/3] dpaa2-mac: bail if the dpmacs fwnode is not found Ioana Ciornei
@ 2022-01-06 13:59 ` Ioana Ciornei
  2022-01-06 13:59 ` [PATCH net-next 3/3] dpaa2-switch: check if the port priv is valid Ioana Ciornei
  2022-01-07  4:10 ` [PATCH net-next 0/3] dpaa2-eth: small cleanup patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Ioana Ciornei @ 2022-01-06 13:59 UTC (permalink / raw)
  To: davem, kuba; +Cc: netdev, robert-ionut.alexa, Ioana Ciornei

We could get into a situation when the fwnode of the parent device is
not yet set because its probe didn't yet finish. When this happens, any
caller of the dpaa2_mac_open() will not have the fwnode available, thus
cause problems at the PHY connect time.

Avoid this by just returning -EPROBE_DEFER from the dpaa2_mac_open when
this happens.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
 drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
index e80376c6e55e..623d113b6581 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
@@ -54,6 +54,12 @@ static struct fwnode_handle *dpaa2_mac_get_node(struct device *dev,
 		parent = of_fwnode_handle(dpmacs);
 	} else if (is_acpi_node(fwnode)) {
 		parent = fwnode;
+	} else {
+		/* The root dprc device didn't yet get to finalize it's probe,
+		 * thus the fwnode field is not yet set. Defer probe if we are
+		 * facing this situation.
+		 */
+		return ERR_PTR(-EPROBE_DEFER);
 	}
 
 	if (!parent)
@@ -330,6 +336,7 @@ int dpaa2_mac_open(struct dpaa2_mac *mac)
 {
 	struct fsl_mc_device *dpmac_dev = mac->mc_dev;
 	struct net_device *net_dev = mac->net_dev;
+	struct fwnode_handle *fw_node;
 	int err;
 
 	err = dpmac_open(mac->mc_io, 0, dpmac_dev->obj_desc.id,
@@ -349,7 +356,13 @@ int dpaa2_mac_open(struct dpaa2_mac *mac)
 	/* Find the device node representing the MAC device and link the device
 	 * behind the associated netdev to it.
 	 */
-	mac->fw_node = dpaa2_mac_get_node(&mac->mc_dev->dev, mac->attr.id);
+	fw_node = dpaa2_mac_get_node(&mac->mc_dev->dev, mac->attr.id);
+	if (IS_ERR(fw_node)) {
+		err = PTR_ERR(fw_node);
+		goto err_close_dpmac;
+	}
+
+	mac->fw_node = fw_node;
 	net_dev->dev.of_node = to_of_node(mac->fw_node);
 
 	return 0;
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net-next 3/3] dpaa2-switch: check if the port priv is valid
  2022-01-06 13:59 [PATCH net-next 0/3] dpaa2-eth: small cleanup Ioana Ciornei
  2022-01-06 13:59 ` [PATCH net-next 1/3] dpaa2-mac: bail if the dpmacs fwnode is not found Ioana Ciornei
  2022-01-06 13:59 ` [PATCH net-next 2/3] dpaa2-mac: return -EPROBE_DEFER from dpaa2_mac_open in case the fwnode is not set Ioana Ciornei
@ 2022-01-06 13:59 ` Ioana Ciornei
  2022-01-07  4:10 ` [PATCH net-next 0/3] dpaa2-eth: small cleanup patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Ioana Ciornei @ 2022-01-06 13:59 UTC (permalink / raw)
  To: davem, kuba; +Cc: netdev, robert-ionut.alexa, Ioana Ciornei

Before accessing the port private structure make sure that there is
still a non-NULL pointer there. A NULL pointer access can happen when we
are on the remove path, some switch ports are unregistered and some are
in the process of unregistering.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
 drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
index d039457928b0..9b5512b4f15d 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
@@ -394,7 +394,8 @@ static int dpaa2_switch_dellink(struct ethsw_core *ethsw, u16 vid)
 
 	for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
 		ppriv_local = ethsw->ports[i];
-		ppriv_local->vlans[vid] = 0;
+		if (ppriv_local)
+			ppriv_local->vlans[vid] = 0;
 	}
 
 	return 0;
@@ -1896,9 +1897,11 @@ static int dpaa2_switch_port_del_vlan(struct ethsw_port_priv *port_priv, u16 vid
 		/* Delete VLAN from switch if it is no longer configured on
 		 * any port
 		 */
-		for (i = 0; i < ethsw->sw_attr.num_ifs; i++)
-			if (ethsw->ports[i]->vlans[vid] & ETHSW_VLAN_MEMBER)
+		for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
+			if (ethsw->ports[i] &&
+			    ethsw->ports[i]->vlans[vid] & ETHSW_VLAN_MEMBER)
 				return 0; /* Found a port member in VID */
+		}
 
 		ethsw->vlans[vid] &= ~ETHSW_VLAN_GLOBAL;
 
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next 0/3] dpaa2-eth: small cleanup
  2022-01-06 13:59 [PATCH net-next 0/3] dpaa2-eth: small cleanup Ioana Ciornei
                   ` (2 preceding siblings ...)
  2022-01-06 13:59 ` [PATCH net-next 3/3] dpaa2-switch: check if the port priv is valid Ioana Ciornei
@ 2022-01-07  4:10 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-01-07  4:10 UTC (permalink / raw)
  To: Ioana Ciornei; +Cc: davem, kuba, netdev, robert-ionut.alexa

Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Thu,  6 Jan 2022 15:59:02 +0200 you wrote:
> These 3 patches are just part of a small cleanup on the dpaa2-eth and
> the dpaa2-switch drivers.
> 
> In case we are hitting a case in which the fwnode of the root dprc
> device we initiate a deferred probe. On the dpaa2-switch side, if we are
> on the remove path, make sure that we check for a non-NULL pointer
> before accessing the port private structure.
> 
> [...]

Here is the summary with links:
  - [net-next,1/3] dpaa2-mac: bail if the dpmacs fwnode is not found
    https://git.kernel.org/netdev/net-next/c/5b1e38c0792c
  - [net-next,2/3] dpaa2-mac: return -EPROBE_DEFER from dpaa2_mac_open in case the fwnode is not set
    https://git.kernel.org/netdev/net-next/c/4e30e98c4b4c
  - [net-next,3/3] dpaa2-switch: check if the port priv is valid
    https://git.kernel.org/netdev/net-next/c/d1a9b84183e8

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-01-07  4:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06 13:59 [PATCH net-next 0/3] dpaa2-eth: small cleanup Ioana Ciornei
2022-01-06 13:59 ` [PATCH net-next 1/3] dpaa2-mac: bail if the dpmacs fwnode is not found Ioana Ciornei
2022-01-06 13:59 ` [PATCH net-next 2/3] dpaa2-mac: return -EPROBE_DEFER from dpaa2_mac_open in case the fwnode is not set Ioana Ciornei
2022-01-06 13:59 ` [PATCH net-next 3/3] dpaa2-switch: check if the port priv is valid Ioana Ciornei
2022-01-07  4:10 ` [PATCH net-next 0/3] dpaa2-eth: small cleanup patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.