[PATCHv6 net-next 5/7] net: ibm: emac: use devm for mutex_init

Rosen Penev posted 7 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCHv6 net-next 5/7] net: ibm: emac: use devm for mutex_init
Posted by Rosen Penev 1 month, 2 weeks ago
It seems since inception that mutex_destroy was never called for these
in _remove. Instead of handling this manually, just use devm for
simplicity.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/net/ethernet/ibm/emac/core.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index f8478f0026af..b9ccaae61c48 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -3021,8 +3021,14 @@ static int emac_probe(struct platform_device *ofdev)
 	SET_NETDEV_DEV(ndev, &ofdev->dev);
 
 	/* Initialize some embedded data structures */
-	mutex_init(&dev->mdio_lock);
-	mutex_init(&dev->link_lock);
+	err = devm_mutex_init(&ofdev->dev, &dev->mdio_lock);
+	if (err)
+		return err;
+
+	err = devm_mutex_init(&ofdev->dev, &dev->link_lock);
+	if (err)
+		return err;
+
 	spin_lock_init(&dev->lock);
 	INIT_WORK(&dev->reset_work, emac_reset_work);
 
-- 
2.47.0
Re: [PATCHv6 net-next 5/7] net: ibm: emac: use devm for mutex_init
Posted by Simon Horman 1 month, 2 weeks ago
On Fri, Oct 11, 2024 at 12:56:20PM -0700, Rosen Penev wrote:
> It seems since inception that mutex_destroy was never called for these
> in _remove. Instead of handling this manually, just use devm for
> simplicity.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/net/ethernet/ibm/emac/core.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
> index f8478f0026af..b9ccaae61c48 100644
> --- a/drivers/net/ethernet/ibm/emac/core.c
> +++ b/drivers/net/ethernet/ibm/emac/core.c
> @@ -3021,8 +3021,14 @@ static int emac_probe(struct platform_device *ofdev)
>  	SET_NETDEV_DEV(ndev, &ofdev->dev);
>  
>  	/* Initialize some embedded data structures */
> -	mutex_init(&dev->mdio_lock);
> -	mutex_init(&dev->link_lock);
> +	err = devm_mutex_init(&ofdev->dev, &dev->mdio_lock);
> +	if (err)
> +		return err;

Hi Rosen,

It looks like this should be:

		goto err_gone;

> +
> +	err = devm_mutex_init(&ofdev->dev, &dev->link_lock);
> +	if (err)
> +		return err;

Ditto.

> +
>  	spin_lock_init(&dev->lock);
>  	INIT_WORK(&dev->reset_work, emac_reset_work);

-- 
pw-bot: cr