Re: [RFC PATCH v1 3/5] media: tegra-video: Move PM runtime handle to streaming

From: Dmitry Osipenko
Date: Tue Apr 28 2020 - 10:59:19 EST


28.04.2020 17:51, Sowjanya Komatineni ÐÐÑÐÑ:
>
> On 4/28/20 6:59 AM, Dmitry Osipenko wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> 28.04.2020 07:20, Sowjanya Komatineni ÐÐÑÐÑ:
>>> diff --git a/drivers/staging/media/tegra-video/csi.c
>>> b/drivers/staging/media/tegra-video/csi.c
>>> index b3dd0c3..29ccdae 100644
>>> --- a/drivers/staging/media/tegra-video/csi.c
>>> +++ b/drivers/staging/media/tegra-video/csi.c
>>> @@ -272,8 +272,25 @@ static int tegra_csi_s_stream(struct v4l2_subdev
>>> *subdev, int enable)
>>> ÂÂÂÂÂÂ struct tegra_vi_channel *chan = v4l2_get_subdev_hostdata(subdev);
>>> ÂÂÂÂÂÂ struct tegra_csi_channel *csi_chan = to_csi_chan(subdev);
>>> ÂÂÂÂÂÂ struct tegra_csi *csi = csi_chan->csi;
>>> +ÂÂÂÂ int ret;
>>> +
>>> +ÂÂÂÂ if (enable && atomic_add_return(1, &csi->clk_refcnt) == 1) {
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = pm_runtime_get_sync(csi->dev);
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂ if (ret < 0) {
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_err(csi->dev,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "failed to get runtime PM: %d\n", ret);
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pm_runtime_put_noidle(csi->dev);
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ atomic_dec(&csi->clk_refcnt);
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂ }
>>> +ÂÂÂÂ }
>>> +
>>> +ÂÂÂÂ ret = csi->ops->csi_streaming(csi_chan, chan->pg_mode, enable);
>>>
>>> -ÂÂÂÂ return csi->ops->csi_streaming(csi_chan, chan->pg_mode, enable);
>>> +ÂÂÂÂ if ((ret < 0 || !enable) && atomic_dec_and_test(&csi->clk_refcnt))
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂ pm_runtime_put_sync(csi->dev);
>> Runtime PM maintains its own refcount, why these
>> clk_refcnt/power_on_refcnt are needed?
>
> Streaming is per channel and we can't turn power/clocks off while other
> channels may still be running.
>

All channels use the same CSI device. You should remove the custom
refcounting.

BTW, next time you'll really need to do refcounting, use the generic kref.