diff mbox series

[3/4] net: dsa: remove NULL check for priv and platform data

Message ID 20210224164042.21747-4-michael@walle.cc
State Accepted
Commit 108157c468eed8291c866415b8708eb2a8735dc4
Delegated to: Priyanka Jain
Headers show
Series net: dsa: various fixes | expand

Commit Message

Michael Walle Feb. 24, 2021, 4:40 p.m. UTC
Because the uclass has the "*_auto" properties set, the driver model
will take care of allocating the private structures for us and they
can't be NULL. Drop the checks.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 net/dsa-uclass.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

Comments

Vladimir Oltean Feb. 24, 2021, 10:23 p.m. UTC | #1
On Wed, Feb 24, 2021 at 05:40:41PM +0100, Michael Walle wrote:
> Because the uclass has the "*_auto" properties set, the driver model
> will take care of allocating the private structures for us and they
> can't be NULL. Drop the checks.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---

Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Ramon Fried Feb. 25, 2021, 7:14 p.m. UTC | #2
On Thu, Feb 25, 2021 at 12:23 AM Vladimir Oltean <olteanv@gmail.com> wrote:
>
> On Wed, Feb 24, 2021 at 05:40:41PM +0100, Michael Walle wrote:
> > Because the uclass has the "*_auto" properties set, the driver model
> > will take care of allocating the private structures for us and they
> > can't be NULL. Drop the checks.
> >
> > Signed-off-by: Michael Walle <michael@walle.cc>
> > ---
>
> Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-By: Ramon Fried <rfried.dev@gmail.com>
diff mbox series

Patch

diff --git a/net/dsa-uclass.c b/net/dsa-uclass.c
index 7898f30e15..d453cc6930 100644
--- a/net/dsa-uclass.c
+++ b/net/dsa-uclass.c
@@ -28,8 +28,8 @@  int dsa_set_tagging(struct udevice *dev, ushort headroom, ushort tailroom)
 {
 	struct dsa_priv *priv;
 
-	if (!dev || !dev_get_uclass_priv(dev))
-		return -ENODEV;
+	if (!dev)
+		return -EINVAL;
 
 	if (headroom + tailroom > DSA_MAX_OVR)
 		return -EINVAL;
@@ -47,11 +47,13 @@  int dsa_set_tagging(struct udevice *dev, ushort headroom, ushort tailroom)
 /* returns the DSA master Ethernet device */
 struct udevice *dsa_get_master(struct udevice *dev)
 {
-	struct dsa_priv *priv = dev_get_uclass_priv(dev);
+	struct dsa_priv *priv;
 
-	if (!priv)
+	if (!dev)
 		return NULL;
 
+	priv = dev_get_uclass_priv(dev);
+
 	return priv->master_dev;
 }
 
@@ -67,9 +69,6 @@  static int dsa_port_start(struct udevice *pdev)
 	struct dsa_ops *ops = dsa_get_ops(dev);
 	int err;
 
-	if (!priv)
-		return -ENODEV;
-
 	if (!master) {
 		dev_err(pdev, "DSA master Ethernet device not found!\n");
 		return -EINVAL;
@@ -101,9 +100,6 @@  static void dsa_port_stop(struct udevice *pdev)
 	struct udevice *master = dsa_get_master(dev);
 	struct dsa_ops *ops = dsa_get_ops(dev);
 
-	if (!priv)
-		return;
-
 	if (ops->port_disable) {
 		struct dsa_port_pdata *port_pdata;
 
@@ -347,7 +343,7 @@  static int dsa_post_bind(struct udevice *dev)
 	ofnode node = dev_ofnode(dev), pnode;
 	int i, err, first_err = 0;
 
-	if (!pdata || !ofnode_valid(node))
+	if (!ofnode_valid(node))
 		return -ENODEV;
 
 	pdata->master_node = ofnode_null();
@@ -459,9 +455,6 @@  static int dsa_pre_probe(struct udevice *dev)
 	struct dsa_pdata *pdata = dev_get_uclass_plat(dev);
 	struct dsa_priv *priv = dev_get_uclass_priv(dev);
 
-	if (!pdata || !priv)
-		return -ENODEV;
-
 	priv->num_ports = pdata->num_ports;
 	priv->cpu_port = pdata->cpu_port;
 	priv->cpu_port_fixed_phy = fixed_phy_create(pdata->cpu_port_node);