Use devm_mutex_init() to simplify the code. No functional change.
Signed-off-by: Guoniu Zhou <guoniu.zhou@nxp.com>
---
drivers/media/i2c/ds90ub953.c | 33 +++++++++++++--------------------
1 file changed, 13 insertions(+), 20 deletions(-)
diff --git a/drivers/media/i2c/ds90ub953.c b/drivers/media/i2c/ds90ub953.c
index c6b77e4982a3449896e564a288ff1562cb1dcb79..47e7c0a5aae7737182e6a1f2797be01e7ecc8142 100644
--- a/drivers/media/i2c/ds90ub953.c
+++ b/drivers/media/i2c/ds90ub953.c
@@ -1342,7 +1342,9 @@ static int ub953_probe(struct i2c_client *client)
if (!priv->plat_data)
return dev_err_probe(dev, -ENODEV, "Platform data missing\n");
- mutex_init(&priv->reg_lock);
+ ret = devm_mutex_init(dev, &priv->reg_lock);
+ if (ret)
+ return ret;
/*
* Initialize to invalid values so that the first reg writes will
@@ -1351,32 +1353,26 @@ static int ub953_probe(struct i2c_client *client)
priv->current_indirect_target = 0xff;
priv->regmap = devm_regmap_init_i2c(client, &ub953_regmap_config);
- if (IS_ERR(priv->regmap)) {
- ret = PTR_ERR(priv->regmap);
- dev_err_probe(dev, ret, "Failed to init regmap\n");
- goto err_mutex_destroy;
- }
+ if (IS_ERR(priv->regmap))
+ return dev_err_probe(dev, PTR_ERR(priv->regmap),
+ "Failed to init regmap\n");
priv->clkin = devm_clk_get_optional(dev, "clkin");
- if (IS_ERR(priv->clkin)) {
- ret = PTR_ERR(priv->clkin);
- dev_err_probe(dev, ret, "failed to parse 'clkin'\n");
- goto err_mutex_destroy;
- }
+ if (IS_ERR(priv->clkin))
+ return dev_err_probe(dev, PTR_ERR(priv->clkin),
+ "Failed to parse 'clkin'\n");
ret = ub953_parse_dt(priv);
if (ret)
- goto err_mutex_destroy;
+ return ret;
ret = ub953_hw_init(priv);
if (ret)
- goto err_mutex_destroy;
+ return ret;
ret = ub953_gpiochip_probe(priv);
- if (ret) {
- dev_err_probe(dev, ret, "Failed to init gpiochip\n");
- goto err_mutex_destroy;
- }
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to init gpiochip\n");
ret = ub953_register_clkout(priv);
if (ret) {
@@ -1400,8 +1396,6 @@ static int ub953_probe(struct i2c_client *client)
ub953_subdev_uninit(priv);
err_gpiochip_remove:
ub953_gpiochip_remove(priv);
-err_mutex_destroy:
- mutex_destroy(&priv->reg_lock);
return ret;
}
@@ -1416,7 +1410,6 @@ static void ub953_remove(struct i2c_client *client)
ub953_subdev_uninit(priv);
ub953_gpiochip_remove(priv);
- mutex_destroy(&priv->reg_lock);
}
static const struct ub953_hw_data ds90ub953_hw = {
--
2.34.1
On Tue, Sep 16, 2025 at 05:43:45PM +0800, Guoniu Zhou wrote: > Use devm_mutex_init() to simplify the code. No functional change. Use devm_mutex_init() and dev_err_probe() to ... Reviewed-by: Frank Li <Frank.Li@nxp.com> Frank > > Signed-off-by: Guoniu Zhou <guoniu.zhou@nxp.com> > --- > drivers/media/i2c/ds90ub953.c | 33 +++++++++++++-------------------- > 1 file changed, 13 insertions(+), 20 deletions(-) > > diff --git a/drivers/media/i2c/ds90ub953.c b/drivers/media/i2c/ds90ub953.c > index c6b77e4982a3449896e564a288ff1562cb1dcb79..47e7c0a5aae7737182e6a1f2797be01e7ecc8142 100644 > --- a/drivers/media/i2c/ds90ub953.c > +++ b/drivers/media/i2c/ds90ub953.c > @@ -1342,7 +1342,9 @@ static int ub953_probe(struct i2c_client *client) > if (!priv->plat_data) > return dev_err_probe(dev, -ENODEV, "Platform data missing\n"); > > - mutex_init(&priv->reg_lock); > + ret = devm_mutex_init(dev, &priv->reg_lock); > + if (ret) > + return ret; > > /* > * Initialize to invalid values so that the first reg writes will > @@ -1351,32 +1353,26 @@ static int ub953_probe(struct i2c_client *client) > priv->current_indirect_target = 0xff; > > priv->regmap = devm_regmap_init_i2c(client, &ub953_regmap_config); > - if (IS_ERR(priv->regmap)) { > - ret = PTR_ERR(priv->regmap); > - dev_err_probe(dev, ret, "Failed to init regmap\n"); > - goto err_mutex_destroy; > - } > + if (IS_ERR(priv->regmap)) > + return dev_err_probe(dev, PTR_ERR(priv->regmap), > + "Failed to init regmap\n"); > > priv->clkin = devm_clk_get_optional(dev, "clkin"); > - if (IS_ERR(priv->clkin)) { > - ret = PTR_ERR(priv->clkin); > - dev_err_probe(dev, ret, "failed to parse 'clkin'\n"); > - goto err_mutex_destroy; > - } > + if (IS_ERR(priv->clkin)) > + return dev_err_probe(dev, PTR_ERR(priv->clkin), > + "Failed to parse 'clkin'\n"); > > ret = ub953_parse_dt(priv); > if (ret) > - goto err_mutex_destroy; > + return ret; > > ret = ub953_hw_init(priv); > if (ret) > - goto err_mutex_destroy; > + return ret; > > ret = ub953_gpiochip_probe(priv); > - if (ret) { > - dev_err_probe(dev, ret, "Failed to init gpiochip\n"); > - goto err_mutex_destroy; > - } > + if (ret) > + return dev_err_probe(dev, ret, "Failed to init gpiochip\n"); > > ret = ub953_register_clkout(priv); > if (ret) { > @@ -1400,8 +1396,6 @@ static int ub953_probe(struct i2c_client *client) > ub953_subdev_uninit(priv); > err_gpiochip_remove: > ub953_gpiochip_remove(priv); > -err_mutex_destroy: > - mutex_destroy(&priv->reg_lock); > > return ret; > } > @@ -1416,7 +1410,6 @@ static void ub953_remove(struct i2c_client *client) > ub953_subdev_uninit(priv); > > ub953_gpiochip_remove(priv); > - mutex_destroy(&priv->reg_lock); > } > > static const struct ub953_hw_data ds90ub953_hw = { > > -- > 2.34.1 >
© 2016 - 2025 Red Hat, Inc.