net: dsa: Use devm_ prefixed allocations
Subsystems (3)
PATCH 1/3 net: dsa: Use devm_ prefixed allocations
To simplify and prevent memory leakage when unbinding, use the devm_ memory allocation calls.
--- net/dsa/dsa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/dsa/dsa.c +3 -3
@@ -305,7 +305,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)if (ret <0 ) goto out; - ds->slave_mii_bus =mdiobus_alloc (); + ds->slave_mii_bus =devm_mdiobus_alloc (parent);if (ds->slave_mii_bus ==NULL ) { ret = -ENOMEM ; goto out;
@@ -400,7 +400,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,/* * Allocate and initialise switch state. */ - ds =kzalloc (sizeof (*ds) + drv->priv_size,GFP_KERNEL ); + ds =devm_kzalloc (parent,sizeof (*ds) + drv->priv_size,GFP_KERNEL );if (ds ==NULL )return ERR_PTR (-ENOMEM );
@@ -883,7 +883,7 @@ static int dsa_probe(struct platform_device *pdev) goto out; } - dst =kzalloc (sizeof (*dst),GFP_KERNEL ); + dst =devm_kzalloc (&pdev->dev,sizeof (*dst),GFP_KERNEL );if (dst ==NULL ) {dev_put (dev); ret = -ENOMEM ;
Signature · 1 line
1.9.1
Quoted 6 lines · Neil Armstrong
To simplify and prevent memory leakage when unbinding, use the
devm_memory allocation calls.Tested-by Andrew Lunn <[email protected]>Tested-by Florian Fainelli <[email protected]>Signed-off-by Neil Armstrong <[email protected]>
I think you also need to get rid of the corresponding free calls in the error path, otherwise it will probably crash at some point.
- Felix
Quoted 34 lines · Neil Armstrong
To simplify and prevent memory leakage when unbinding, use the
devm_memory allocation calls.Tested-by Andrew Lunn <[email protected]>Tested-by Florian Fainelli <[email protected]>Signed-off-by Neil Armstrong <[email protected]>--- net/dsa/dsa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/dsa/dsa.c +2
-2@@ -305,7 +305,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)if (ret <0 ) goto out; - ds->slave_mii_bus =mdiobus_alloc (); + ds->slave_mii_bus =devm_mdiobus_alloc (parent);if (ds->slave_mii_bus ==NULL ) { ret = -ENOMEM ; goto out;@@ -400,7 +400,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,/* * Allocate and initialise switch state. */ - ds =kzalloc (sizeof (*ds) + drv->priv_size,GFP_KERNEL ); + ds =devm_kzalloc (parent,sizeof (*ds) + drv->priv_size,GFP_KERNEL );if (ds ==NULL )return ERR_PTR (-ENOMEM );
net/dsa/dsa.c static int dsa_probe(struct platform_device *pdev) · line 889
Quoted 8 lines
net/dsa/dsa.c +1
-1@@ -883,7 +883,7 @@ static int dsa_probe(struct platform_device *pdev) goto out; } - dst =kzalloc (sizeof (*dst),GFP_KERNEL ); + dst =devm_kzalloc (&pdev->dev,sizeof (*dst),GFP_KERNEL );if (dst ==NULL ) {dev_put (dev); ret = -ENOMEM ;
Shouldn't you remove the correspoding kfree(), etc. calls?
MBR, Sergei
Quoted 47 lines · Sergei Shtylyov
Quoted 34 lines · Neil Armstrong
To simplify and prevent memory leakage when unbinding, use the
devm_memory allocation calls.Tested-by Andrew Lunn <[email protected]>Tested-by Florian Fainelli <[email protected]>Signed-off-by Neil Armstrong <[email protected]>--- net/dsa/dsa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/dsa/dsa.c +2
-2@@ -305,7 +305,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)if (ret <0 ) goto out; - ds->slave_mii_bus =mdiobus_alloc (); + ds->slave_mii_bus =devm_mdiobus_alloc (parent);if (ds->slave_mii_bus ==NULL ) { ret = -ENOMEM ; goto out;@@ -400,7 +400,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,/* * Allocate and initialise switch state. */ - ds =kzalloc (sizeof (*ds) + drv->priv_size,GFP_KERNEL ); + ds =devm_kzalloc (parent,sizeof (*ds) + drv->priv_size,GFP_KERNEL );if (ds ==NULL )return ERR_PTR (-ENOMEM );net/dsa/dsa.c static int dsa_probe(struct platform_device *pdev) · line 889
Quoted 8 lines
net/dsa/dsa.c +1
-1@@ -883,7 +883,7 @@ static int dsa_probe(struct platform_device *pdev) goto out; } - dst =kzalloc (sizeof (*dst),GFP_KERNEL ); + dst =devm_kzalloc (&pdev->dev,sizeof (*dst),GFP_KERNEL );if (dst ==NULL ) {dev_put (dev); ret = -ENOMEM ;Shouldn't you remove the correspoding
kfree(), etc. calls?
Quoted 2 lines
MBR, Sergei
The corresponding kfree() calls were all missing.
Neil
Quoted 45 lines · Neil Armstrong
Quoted 45 lines
Quoted 34 lines
To simplify and prevent memory leakage when unbinding, use the
devm_memory allocation calls.Tested-by Andrew Lunn <[email protected]>Tested-by Florian Fainelli <[email protected]>Signed-off-by Neil Armstrong <[email protected]>--- net/dsa/dsa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/dsa/dsa.c +2
-2@@ -305,7 +305,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)if (ret <0 ) goto out; - ds->slave_mii_bus =mdiobus_alloc (); + ds->slave_mii_bus =devm_mdiobus_alloc (parent);if (ds->slave_mii_bus ==NULL ) { ret = -ENOMEM ; goto out;@@ -400,7 +400,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,/* * Allocate and initialise switch state. */ - ds =kzalloc (sizeof (*ds) + drv->priv_size,GFP_KERNEL ); + ds =devm_kzalloc (parent,sizeof (*ds) + drv->priv_size,GFP_KERNEL );if (ds ==NULL )return ERR_PTR (-ENOMEM );net/dsa/dsa.c static int dsa_probe(struct platform_device *pdev) · line 889
Quoted 8 lines
net/dsa/dsa.c +1
-1@@ -883,7 +883,7 @@ static int dsa_probe(struct platform_device *pdev) goto out; } - dst =kzalloc (sizeof (*dst),GFP_KERNEL ); + dst =devm_kzalloc (&pdev->dev,sizeof (*dst),GFP_KERNEL );if (dst ==NULL ) {dev_put (dev); ret = -ENOMEM ;Shouldn't you remove the correspoding
kfree(), etc. calls?
Quoted 3 lines
Quoted 2 lines
MBR, Sergei
The corresponding
kfree()calls were all missing.
Then this patch should be for net, not net-next. Either that, or add thekfree() calls first, then remove them in this net-next patch.
Quoted 1 line
Neil
MBR, Sergei
Quoted 48 lines · Neil Armstrong
Quoted 47 lines · Sergei Shtylyov
Quoted 34 lines · Neil Armstrong
To simplify and prevent memory leakage when unbinding, use the
devm_memory allocation calls.Tested-by Andrew Lunn <[email protected]>Tested-by Florian Fainelli <[email protected]>Signed-off-by Neil Armstrong <[email protected]>--- net/dsa/dsa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/dsa/dsa.c +2
-2@@ -305,7 +305,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)if (ret <0 ) goto out; - ds->slave_mii_bus =mdiobus_alloc (); + ds->slave_mii_bus =devm_mdiobus_alloc (parent);if (ds->slave_mii_bus ==NULL ) { ret = -ENOMEM ; goto out;@@ -400,7 +400,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,/* * Allocate and initialise switch state. */ - ds =kzalloc (sizeof (*ds) + drv->priv_size,GFP_KERNEL ); + ds =devm_kzalloc (parent,sizeof (*ds) + drv->priv_size,GFP_KERNEL );if (ds ==NULL )return ERR_PTR (-ENOMEM );net/dsa/dsa.c static int dsa_probe(struct platform_device *pdev) · line 889
Quoted 8 lines
net/dsa/dsa.c +1
-1@@ -883,7 +883,7 @@ static int dsa_probe(struct platform_device *pdev) goto out; } - dst =kzalloc (sizeof (*dst),GFP_KERNEL ); + dst =devm_kzalloc (&pdev->dev,sizeof (*dst),GFP_KERNEL );if (dst ==NULL ) {dev_put (dev); ret = -ENOMEM ;Shouldn't you remove the correspoding
kfree(), etc. calls?
Quoted 3 lines
Quoted 2 lines
MBR, Sergei
The corresponding
kfree()calls were all missing.
Not in the error handling path. mdiobus_alloc has a corresponding mdiobus_free in the same function.
The ds kzalloc in dsa_switch_setup has a kfree in dsa_switch_setup_one.
- Felix
Quoted 49 lines · Felix Fietkau
Quoted 48 lines · Neil Armstrong
Quoted 47 lines · Sergei Shtylyov
Quoted 34 lines · Neil Armstrong
To simplify and prevent memory leakage when unbinding, use the
devm_memory allocation calls.Tested-by Andrew Lunn <[email protected]>Tested-by Florian Fainelli <[email protected]>Signed-off-by Neil Armstrong <[email protected]>--- net/dsa/dsa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/dsa/dsa.c +2
-2@@ -305,7 +305,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)if (ret <0 ) goto out; - ds->slave_mii_bus =mdiobus_alloc (); + ds->slave_mii_bus =devm_mdiobus_alloc (parent);if (ds->slave_mii_bus ==NULL ) { ret = -ENOMEM ; goto out;@@ -400,7 +400,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,/* * Allocate and initialise switch state. */ - ds =kzalloc (sizeof (*ds) + drv->priv_size,GFP_KERNEL ); + ds =devm_kzalloc (parent,sizeof (*ds) + drv->priv_size,GFP_KERNEL );if (ds ==NULL )return ERR_PTR (-ENOMEM );net/dsa/dsa.c static int dsa_probe(struct platform_device *pdev) · line 889
Quoted 8 lines
net/dsa/dsa.c +1
-1@@ -883,7 +883,7 @@ static int dsa_probe(struct platform_device *pdev) goto out; } - dst =kzalloc (sizeof (*dst),GFP_KERNEL ); + dst =devm_kzalloc (&pdev->dev,sizeof (*dst),GFP_KERNEL );if (dst ==NULL ) {dev_put (dev); ret = -ENOMEM ;Shouldn't you remove the correspoding
kfree(), etc. calls?
Quoted 9 lines
Quoted 3 lines
Quoted 2 lines
MBR, Sergei
The corresponding
kfree()calls were all missing.Not in the error handling path.
mdiobus_allochas a correspondingmdiobus_freein the same function.
The ds kzalloc indsa_switch_setuphas a kfree indsa_switch_setup_one.- Felix
Thanks Felix & Sergei,
I will repost based on net with an intermediate commit adding the missing kfree calls.
Neil