ASoc: qcom: q6apm: Use automatic cleanup of kfree()

Its common pattern in q6dsp code to allocate temporary buffer
to send gpr/apr packets and free at the function exit.
Now this can be simplified via __free(kfree) mechanism.

No functional changes.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Link: https://patch.msgid.link/20251023102444.88158-15-srinivas.kandagatla@oss.qualcomm.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Srinivas Kandagatla 2025-10-23 11:24:38 +01:00 committed by Mark Brown
parent 55094e55ae
commit 89cf2223ee
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0

View File

@ -99,12 +99,8 @@ static int audioreach_graph_mgmt_cmd(struct audioreach_graph *graph, uint32_t op
struct apm_graph_mgmt_cmd *mgmt_cmd; struct apm_graph_mgmt_cmd *mgmt_cmd;
struct audioreach_sub_graph *sg; struct audioreach_sub_graph *sg;
struct q6apm *apm = graph->apm; struct q6apm *apm = graph->apm;
int i = 0, rc, payload_size; int i = 0, payload_size = APM_GRAPH_MGMT_PSIZE(mgmt_cmd, num_sub_graphs);
struct gpr_pkt *pkt; struct gpr_pkt *pkt __free(kfree) = audioreach_alloc_apm_cmd_pkt(payload_size, opcode, 0);
payload_size = APM_GRAPH_MGMT_PSIZE(mgmt_cmd, num_sub_graphs);
pkt = audioreach_alloc_apm_cmd_pkt(payload_size, opcode, 0);
if (IS_ERR(pkt)) if (IS_ERR(pkt))
return PTR_ERR(pkt); return PTR_ERR(pkt);
@ -120,11 +116,7 @@ static int audioreach_graph_mgmt_cmd(struct audioreach_graph *graph, uint32_t op
list_for_each_entry(sg, &info->sg_list, node) list_for_each_entry(sg, &info->sg_list, node)
mgmt_cmd->sub_graph_id_list[i++] = sg->sub_graph_id; mgmt_cmd->sub_graph_id_list[i++] = sg->sub_graph_id;
rc = q6apm_send_cmd_sync(apm, pkt, 0); return q6apm_send_cmd_sync(apm, pkt, 0);
kfree(pkt);
return rc;
} }
static void q6apm_put_audioreach_graph(struct kref *ref) static void q6apm_put_audioreach_graph(struct kref *ref)
@ -148,16 +140,13 @@ static void q6apm_put_audioreach_graph(struct kref *ref)
static int q6apm_get_apm_state(struct q6apm *apm) static int q6apm_get_apm_state(struct q6apm *apm)
{ {
struct gpr_pkt *pkt; struct gpr_pkt *pkt __free(kfree) = audioreach_alloc_apm_cmd_pkt(0,
APM_CMD_GET_SPF_STATE, 0);
pkt = audioreach_alloc_apm_cmd_pkt(0, APM_CMD_GET_SPF_STATE, 0);
if (IS_ERR(pkt)) if (IS_ERR(pkt))
return PTR_ERR(pkt); return PTR_ERR(pkt);
q6apm_send_cmd_sync(apm, pkt, APM_CMD_RSP_GET_SPF_STATE); q6apm_send_cmd_sync(apm, pkt, APM_CMD_RSP_GET_SPF_STATE);
kfree(pkt);
return apm->state; return apm->state;
} }
@ -270,7 +259,7 @@ int q6apm_unmap_memory_regions(struct q6apm_graph *graph, unsigned int dir)
{ {
struct apm_cmd_shared_mem_unmap_regions *cmd; struct apm_cmd_shared_mem_unmap_regions *cmd;
struct audioreach_graph_data *data; struct audioreach_graph_data *data;
struct gpr_pkt *pkt; struct gpr_pkt *pkt __free(kfree) = NULL;
int rc; int rc;
if (dir == SNDRV_PCM_STREAM_PLAYBACK) if (dir == SNDRV_PCM_STREAM_PLAYBACK)
@ -290,7 +279,6 @@ int q6apm_unmap_memory_regions(struct q6apm_graph *graph, unsigned int dir)
cmd->mem_map_handle = data->mem_map_handle; cmd->mem_map_handle = data->mem_map_handle;
rc = audioreach_graph_send_cmd_sync(graph, pkt, APM_CMD_SHARED_MEM_UNMAP_REGIONS); rc = audioreach_graph_send_cmd_sync(graph, pkt, APM_CMD_SHARED_MEM_UNMAP_REGIONS);
kfree(pkt);
audioreach_graph_free_buf(graph); audioreach_graph_free_buf(graph);
@ -420,11 +408,9 @@ int q6apm_write_async(struct q6apm_graph *graph, uint32_t len, uint32_t msw_ts,
{ {
struct apm_data_cmd_wr_sh_mem_ep_data_buffer_v2 *write_buffer; struct apm_data_cmd_wr_sh_mem_ep_data_buffer_v2 *write_buffer;
struct audio_buffer *ab; struct audio_buffer *ab;
struct gpr_pkt *pkt; int iid = q6apm_graph_get_rx_shmem_module_iid(graph);
int rc, iid; struct gpr_pkt *pkt __free(kfree) = audioreach_alloc_pkt(sizeof(*write_buffer),
DATA_CMD_WR_SH_MEM_EP_DATA_BUFFER_V2,
iid = q6apm_graph_get_rx_shmem_module_iid(graph);
pkt = audioreach_alloc_pkt(sizeof(*write_buffer), DATA_CMD_WR_SH_MEM_EP_DATA_BUFFER_V2,
graph->rx_data.dsp_buf | (len << APM_WRITE_TOKEN_LEN_SHIFT), graph->rx_data.dsp_buf | (len << APM_WRITE_TOKEN_LEN_SHIFT),
graph->port->id, iid); graph->port->id, iid);
if (IS_ERR(pkt)) if (IS_ERR(pkt))
@ -450,11 +436,7 @@ int q6apm_write_async(struct q6apm_graph *graph, uint32_t len, uint32_t msw_ts,
mutex_unlock(&graph->lock); mutex_unlock(&graph->lock);
rc = gpr_send_port_pkt(graph->port, pkt); return gpr_send_port_pkt(graph->port, pkt);
kfree(pkt);
return rc;
} }
EXPORT_SYMBOL_GPL(q6apm_write_async); EXPORT_SYMBOL_GPL(q6apm_write_async);
@ -463,11 +445,9 @@ int q6apm_read(struct q6apm_graph *graph)
struct data_cmd_rd_sh_mem_ep_data_buffer_v2 *read_buffer; struct data_cmd_rd_sh_mem_ep_data_buffer_v2 *read_buffer;
struct audioreach_graph_data *port; struct audioreach_graph_data *port;
struct audio_buffer *ab; struct audio_buffer *ab;
struct gpr_pkt *pkt; int iid = q6apm_graph_get_tx_shmem_module_iid(graph);
int rc, iid; struct gpr_pkt *pkt __free(kfree) = audioreach_alloc_pkt(sizeof(*read_buffer),
DATA_CMD_RD_SH_MEM_EP_DATA_BUFFER_V2,
iid = q6apm_graph_get_tx_shmem_module_iid(graph);
pkt = audioreach_alloc_pkt(sizeof(*read_buffer), DATA_CMD_RD_SH_MEM_EP_DATA_BUFFER_V2,
graph->tx_data.dsp_buf, graph->port->id, iid); graph->tx_data.dsp_buf, graph->port->id, iid);
if (IS_ERR(pkt)) if (IS_ERR(pkt))
return PTR_ERR(pkt); return PTR_ERR(pkt);
@ -490,10 +470,7 @@ int q6apm_read(struct q6apm_graph *graph)
mutex_unlock(&graph->lock); mutex_unlock(&graph->lock);
rc = gpr_send_port_pkt(graph->port, pkt); return gpr_send_port_pkt(graph->port, pkt);
kfree(pkt);
return rc;
} }
EXPORT_SYMBOL_GPL(q6apm_read); EXPORT_SYMBOL_GPL(q6apm_read);