]> www.infradead.org Git - users/hch/misc.git/commitdiff
media: adv7180: Move state mutex handling outside init_device()
authorNiklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Thu, 28 Aug 2025 16:06:46 +0000 (18:06 +0200)
committerHans Verkuil <hverkuil+cisco@kernel.org>
Thu, 4 Sep 2025 08:06:13 +0000 (10:06 +0200)
Future rework to get rid of .s_power requires the state mutex to be
held for multiple operations where initializing the device is one of
them.

Move lock handling outside init_device() but enforce the lock is held
with a lockdep_assert_held().

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
drivers/media/i2c/adv7180.c

index b7f175650bd089aa6a73533aabe0d6be32c5f497..9dbd33c4a30c086dbe7f2a781bd83846f63a6232 100644 (file)
@@ -880,7 +880,7 @@ static int init_device(struct adv7180_state *state)
 {
        int ret;
 
-       mutex_lock(&state->mutex);
+       lockdep_assert_held(&state->mutex);
 
        adv7180_set_power_pin(state, true);
        adv7180_set_reset_pin(state, false);
@@ -890,11 +890,11 @@ static int init_device(struct adv7180_state *state)
 
        ret = state->chip_info->init(state);
        if (ret)
-               goto out_unlock;
+               return ret;
 
        ret = adv7180_program_std(state);
        if (ret)
-               goto out_unlock;
+               return ret;
 
        adv7180_set_field_mode(state);
 
@@ -905,31 +905,28 @@ static int init_device(struct adv7180_state *state)
                                    ADV7180_ICONF1_ACTIVE_LOW |
                                    ADV7180_ICONF1_PSYNC_ONLY);
                if (ret < 0)
-                       goto out_unlock;
+                       return ret;
 
                ret = adv7180_write(state, ADV7180_REG_IMR1, 0);
                if (ret < 0)
-                       goto out_unlock;
+                       return ret;
 
                ret = adv7180_write(state, ADV7180_REG_IMR2, 0);
                if (ret < 0)
-                       goto out_unlock;
+                       return ret;
 
                /* enable AD change interrupts */
                ret = adv7180_write(state, ADV7180_REG_IMR3,
                                    ADV7180_IRQ3_AD_CHANGE);
                if (ret < 0)
-                       goto out_unlock;
+                       return ret;
 
                ret = adv7180_write(state, ADV7180_REG_IMR4, 0);
                if (ret < 0)
-                       goto out_unlock;
+                       return ret;
        }
 
-out_unlock:
-       mutex_unlock(&state->mutex);
-
-       return ret;
+       return 0;
 }
 
 static int adv7180_s_stream(struct v4l2_subdev *sd, int enable)
@@ -1479,7 +1476,9 @@ static int adv7180_probe(struct i2c_client *client)
        if (ret)
                goto err_free_ctrl;
 
+       mutex_lock(&state->mutex);
        ret = init_device(state);
+       mutex_unlock(&state->mutex);
        if (ret)
                goto err_media_entity_cleanup;
 
@@ -1562,6 +1561,8 @@ static int adv7180_resume(struct device *dev)
        struct adv7180_state *state = to_state(sd);
        int ret;
 
+       guard(mutex)(&state->mutex);
+
        ret = init_device(state);
        if (ret < 0)
                return ret;