lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5d6fbe99-e281-4ae1-b2b6-37cab726143c@windriver.com>
Date: Thu, 1 Jan 2026 10:03:28 +0800
From: xiaolei wang <xiaolei.wang@...driver.com>
To: Tarang Raval <tarang.raval@...iconsignals.io>,
        "laurent.pinchart@...asonboard.com" <laurent.pinchart@...asonboard.com>,
        "sakari.ailus@...ux.intel.com" <sakari.ailus@...ux.intel.com>,
        "dave.stevenson@...pberrypi.com" <dave.stevenson@...pberrypi.com>,
        "jacopo@...ndi.org" <jacopo@...ndi.org>,
        "mchehab@...nel.org" <mchehab@...nel.org>,
        "prabhakar.mahadev-lad.rj@...renesas.com"
 <prabhakar.mahadev-lad.rj@...renesas.com>,
        "hverkuil+cisco@...nel.org" <hverkuil+cisco@...nel.org>,
        "johannes.goede@....qualcomm.com" <johannes.goede@....qualcomm.com>,
        "hverkuil-cisco@...all.nl" <hverkuil-cisco@...all.nl>,
        "jai.luthra@...asonboard.com" <jai.luthra@...asonboard.com>
Cc: "linux-media@...r.kernel.org" <linux-media@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3 2/3] media: i2c: ov5647: Switch to using the sub-device
 state lock


On 12/31/25 18:54, Tarang Raval wrote:
> CAUTION: This email comes from a non Wind River email account!
> Do not click links or open attachments unless you recognize the sender and know the content is safe.
>
> Hi Xiaolei,
>
>> Switch to using the sub-device state lock and properly call
>> v4l2_subdev_init_finalize() / v4l2_subdev_cleanup() on probe() /
>> remove().
>>   
>> Signed-off-by: Xiaolei Wang <xiaolei.wang@...driver.com>
>> ---
>>   drivers/media/i2c/ov5647.c | 37 ++++++++++++++++---------------------
>>   1 file changed, 16 insertions(+), 21 deletions(-)
>>   
>> diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
>> index cbcb760ba5cd..bc81f378436a 100644
>> --- a/drivers/media/i2c/ov5647.c
>> +++ b/drivers/media/i2c/ov5647.c
>> @@ -92,7 +92,6 @@ struct ov5647 {
>>          struct v4l2_subdev              sd;
>>          struct regmap                   *regmap;
>>          struct media_pad                pad;
>> -       struct mutex                    lock;
>>          struct clk                      *xclk;
>>          struct gpio_desc                *pwdn;
>>          bool                            clock_ncont;
>> @@ -807,10 +806,10 @@ __ov5647_get_pad_crop(struct ov5647 *ov5647,
>>   static int ov5647_s_stream(struct v4l2_subdev *sd, int enable)
>>   {
>>          struct i2c_client *client = v4l2_get_subdevdata(sd);
>> -       struct ov5647 *sensor = to_sensor(sd);
>> +       struct v4l2_subdev_state *state;
>>          int ret;
>>   
>> -       mutex_lock(&sensor->lock);
>> +       state = v4l2_subdev_lock_and_get_active_state(sd);
>>   
>>          if (enable) {
>>                  ret = pm_runtime_resume_and_get(&client->dev);
>> @@ -831,14 +830,14 @@ static int ov5647_s_stream(struct v4l2_subdev *sd, int enable)
>>                  pm_runtime_put(&client->dev);
>>          }
>>   
>> -       mutex_unlock(&sensor->lock);
>> +       v4l2_subdev_unlock_state(state);
>>   
>>          return 0;
>>   
>>   error_pm:
>>          pm_runtime_put(&client->dev);
>>   error_unlock:
>> -       mutex_unlock(&sensor->lock);
>> +       v4l2_subdev_unlock_state(state);
>>   
>>          return ret;
>>   }
>> @@ -886,7 +885,6 @@ static int ov5647_get_pad_fmt(struct v4l2_subdev *sd,
>>          const struct v4l2_mbus_framefmt *sensor_format;
>>          struct ov5647 *sensor = to_sensor(sd);
>>   
>> -       mutex_lock(&sensor->lock);
>>          switch (format->which) {
>>          case V4L2_SUBDEV_FORMAT_TRY:
>>                  sensor_format = v4l2_subdev_state_get_format(sd_state,
>> @@ -898,7 +896,6 @@ static int ov5647_get_pad_fmt(struct v4l2_subdev *sd,
>>          }
>>   
>>          *fmt = *sensor_format;
>> -       mutex_unlock(&sensor->lock);
>>   
>>          return 0;
>>   }
>> @@ -916,7 +913,6 @@ static int ov5647_set_pad_fmt(struct v4l2_subdev *sd,
>>                                        fmt->width, fmt->height);
>>   
>>          /* Update the sensor mode and apply at it at streamon time. */
>> -       mutex_lock(&sensor->lock);
>>          if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
>>                  *v4l2_subdev_state_get_format(sd_state, format->pad) = mode->format;
>>          } else {
>> @@ -945,7 +941,6 @@ static int ov5647_set_pad_fmt(struct v4l2_subdev *sd,
>>                                           exposure_def);
>>          }
>>          *fmt = mode->format;
>> -       mutex_unlock(&sensor->lock);
>>   
>>          return 0;
>>   }
>> @@ -958,10 +953,8 @@ static int ov5647_get_selection(struct v4l2_subdev *sd,
>>          case V4L2_SEL_TGT_CROP: {
>>                  struct ov5647 *sensor = to_sensor(sd);
>>   
>> -               mutex_lock(&sensor->lock);
>>                  sel->r = *__ov5647_get_pad_crop(sensor, sd_state, sel->pad,
>>                                                  sel->which);
>> -               mutex_unlock(&sensor->lock);
>>   
>>                  return 0;
>>          }
>> @@ -1114,9 +1107,6 @@ static int ov5647_s_ctrl(struct v4l2_ctrl *ctrl)
>>          struct i2c_client *client = v4l2_get_subdevdata(sd);
>>          int ret = 0;
>>   
>> -
>> -       /* v4l2_ctrl_lock() locks our own mutex */
>> -
>>          if (ctrl->id == V4L2_CID_VBLANK) {
>>                  int exposure_max, exposure_def;
>>   
>> @@ -1316,13 +1306,11 @@ static int ov5647_probe(struct i2c_client *client)
>>                  return -EINVAL;
>>          }
>>   
>> -       mutex_init(&sensor->lock);
>> -
>>          sensor->mode = OV5647_DEFAULT_MODE;
>>   
>>          ret = ov5647_init_controls(sensor);
>>          if (ret)
>> -               goto mutex_destroy;
>> +               return ret;
>>   
>>          sd = &sensor->sd;
>>          v4l2_i2c_subdev_init(sd, client, &ov5647_subdev_ops);
>> @@ -1350,9 +1338,16 @@ static int ov5647_probe(struct i2c_client *client)
>>          if (ret < 0)
>>                  goto power_off;
>>   
>> +       sd->state_lock = sensor->ctrls.lock;
>> +       ret = v4l2_subdev_init_finalize(sd);
>> +       if (ret < 0) {
>> +               dev_err(&client->dev, "failed to init subdev: %d", ret);
> Use dev_err_probe

I will correct this in the next version.

Best Regards,
Xiaolei

>
>> +               goto power_off;
>> +       }
>> +
>>          ret = v4l2_async_register_subdev(sd);
>>          if (ret < 0)
>> -               goto power_off;
>> +               goto v4l2_subdev_cleanup;
>>   
>>          /* Enable runtime PM and turn off the device */
>>          pm_runtime_set_active(dev);
>> @@ -1363,14 +1358,14 @@ static int ov5647_probe(struct i2c_client *client)
>>   
>>          return 0;
>>   
>> +v4l2_subdev_cleanup:
>> +       v4l2_subdev_cleanup(sd);
>>   power_off:
>>          ov5647_power_off(dev);
>>   entity_cleanup:
>>          media_entity_cleanup(&sd->entity);
>>   ctrl_handler_free:
>>          v4l2_ctrl_handler_free(&sensor->ctrls);
>> -mutex_destroy:
>> -       mutex_destroy(&sensor->lock);
>>   
>>          return ret;
>>   }
>> @@ -1381,11 +1376,11 @@ static void ov5647_remove(struct i2c_client *client)
>>          struct ov5647 *sensor = to_sensor(sd);
>>   
>>          v4l2_async_unregister_subdev(&sensor->sd);
>> +       v4l2_subdev_cleanup(sd);
>>          media_entity_cleanup(&sensor->sd.entity);
>>          v4l2_ctrl_handler_free(&sensor->ctrls);
>>          v4l2_device_unregister_subdev(sd);
>>          pm_runtime_disable(&client->dev);
>> -       mutex_destroy(&sensor->lock);
>>   }
>>   
>>   static const struct dev_pm_ops ov5647_pm_ops = {
>> --
>> 2.43.0
> Reviewed-by: Tarang Raval <tarang.raval@...iconsignals.io>
>
> Best Regards,
> Tarang

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ