Re: [PATCH 5/9] media: platform: amd: use refcount_t instead of atomic_t
From: Bin Du
Date: Tue Jun 30 2026 - 02:07:37 EST
On 6/29/2026 11:51 PM, Nirujogi, Pratap wrote:
>
>
> On 6/29/2026 7:30 AM, Ricardo Ribalda wrote:
>> [You don't often get email from ribalda@xxxxxxxxxxxx. Learn why this
>> is important at https://aka.ms/LearnAboutSenderIdentification ]
>>
>> Caution: This message originated from an External Source. Use proper
>> caution when opening attachments, clicking links, or responding.
>>
>>
>> We are using the refcnt variable for refcounting. Use the refcount_t
>> type instead, as it has support for saturation and underflow.
>>
>> This also makes cocci happier, as it will fix the following warning:
>> ./platform/amd/isp4/isp4_subdev.c:394:6-25: WARNING:
>> atomic_dec_and_test variation before object free at line 395.
>>
>> Fixes: 4c5feef6a62c ("media: platform: amd: Add isp4 fw and hw
>> interface")
>> Cc: stable@xxxxxxxxxxxxxxx
>> Signed-off-by: Ricardo Ribalda <ribalda@xxxxxxxxxxxx>
>> ---
>> drivers/media/platform/amd/isp4/isp4_interface.c | 4 ++--
>> drivers/media/platform/amd/isp4/isp4_interface.h | 2 +-
>> drivers/media/platform/amd/isp4/isp4_subdev.c | 2 +-
>> 3 files changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/media/platform/amd/isp4/isp4_interface.c b/
>> drivers/media/platform/amd/isp4/isp4_interface.c
>> index 8d73f66bb42c..00a817909292 100644
>> --- a/drivers/media/platform/amd/isp4/isp4_interface.c
>> +++ b/drivers/media/platform/amd/isp4/isp4_interface.c
>> @@ -375,7 +375,7 @@ static int isp4if_send_fw_cmd(struct
>> isp4_interface *ispif, u32 cmd_id,
>> return -ENOMEM;
>>
>> /* Get two references: one for the resp thread, one
>> for us */
>> - atomic_set(&ele->refcnt, 2);
>> + refcount_set(&ele->refcnt, 2);
>> init_completion(&ele->cmd_done);
>> }
>>
>> @@ -455,7 +455,7 @@ static int isp4if_send_fw_cmd(struct
>> isp4_interface *ispif, u32 cmd_id,
>>
>> put_ele_ref:
>> /* Don't free the command if we didn't put the last reference */
>> - if (ele && atomic_dec_return(&ele->refcnt))
>> + if (ele && !refcount_dec_and_test(&ele->refcnt))
>> ele = NULL;
>>
>> free_ele:
>> diff --git a/drivers/media/platform/amd/isp4/isp4_interface.h b/
>> drivers/media/platform/amd/isp4/isp4_interface.h
>> index ce3ac9b9e5cd..04db71cd54e6 100644
>> --- a/drivers/media/platform/amd/isp4/isp4_interface.h
>> +++ b/drivers/media/platform/amd/isp4/isp4_interface.h
>> @@ -68,7 +68,7 @@ struct isp4if_cmd_element {
>> u32 seq_num;
>> u32 cmd_id;
>> struct completion cmd_done;
>> - atomic_t refcnt;
>> + refcount_t refcnt;
>> };
>>
>> struct isp4_interface {
>> diff --git a/drivers/media/platform/amd/isp4/isp4_subdev.c b/drivers/
>> media/platform/amd/isp4/isp4_subdev.c
>> index 48deea79ce6c..2a8bc1207843 100644
>> --- a/drivers/media/platform/amd/isp4/isp4_subdev.c
>> +++ b/drivers/media/platform/amd/isp4/isp4_subdev.c
>> @@ -391,7 +391,7 @@ static void isp4sd_fw_resp_cmd_done(struct
>> isp4_subdev *isp_subdev,
>>
>> if (ele) {
>> complete(&ele->cmd_done);
>> - if (atomic_dec_and_test(&ele->refcnt))
>> + if (refcount_dec_and_test(&ele->refcnt))
>> kfree(ele);
>> }
>> }
>>
>> --
>> 2.55.0.rc0.799.gd6f94ed593-goog
>>
>
> Reviewed-by: Pratap Nirujogi <pratap.nirujogi@xxxxxxx>
>
> Thanks,
> Pratap
>
>
Reviewed-by: Bin Du <bin.du@xxxxxxx>
Regards,
Bin