media: platform: amd: use refcount_t instead of atomic_t

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: 4c5feef6a6 ("media: platform: amd: Add isp4 fw and hw interface")
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Reviewed-by: Pratap Nirujogi <pratap.nirujogi@amd.com>
Reviewed-by: Bin Du <bin.du@amd.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
This commit is contained in:
Ricardo Ribalda
2026-06-29 11:30:46 +00:00
committed by Hans Verkuil
parent 6b8ff73412
commit 0baf8f4211
3 changed files with 4 additions and 4 deletions

View File

@@ -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:

View File

@@ -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 {

View File

@@ -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);
}
}