Skip to contentSkip to conversation

media: amphion: Use kmalloc instead of vmalloc

PATCH In review [email protected] 3 participants 5 messages Dec 22, 2025 – Jan 7

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: amphion: Use kmalloc instead of vmalloc

From: Ming Qian <[email protected]>

Replace vmalloc/vfree with kmalloc/kfree for allocating small driver structures (vpu_inst, vdec_t, venc_t, vpu_cmd_t, and frame objects).

vmalloc() is designed for large memory allocations and incurs unnecessary overhead for small objects due to virtual memory mapping. kmalloc() is more appropriate as it allocates physically contiguous memory with lower overhead.

ftrace measurements of vpu_alloc_cmd() show significant improvement:

  Before (vmalloc):  35-72 us   (avg ~45.7 us)
  After (kmalloc):   11-26 us   (avg ~16.8 us)

This reduces allocation time by approximately 63%.

No functional changes are intended.

---
 drivers/media/platform/amphion/vdec.c     | 16 +++++++---------
 drivers/media/platform/amphion/venc.c     | 20 +++++++++-----------
 drivers/media/platform/amphion/vpu_cmds.c | 15 +++++++--------
 drivers/media/platform/amphion/vpu_core.c | 11 ++++-------
 4 files changed, 27 insertions(+), 35 deletions(-)
drivers/media/platform/amphion/vdec.c +7 -9
index c0d2aabb9e0e..7a1c58cac02d 100644
@@ -9,7 +9,6 @@
 #include <linux/list.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/vmalloc.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-event.h>
@@ -17,7 +16,6 @@
 #include <media/v4l2-ioctl.h>
 #include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
-#include <media/videobuf2-vmalloc.h>
 #include "vpu.h"
 #include "vpu_defs.h"
 #include "vpu_core.h"
@@ -1642,9 +1640,9 @@ static void vdec_cleanup(struct vpu_inst *inst)
 		vdec->slots = NULL;
 		vdec->slot_count = 0;
 	}
-	vfree(vdec);
+	kfree(vdec);
 	inst->priv = NULL;
-	vfree(inst);
+	kfree(inst);
 }
 
 static void vdec_init_params(struct vdec_t *vdec)
@@ -1909,13 +1907,13 @@ static int vdec_open(struct file *file)
 	struct vdec_t *vdec;
 	int ret;
 
-	inst = vzalloc(sizeof(*inst));
+	inst = kzalloc(sizeof(*inst), GFP_KERNEL);
 	if (!inst)
 		return -ENOMEM;
 
-	vdec = vzalloc(sizeof(*vdec));
+	vdec = kzalloc(sizeof(*vdec), GFP_KERNEL);
 	if (!vdec) {
-		vfree(inst);
+		kfree(inst);
 		return -ENOMEM;
 	}
 
@@ -1923,8 +1921,8 @@ static int vdec_open(struct file *file)
 				    sizeof(*vdec->slots),
 				    GFP_KERNEL | __GFP_ZERO);
 	if (!vdec->slots) {
-		vfree(vdec);
-		vfree(inst);
+		kfree(vdec);
+		kfree(inst);
 		return -ENOMEM;
 	}
 	vdec->slot_count = VDEC_SLOT_CNT_DFT;
drivers/media/platform/amphion/venc.c +9 -11
index aced76401b69..9e5cbc2b0d3f 100644
@@ -13,14 +13,12 @@
 #include <linux/videodev2.h>
 #include <linux/ktime.h>
 #include <linux/rational.h>
-#include <linux/vmalloc.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-mem2mem.h>
 #include <media/v4l2-ioctl.h>
 #include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
-#include <media/videobuf2-vmalloc.h>
 #include "vpu.h"
 #include "vpu_defs.h"
 #include "vpu_core.h"
@@ -844,7 +842,7 @@ static int venc_get_encoded_frames(struct vpu_inst *inst)
 					       v4l2_m2m_dst_buf_remove(inst->fh.m2m_ctx)))
 			break;
 		list_del_init(&frame->list);
-		vfree(frame);
+		kfree(frame);
 	}
 
 	return 0;
@@ -860,7 +858,7 @@ static int venc_frame_encoded(struct vpu_inst *inst, void *arg)
 	if (!info)
 		return -EINVAL;
 	venc = inst->priv;
-	frame = vzalloc(sizeof(*frame));
+	frame = kzalloc(sizeof(*frame), GFP_KERNEL);
 	if (!frame)
 		return -ENOMEM;
 
@@ -912,9 +910,9 @@ static void venc_cleanup(struct vpu_inst *inst)
 		return;
 
 	venc = inst->priv;
-	vfree(venc);
+	kfree(venc);
 	inst->priv = NULL;
-	vfree(inst);
+	kfree(inst);
 }
 
 static int venc_start_session(struct vpu_inst *inst, u32 type)
@@ -1067,7 +1065,7 @@ static void venc_cleanup_frames(struct venc_t *venc)
 
 	list_for_each_entry_safe(frame, tmp, &venc->frames, list) {
 		list_del_init(&frame->list);
-		vfree(frame);
+		kfree(frame);
 	}
 }
 
@@ -1151,7 +1149,7 @@ static int venc_process_capture(struct vpu_inst *inst, struct vb2_buffer *vb)
 		return ret;
 
 	list_del_init(&frame->list);
-	vfree(frame);
+	kfree(frame);
 	return 0;
 }
 
@@ -1309,13 +1307,13 @@ static int venc_open(struct file *file)
 	struct venc_t *venc;
 	int ret;
 
-	inst = vzalloc(sizeof(*inst));
+	inst = kzalloc(sizeof(*inst), GFP_KERNEL);
 	if (!inst)
 		return -ENOMEM;
 
-	venc = vzalloc(sizeof(*venc));
+	venc = kzalloc(sizeof(*venc), GFP_KERNEL);
 	if (!venc) {
-		vfree(inst);
+		kfree(inst);
 		return -ENOMEM;
 	}
 
drivers/media/platform/amphion/vpu_cmds.c +7 -8
index 5695f5c1cb3e..ab69412e0aa7 100644
@@ -13,7 +13,6 @@
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/delay.h>
-#include <linux/vmalloc.h>
 #include "vpu.h"
 #include "vpu_defs.h"
 #include "vpu_cmds.h"
@@ -84,13 +83,13 @@ static struct vpu_cmd_t *vpu_alloc_cmd(struct vpu_inst *inst, u32 id, void *data
 	int i;
 	int ret;
 
-	cmd = vzalloc(sizeof(*cmd));
+	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
 	if (!cmd)
 		return NULL;
 
-	cmd->pkt = vzalloc(sizeof(*cmd->pkt));
+	cmd->pkt = kzalloc(sizeof(*cmd->pkt), GFP_KERNEL);
 	if (!cmd->pkt) {
-		vfree(cmd);
+		kfree(cmd);
 		return NULL;
 	}
 
@@ -98,8 +97,8 @@ static struct vpu_cmd_t *vpu_alloc_cmd(struct vpu_inst *inst, u32 id, void *data
 	ret = vpu_iface_pack_cmd(inst->core, cmd->pkt, inst->id, id, data);
 	if (ret) {
 		dev_err(inst->dev, "iface pack cmd %s fail\n", vpu_id_name(id));
-		vfree(cmd->pkt);
-		vfree(cmd);
+		kfree(cmd->pkt);
+		kfree(cmd);
 		return NULL;
 	}
 	for (i = 0; i < ARRAY_SIZE(vpu_cmd_requests); i++) {
@@ -118,8 +117,8 @@ static void vpu_free_cmd(struct vpu_cmd_t *cmd)
 		return;
 	if (cmd->last_response_cmd)
 		atomic_long_set(cmd->last_response_cmd, cmd->key);
-	vfree(cmd->pkt);
-	vfree(cmd);
+	kfree(cmd->pkt);
+	kfree(cmd);
 }
 
 static int vpu_session_process_cmd(struct vpu_inst *inst, struct vpu_cmd_t *cmd)
drivers/media/platform/amphion/vpu_core.c +4 -7
index 168f0514851e..85cc4a14f8ed 100644
@@ -17,7 +17,6 @@
 #include <linux/pm_runtime.h>
 #include <linux/pm_domain.h>
 #include <linux/firmware.h>
-#include <linux/vmalloc.h>
 #include "vpu.h"
 #include "vpu_defs.h"
 #include "vpu_core.h"
@@ -265,7 +264,7 @@ static int vpu_core_register(struct device *dev, struct vpu_core *core)
 	INIT_WORK(&core->msg_work, vpu_msg_run_work);
 	INIT_DELAYED_WORK(&core->msg_delayed_work, vpu_msg_delayed_work);
 	buffer_size = roundup_pow_of_two(VPU_MSG_BUFFER_SIZE);
-	core->msg_buffer = vzalloc(buffer_size);
+	core->msg_buffer = kzalloc(buffer_size, GFP_KERNEL);
 	if (!core->msg_buffer) {
 		dev_err(core->dev, "failed allocate buffer for fifo\n");
 		ret = -ENOMEM;
@@ -282,10 +281,8 @@ static int vpu_core_register(struct device *dev, struct vpu_core *core)
 
 	return 0;
 error:
-	if (core->msg_buffer) {
-		vfree(core->msg_buffer);
-		core->msg_buffer = NULL;
-	}
+	kfree(core->msg_buffer);
+	core->msg_buffer = NULL;
 	if (core->workqueue) {
 		destroy_workqueue(core->workqueue);
 		core->workqueue = NULL;
@@ -308,7 +305,7 @@ static int vpu_core_unregister(struct device *dev, struct vpu_core *core)
 
 	vpu_core_put_vpu(core);
 	core->vpu = NULL;
-	vfree(core->msg_buffer);
+	kfree(core->msg_buffer);
 	core->msg_buffer = NULL;
 
 	if (core->workqueue) {

base-commit: b70886ff5833cf499e77af77d2324ce8f68b60ce

Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Le lundi 22 décembre 2025 à 16:49 +0800, [email protected] a écrit :

Quoted 13 lines

From: Ming Qian <[email protected]>

Replace vmalloc/vfree with kmalloc/kfree for allocating small driver structures (vpu_inst, vdec_t, venc_t, vpu_cmd_t, and frame objects).

vmalloc() is designed for large memory allocations and incurs unnecessary overhead for small objects due to virtual memory mapping. kmalloc() is more appropriate as it allocates physically contiguous memory with lower overhead.

ftrace measurements of vpu_alloc_cmd() show significant improvement:

Quoted 8 lines

  Before (vmalloc):  35-72 us   (avg ~45.7 us)
  After (kmalloc):   11-26 us   (avg ~16.8 us)

This reduces allocation time by approximately 63%.

No functional changes are intended.

I don't see this patch on patchwork yet, I don't know why. Did you get a notification or anything ? The patch looks good to me.

Quoted 247 lines

---
 drivers/media/platform/amphion/vdec.c     | 16 +++++++--------- drivers/media/platform/amphion/venc.c     | 20 +++++++++----------- drivers/media/platform/amphion/vpu_cmds.c | 15 +++++++-------- drivers/media/platform/amphion/vpu_core.c | 11 ++++-------

 4 files changed, 27 insertions(+), 35 deletions(-)
drivers/media/platform/amphion/vdec.c +2 -4
index c0d2aabb9e0e..7a1c58cac02d 100644
@@ -9,7 +9,6 @@
  #include <linux/list.h>
  #include <linux/kernel.h>
  #include <linux/module.h>
-#include <linux/vmalloc.h>
  #include <linux/videodev2.h>
  #include <media/v4l2-device.h>
  #include <media/v4l2-event.h>
@@ -17,7 +16,6 @@
  #include <media/v4l2-ioctl.h>
  #include <media/videobuf2-v4l2.h>
  #include <media/videobuf2-dma-contig.h>
-#include <media/videobuf2-vmalloc.h>
  #include "vpu.h"
  #include "vpu_defs.h"
  #include "vpu_core.h"
@@ -1642,9 +1640,9 @@ static void vdec_cleanup(struct vpu_inst *inst)
  		vdec->slots = NULL;
  		vdec->slot_count = 0;
  	}
-	vfree(vdec);
+	kfree(vdec);
  	inst->priv = NULL;
-	vfree(inst);
+	kfree(inst);
  }


 static void vdec_init_params(struct vdec_t *vdec)

drivers/media/platform/amphion/vdec.c +0 -0
@@ -1909,13 +1907,13 @@ static int vdec_open(struct file *file)
  	struct vdec_t *vdec;
  	int ret;

drivers/media/platform/amphion/vdec.c +1 -1
-	inst = vzalloc(sizeof(*inst));
+	inst = kzalloc(sizeof(*inst), GFP_KERNEL);

  if (!inst)
  return -ENOMEM;

drivers/media/platform/amphion/vdec.c +1 -1
-	vdec = vzalloc(sizeof(*vdec));
+	vdec = kzalloc(sizeof(*vdec), GFP_KERNEL);

  if (!vdec) {

drivers/media/platform/amphion/vdec.c +1 -1
-		vfree(inst);
+		kfree(inst);

  return -ENOMEM;
  }

drivers/media/platform/amphion/vdec.c +2 -2
@@ -1923,8 +1921,8 @@ static int vdec_open(struct file *file)
  				    sizeof(*vdec->slots),
  				    GFP_KERNEL | __GFP_ZERO);
  	if (!vdec->slots) {
-		vfree(vdec);
-		vfree(inst);
+		kfree(vdec);
+		kfree(inst);
  		return -ENOMEM;
  	}
  	vdec->slot_count = VDEC_SLOT_CNT_DFT;
drivers/media/platform/amphion/venc.c +1 -3
index aced76401b69..9e5cbc2b0d3f 100644
@@ -13,14 +13,12 @@
  #include <linux/videodev2.h>
  #include <linux/ktime.h>
  #include <linux/rational.h>
-#include <linux/vmalloc.h>
  #include <media/v4l2-device.h>
  #include <media/v4l2-event.h>
  #include <media/v4l2-mem2mem.h>
  #include <media/v4l2-ioctl.h>
  #include <media/videobuf2-v4l2.h>
  #include <media/videobuf2-dma-contig.h>
-#include <media/videobuf2-vmalloc.h>
  #include "vpu.h"
  #include "vpu_defs.h"
  #include "vpu_core.h"
@@ -844,7 +842,7 @@ static int venc_get_encoded_frames(struct vpu_inst *inst)
  					       v4l2_m2m_dst_buf_remove(inst->fh.m2m_ctx)))
  			break;
  		list_del_init(&frame->list);
-		vfree(frame);
+		kfree(frame);
  	}


  return 0;

drivers/media/platform/amphion/venc.c +1 -1
@@ -860,7 +858,7 @@ static int venc_frame_encoded(struct vpu_inst *inst, void *arg)
  	if (!info)
  		return -EINVAL;
  	venc = inst->priv;
-	frame = vzalloc(sizeof(*frame));
+	frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  	if (!frame)
  		return -ENOMEM;

drivers/media/platform/amphion/venc.c +0 -0
@@ -912,9 +910,9 @@ static void venc_cleanup(struct vpu_inst *inst)
  		return;


  venc = inst->priv;

drivers/media/platform/amphion/venc.c +1 -1
-	vfree(venc);
+	kfree(venc);

  inst->priv = NULL;

drivers/media/platform/amphion/venc.c +1 -1
-	vfree(inst);
+	kfree(inst);

 }

 static int venc_start_session(struct vpu_inst *inst, u32 type)

drivers/media/platform/amphion/venc.c +0 -0
@@ -1067,7 +1065,7 @@ static void venc_cleanup_frames(struct venc_t *venc)


  list_for_each_entry_safe(frame, tmp, &venc->frames, list) { list_del_init(&frame->list);

drivers/media/platform/amphion/venc.c +1 -1
-		vfree(frame);
+		kfree(frame);

  }
 }

drivers/media/platform/amphion/venc.c +0 -0
@@ -1151,7 +1149,7 @@ static int venc_process_capture(struct vpu_inst *inst, struct vb2_buffer *vb)
  		return ret;


  list_del_init(&frame->list);

drivers/media/platform/amphion/venc.c +1 -1
-	vfree(frame);
+	kfree(frame);

  return 0;
 }

drivers/media/platform/amphion/venc.c +0 -0
@@ -1309,13 +1307,13 @@ static int venc_open(struct file *file)
  	struct venc_t *venc;
  	int ret;

drivers/media/platform/amphion/venc.c +1 -1
-	inst = vzalloc(sizeof(*inst));
+	inst = kzalloc(sizeof(*inst), GFP_KERNEL);

  if (!inst)
  return -ENOMEM;

drivers/media/platform/amphion/venc.c +1 -1
-	venc = vzalloc(sizeof(*venc));
+	venc = kzalloc(sizeof(*venc), GFP_KERNEL);

  if (!venc) {

drivers/media/platform/amphion/venc.c +1 -1
-		vfree(inst);
+		kfree(inst);

  return -ENOMEM;
  }

drivers/media/platform/amphion/vpu_cmds.c +0 -1
index 5695f5c1cb3e..ab69412e0aa7 100644
@@ -13,7 +13,6 @@
  #include <linux/slab.h>
  #include <linux/types.h>
  #include <linux/delay.h>
-#include <linux/vmalloc.h>
  #include "vpu.h"
  #include "vpu_defs.h"
  #include "vpu_cmds.h"
@@ -84,13 +83,13 @@ static struct vpu_cmd_t *vpu_alloc_cmd(struct vpu_inst *inst, u32 id, void *data
  	int i;
  	int ret;

drivers/media/platform/amphion/vpu_cmds.c +1 -1
-	cmd = vzalloc(sizeof(*cmd));
+	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);

  if (!cmd)
  return NULL;

drivers/media/platform/amphion/vpu_cmds.c +1 -1
-	cmd->pkt = vzalloc(sizeof(*cmd->pkt));
+	cmd->pkt = kzalloc(sizeof(*cmd->pkt), GFP_KERNEL);

  if (!cmd->pkt) {

drivers/media/platform/amphion/vpu_cmds.c +1 -1
-		vfree(cmd);
+		kfree(cmd);

  return NULL;
  }

drivers/media/platform/amphion/vpu_cmds.c +4 -4
@@ -98,8 +97,8 @@ static struct vpu_cmd_t *vpu_alloc_cmd(struct vpu_inst *inst, u32 id, void *data
  	ret = vpu_iface_pack_cmd(inst->core, cmd->pkt, inst->id, id, data);
  	if (ret) {
  		dev_err(inst->dev, "iface pack cmd %s fail\n", vpu_id_name(id));
-		vfree(cmd->pkt);
-		vfree(cmd);
+		kfree(cmd->pkt);
+		kfree(cmd);
  		return NULL;
  	}
  	for (i = 0; i < ARRAY_SIZE(vpu_cmd_requests); i++) {
@@ -118,8 +117,8 @@ static void vpu_free_cmd(struct vpu_cmd_t *cmd)
  		return;
  	if (cmd->last_response_cmd)
  		atomic_long_set(cmd->last_response_cmd, cmd->key);
-	vfree(cmd->pkt);
-	vfree(cmd);
+	kfree(cmd->pkt);
+	kfree(cmd);
  }


 static int vpu_session_process_cmd(struct vpu_inst *inst, struct vpu_cmd_t *cmd)

drivers/media/platform/amphion/vpu_core.c +1 -2
index 168f0514851e..85cc4a14f8ed 100644
@@ -17,7 +17,6 @@
  #include <linux/pm_runtime.h>
  #include <linux/pm_domain.h>
  #include <linux/firmware.h>
-#include <linux/vmalloc.h>
  #include "vpu.h"
  #include "vpu_defs.h"
  #include "vpu_core.h"
@@ -265,7 +264,7 @@ static int vpu_core_register(struct device *dev, struct vpu_core *core)
  	INIT_WORK(&core->msg_work, vpu_msg_run_work);
  	INIT_DELAYED_WORK(&core->msg_delayed_work, vpu_msg_delayed_work);
  	buffer_size = roundup_pow_of_two(VPU_MSG_BUFFER_SIZE);
-	core->msg_buffer = vzalloc(buffer_size);
+	core->msg_buffer = kzalloc(buffer_size, GFP_KERNEL);
  	if (!core->msg_buffer) {
  		dev_err(core->dev, "failed allocate buffer for fifo\n");
  		ret = -ENOMEM;
@@ -282,10 +281,8 @@ static int vpu_core_register(struct device *dev, struct vpu_core *core)


  return 0;
 error:

drivers/media/platform/amphion/vpu_core.c +2 -4
-	if (core->msg_buffer) {
-		vfree(core->msg_buffer);
-		core->msg_buffer = NULL;
-	}
+	kfree(core->msg_buffer);
+	core->msg_buffer = NULL;

  if (core->workqueue) { destroy_workqueue(core->workqueue); core->workqueue = NULL;

drivers/media/platform/amphion/vpu_core.c +0 -0
@@ -308,7 +305,7 @@ static int vpu_core_unregister(struct device *dev, struct vpu_core *core)


  vpu_core_put_vpu(core);
  core->vpu = NULL;

drivers/media/platform/amphion/vpu_core.c +1 -1
-	vfree(core->msg_buffer);
+	kfree(core->msg_buffer);

  core->msg_buffer = NULL;

  if (core->workqueue) {

base-commit: b70886ff5833cf499e77af77d2324ce8f68b60ce

#2 lore raw

Hi Nicolas,

Quoted 21 lines · Nicolas Dufresne

Hi,

Quoted 18 lines · Le lundi 22 décembre 2025 à 16:49 +0800, [email protected] a écrit :

From: Ming Qian <[email protected]>

Replace vmalloc/vfree with kmalloc/kfree for allocating small driver structures (vpu_inst, vdec_t, venc_t, vpu_cmd_t, and frame objects).

vmalloc() is designed for large memory allocations and incurs unnecessary overhead for small objects due to virtual memory mapping. kmalloc() is more appropriate as it allocates physically contiguous memory with lower overhead.

ftrace measurements of vpu_alloc_cmd() show significant improvement:

   Before (vmalloc):  35-72 us   (avg ~45.7 us)
   After (kmalloc):   11-26 us   (avg ~16.8 us)

This reduces allocation time by approximately 63%.

Quoted 9 lines
Quoted 3 lines

No functional changes are intended.

I don't see this patch on patchwork yet, I don't know why. Did you get a notification or anything ? The patch looks good to me.

I did not receive any system notification or reply.
It's currently in patchwork, and I'm not sure why there's been such a long delay.

Thanks for your review.

Regards,
Ming

Quoted 247 lines
Quoted 247 lines
---
  drivers/media/platform/amphion/vdec.c     | 16 +++++++---------
  drivers/media/platform/amphion/venc.c     | 20 +++++++++-----------
  drivers/media/platform/amphion/vpu_cmds.c | 15 +++++++--------
  drivers/media/platform/amphion/vpu_core.c | 11 ++++-------
  4 files changed, 27 insertions(+), 35 deletions(-)
drivers/media/platform/amphion/vdec.c +7 -9
index c0d2aabb9e0e..7a1c58cac02d 100644
@@ -9,7 +9,6 @@
  #include <linux/list.h>
  #include <linux/kernel.h>
  #include <linux/module.h>
-#include <linux/vmalloc.h>
  #include <linux/videodev2.h>
  #include <media/v4l2-device.h>
  #include <media/v4l2-event.h>
@@ -17,7 +16,6 @@
  #include <media/v4l2-ioctl.h>
  #include <media/videobuf2-v4l2.h>
  #include <media/videobuf2-dma-contig.h>
-#include <media/videobuf2-vmalloc.h>
  #include "vpu.h"
  #include "vpu_defs.h"
  #include "vpu_core.h"
@@ -1642,9 +1640,9 @@ static void vdec_cleanup(struct vpu_inst *inst)
  		vdec->slots = NULL;
  		vdec->slot_count = 0;
  	}
-	vfree(vdec);
+	kfree(vdec);
  	inst->priv = NULL;
-	vfree(inst);
+	kfree(inst);
  }
 
  static void vdec_init_params(struct vdec_t *vdec)
@@ -1909,13 +1907,13 @@ static int vdec_open(struct file *file)
  	struct vdec_t *vdec;
  	int ret;
 
-	inst = vzalloc(sizeof(*inst));
+	inst = kzalloc(sizeof(*inst), GFP_KERNEL);
  	if (!inst)
  		return -ENOMEM;
 
-	vdec = vzalloc(sizeof(*vdec));
+	vdec = kzalloc(sizeof(*vdec), GFP_KERNEL);
  	if (!vdec) {
-		vfree(inst);
+		kfree(inst);
  		return -ENOMEM;
  	}
 
@@ -1923,8 +1921,8 @@ static int vdec_open(struct file *file)
  				    sizeof(*vdec->slots),
  				    GFP_KERNEL | __GFP_ZERO);
  	if (!vdec->slots) {
-		vfree(vdec);
-		vfree(inst);
+		kfree(vdec);
+		kfree(inst);
  		return -ENOMEM;
  	}
  	vdec->slot_count = VDEC_SLOT_CNT_DFT;
drivers/media/platform/amphion/venc.c +9 -11
index aced76401b69..9e5cbc2b0d3f 100644
@@ -13,14 +13,12 @@
  #include <linux/videodev2.h>
  #include <linux/ktime.h>
  #include <linux/rational.h>
-#include <linux/vmalloc.h>
  #include <media/v4l2-device.h>
  #include <media/v4l2-event.h>
  #include <media/v4l2-mem2mem.h>
  #include <media/v4l2-ioctl.h>
  #include <media/videobuf2-v4l2.h>
  #include <media/videobuf2-dma-contig.h>
-#include <media/videobuf2-vmalloc.h>
  #include "vpu.h"
  #include "vpu_defs.h"
  #include "vpu_core.h"
@@ -844,7 +842,7 @@ static int venc_get_encoded_frames(struct vpu_inst *inst)
  					       v4l2_m2m_dst_buf_remove(inst->fh.m2m_ctx)))
  			break;
  		list_del_init(&frame->list);
-		vfree(frame);
+		kfree(frame);
  	}
 
  	return 0;
@@ -860,7 +858,7 @@ static int venc_frame_encoded(struct vpu_inst *inst, void *arg)
  	if (!info)
  		return -EINVAL;
  	venc = inst->priv;
-	frame = vzalloc(sizeof(*frame));
+	frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  	if (!frame)
  		return -ENOMEM;
 
@@ -912,9 +910,9 @@ static void venc_cleanup(struct vpu_inst *inst)
  		return;
 
  	venc = inst->priv;
-	vfree(venc);
+	kfree(venc);
  	inst->priv = NULL;
-	vfree(inst);
+	kfree(inst);
  }
 
  static int venc_start_session(struct vpu_inst *inst, u32 type)
@@ -1067,7 +1065,7 @@ static void venc_cleanup_frames(struct venc_t *venc)
 
  	list_for_each_entry_safe(frame, tmp, &venc->frames, list) {
  		list_del_init(&frame->list);
-		vfree(frame);
+		kfree(frame);
  	}
  }
 
@@ -1151,7 +1149,7 @@ static int venc_process_capture(struct vpu_inst *inst, struct vb2_buffer *vb)
  		return ret;
 
  	list_del_init(&frame->list);
-	vfree(frame);
+	kfree(frame);
  	return 0;
  }
 
@@ -1309,13 +1307,13 @@ static int venc_open(struct file *file)
  	struct venc_t *venc;
  	int ret;
 
-	inst = vzalloc(sizeof(*inst));
+	inst = kzalloc(sizeof(*inst), GFP_KERNEL);
  	if (!inst)
  		return -ENOMEM;
 
-	venc = vzalloc(sizeof(*venc));
+	venc = kzalloc(sizeof(*venc), GFP_KERNEL);
  	if (!venc) {
-		vfree(inst);
+		kfree(inst);
  		return -ENOMEM;
  	}
 
drivers/media/platform/amphion/vpu_cmds.c +7 -8
index 5695f5c1cb3e..ab69412e0aa7 100644
@@ -13,7 +13,6 @@
  #include <linux/slab.h>
  #include <linux/types.h>
  #include <linux/delay.h>
-#include <linux/vmalloc.h>
  #include "vpu.h"
  #include "vpu_defs.h"
  #include "vpu_cmds.h"
@@ -84,13 +83,13 @@ static struct vpu_cmd_t *vpu_alloc_cmd(struct vpu_inst *inst, u32 id, void *data
  	int i;
  	int ret;
 
-	cmd = vzalloc(sizeof(*cmd));
+	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  	if (!cmd)
  		return NULL;
 
-	cmd->pkt = vzalloc(sizeof(*cmd->pkt));
+	cmd->pkt = kzalloc(sizeof(*cmd->pkt), GFP_KERNEL);
  	if (!cmd->pkt) {
-		vfree(cmd);
+		kfree(cmd);
  		return NULL;
  	}
 
@@ -98,8 +97,8 @@ static struct vpu_cmd_t *vpu_alloc_cmd(struct vpu_inst *inst, u32 id, void *data
  	ret = vpu_iface_pack_cmd(inst->core, cmd->pkt, inst->id, id, data);
  	if (ret) {
  		dev_err(inst->dev, "iface pack cmd %s fail\n", vpu_id_name(id));
-		vfree(cmd->pkt);
-		vfree(cmd);
+		kfree(cmd->pkt);
+		kfree(cmd);
  		return NULL;
  	}
  	for (i = 0; i < ARRAY_SIZE(vpu_cmd_requests); i++) {
@@ -118,8 +117,8 @@ static void vpu_free_cmd(struct vpu_cmd_t *cmd)
  		return;
  	if (cmd->last_response_cmd)
  		atomic_long_set(cmd->last_response_cmd, cmd->key);
-	vfree(cmd->pkt);
-	vfree(cmd);
+	kfree(cmd->pkt);
+	kfree(cmd);
  }
 
  static int vpu_session_process_cmd(struct vpu_inst *inst, struct vpu_cmd_t *cmd)
drivers/media/platform/amphion/vpu_core.c +4 -7
index 168f0514851e..85cc4a14f8ed 100644
@@ -17,7 +17,6 @@
  #include <linux/pm_runtime.h>
  #include <linux/pm_domain.h>
  #include <linux/firmware.h>
-#include <linux/vmalloc.h>
  #include "vpu.h"
  #include "vpu_defs.h"
  #include "vpu_core.h"
@@ -265,7 +264,7 @@ static int vpu_core_register(struct device *dev, struct vpu_core *core)
  	INIT_WORK(&core->msg_work, vpu_msg_run_work);
  	INIT_DELAYED_WORK(&core->msg_delayed_work, vpu_msg_delayed_work);
  	buffer_size = roundup_pow_of_two(VPU_MSG_BUFFER_SIZE);
-	core->msg_buffer = vzalloc(buffer_size);
+	core->msg_buffer = kzalloc(buffer_size, GFP_KERNEL);
  	if (!core->msg_buffer) {
  		dev_err(core->dev, "failed allocate buffer for fifo\n");
  		ret = -ENOMEM;
@@ -282,10 +281,8 @@ static int vpu_core_register(struct device *dev, struct vpu_core *core)
 
  	return 0;
  error:
-	if (core->msg_buffer) {
-		vfree(core->msg_buffer);
-		core->msg_buffer = NULL;
-	}
+	kfree(core->msg_buffer);
+	core->msg_buffer = NULL;
  	if (core->workqueue) {
  		destroy_workqueue(core->workqueue);
  		core->workqueue = NULL;
@@ -308,7 +305,7 @@ static int vpu_core_unregister(struct device *dev, struct vpu_core *core)
 
  	vpu_core_put_vpu(core);
  	core->vpu = NULL;
-	vfree(core->msg_buffer);
+	kfree(core->msg_buffer);
  	core->msg_buffer = NULL;
 
  	if (core->workqueue) {

base-commit: b70886ff5833cf499e77af77d2324ce8f68b60ce

Reviewed-by on v1 1/1
#3 lore raw
In reply to [email protected]

Hi,

Le lundi 22 décembre 2025 à 16:49 +0800, [email protected] a écrit :

Quoted 13 lines

From: Ming Qian <[email protected]>

Replace vmalloc/vfree with kmalloc/kfree for allocating small driver structures (vpu_inst, vdec_t, venc_t, vpu_cmd_t, and frame objects).

vmalloc() is designed for large memory allocations and incurs unnecessary overhead for small objects due to virtual memory mapping. kmalloc() is more appropriate as it allocates physically contiguous memory with lower overhead.

ftrace measurements of vpu_alloc_cmd() show significant improvement:

Quoted 8 lines

  Before (vmalloc):  35-72 us   (avg ~45.7 us)
  After (kmalloc):   11-26 us   (avg ~16.8 us)

This reduces allocation time by approximately 63%.

No functional changes are intended.

Looks good to me.

Quoted 261 lines

---
 drivers/media/platform/amphion/vdec.c     | 16 +++++++--------- drivers/media/platform/amphion/venc.c     | 20 +++++++++----------- drivers/media/platform/amphion/vpu_cmds.c | 15 +++++++-------- drivers/media/platform/amphion/vpu_core.c | 11 ++++-------

 4 files changed, 27 insertions(+), 35 deletions(-)
drivers/media/platform/amphion/vdec.c +2 -4
index c0d2aabb9e0e..7a1c58cac02d 100644
@@ -9,7 +9,6 @@
  #include <linux/list.h>
  #include <linux/kernel.h>
  #include <linux/module.h>
-#include <linux/vmalloc.h>
  #include <linux/videodev2.h>
  #include <media/v4l2-device.h>
  #include <media/v4l2-event.h>
@@ -17,7 +16,6 @@
  #include <media/v4l2-ioctl.h>
  #include <media/videobuf2-v4l2.h>
  #include <media/videobuf2-dma-contig.h>
-#include <media/videobuf2-vmalloc.h>
  #include "vpu.h"
  #include "vpu_defs.h"
  #include "vpu_core.h"
@@ -1642,9 +1640,9 @@ static void vdec_cleanup(struct vpu_inst *inst)
  		vdec->slots = NULL;
  		vdec->slot_count = 0;
  	}
-	vfree(vdec);
+	kfree(vdec);
  	inst->priv = NULL;
-	vfree(inst);
+	kfree(inst);
  }


 static void vdec_init_params(struct vdec_t *vdec)

drivers/media/platform/amphion/vdec.c +0 -0
@@ -1909,13 +1907,13 @@ static int vdec_open(struct file *file)
  	struct vdec_t *vdec;
  	int ret;

drivers/media/platform/amphion/vdec.c +1 -1
-	inst = vzalloc(sizeof(*inst));
+	inst = kzalloc(sizeof(*inst), GFP_KERNEL);

  if (!inst)
  return -ENOMEM;

drivers/media/platform/amphion/vdec.c +1 -1
-	vdec = vzalloc(sizeof(*vdec));
+	vdec = kzalloc(sizeof(*vdec), GFP_KERNEL);

  if (!vdec) {

drivers/media/platform/amphion/vdec.c +1 -1
-		vfree(inst);
+		kfree(inst);

  return -ENOMEM;
  }

drivers/media/platform/amphion/vdec.c +2 -2
@@ -1923,8 +1921,8 @@ static int vdec_open(struct file *file)
  				    sizeof(*vdec->slots),
  				    GFP_KERNEL | __GFP_ZERO);
  	if (!vdec->slots) {
-		vfree(vdec);
-		vfree(inst);
+		kfree(vdec);
+		kfree(inst);
  		return -ENOMEM;
  	}
  	vdec->slot_count = VDEC_SLOT_CNT_DFT;
drivers/media/platform/amphion/venc.c +0 -2
index aced76401b69..9e5cbc2b0d3f 100644
@@ -13,14 +13,12 @@
  #include <linux/videodev2.h>
  #include <linux/ktime.h>
  #include <linux/rational.h>
-#include <linux/vmalloc.h>
  #include <media/v4l2-device.h>
  #include <media/v4l2-event.h>
  #include <media/v4l2-mem2mem.h>
  #include <media/v4l2-ioctl.h>
  #include <media/videobuf2-v4l2.h>
  #include <media/videobuf2-dma-contig.h>
-#include <media/videobuf2-vmalloc.h>
  #include "vpu.h"
  #include "vpu_defs.h"
  #include "vpu_core.h"
@@ -844,7 +842,7 @@ static int venc_get_encoded_frames(struct vpu_inst *inst)

         v4l2_m2m_dst_buf_remove(inst-

Quoted 1 line

fh.m2m_ctx)))

  break;
  list_del_init(&frame->list);

drivers/media/platform/amphion/venc.c +1 -1
-		vfree(frame);
+		kfree(frame);

  }

  return 0;

drivers/media/platform/amphion/venc.c +1 -1
@@ -860,7 +858,7 @@ static int venc_frame_encoded(struct vpu_inst *inst, void
 *arg)
  	if (!info)
  		return -EINVAL;
  	venc = inst->priv;
-	frame = vzalloc(sizeof(*frame));
+	frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  	if (!frame)
  		return -ENOMEM;

drivers/media/platform/amphion/venc.c +0 -0
@@ -912,9 +910,9 @@ static void venc_cleanup(struct vpu_inst *inst)
  		return;


  venc = inst->priv;

drivers/media/platform/amphion/venc.c +1 -1
-	vfree(venc);
+	kfree(venc);

  inst->priv = NULL;

drivers/media/platform/amphion/venc.c +1 -1
-	vfree(inst);
+	kfree(inst);

 }

 static int venc_start_session(struct vpu_inst *inst, u32 type)

drivers/media/platform/amphion/venc.c +0 -0
@@ -1067,7 +1065,7 @@ static void venc_cleanup_frames(struct venc_t *venc)


  list_for_each_entry_safe(frame, tmp, &venc->frames, list) { list_del_init(&frame->list);

drivers/media/platform/amphion/venc.c +1 -1
-		vfree(frame);
+		kfree(frame);

  }
 }

drivers/media/platform/amphion/venc.c +0 -0
@@ -1151,7 +1149,7 @@ static int venc_process_capture(struct vpu_inst *inst,
 struct vb2_buffer *vb)
  		return ret;


  list_del_init(&frame->list);

drivers/media/platform/amphion/venc.c +1 -1
-	vfree(frame);
+	kfree(frame);

  return 0;
 }

drivers/media/platform/amphion/venc.c +0 -0
@@ -1309,13 +1307,13 @@ static int venc_open(struct file *file)
  	struct venc_t *venc;
  	int ret;

drivers/media/platform/amphion/venc.c +1 -1
-	inst = vzalloc(sizeof(*inst));
+	inst = kzalloc(sizeof(*inst), GFP_KERNEL);

  if (!inst)
  return -ENOMEM;

drivers/media/platform/amphion/venc.c +1 -1
-	venc = vzalloc(sizeof(*venc));
+	venc = kzalloc(sizeof(*venc), GFP_KERNEL);

  if (!venc) {

drivers/media/platform/amphion/venc.c +1 -1
-		vfree(inst);
+		kfree(inst);

  return -ENOMEM;
  }

drivers/media/platform/amphion/vpu_cmds.c +0 -1
index 5695f5c1cb3e..ab69412e0aa7 100644
@@ -13,7 +13,6 @@
  #include <linux/slab.h>
  #include <linux/types.h>
  #include <linux/delay.h>
-#include <linux/vmalloc.h>
  #include "vpu.h"
  #include "vpu_defs.h"
  #include "vpu_cmds.h"
@@ -84,13 +83,13 @@ static struct vpu_cmd_t *vpu_alloc_cmd(struct vpu_inst
 *inst, u32 id, void *data
  	int i;
  	int ret;

drivers/media/platform/amphion/vpu_cmds.c +1 -1
-	cmd = vzalloc(sizeof(*cmd));
+	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);

  if (!cmd)
  return NULL;

drivers/media/platform/amphion/vpu_cmds.c +1 -1
-	cmd->pkt = vzalloc(sizeof(*cmd->pkt));
+	cmd->pkt = kzalloc(sizeof(*cmd->pkt), GFP_KERNEL);

  if (!cmd->pkt) {

drivers/media/platform/amphion/vpu_cmds.c +1 -1
-		vfree(cmd);
+		kfree(cmd);

  return NULL;
  }

drivers/media/platform/amphion/vpu_cmds.c +2 -2
@@ -98,8 +97,8 @@ static struct vpu_cmd_t *vpu_alloc_cmd(struct vpu_inst
 *inst, u32 id, void *data
  	ret = vpu_iface_pack_cmd(inst->core, cmd->pkt, inst->id, id, data);
  	if (ret) {
  		dev_err(inst->dev, "iface pack cmd %s fail\n",
 vpu_id_name(id));
-		vfree(cmd->pkt);
-		vfree(cmd);
+		kfree(cmd->pkt);
+		kfree(cmd);
  		return NULL;

  }
  for (i = 0; i < ARRAY_SIZE(vpu_cmd_requests); i++) {

drivers/media/platform/amphion/vpu_cmds.c +2 -2
@@ -118,8 +117,8 @@ static void vpu_free_cmd(struct vpu_cmd_t *cmd)
  		return;
  	if (cmd->last_response_cmd)
  		atomic_long_set(cmd->last_response_cmd, cmd->key);
-	vfree(cmd->pkt);
-	vfree(cmd);
+	kfree(cmd->pkt);
+	kfree(cmd);
  }


 static int vpu_session_process_cmd(struct vpu_inst *inst, struct vpu_cmd_t *cmd)

drivers/media/platform/amphion/vpu_core.c +1 -2
index 168f0514851e..85cc4a14f8ed 100644
@@ -17,7 +17,6 @@
  #include <linux/pm_runtime.h>
  #include <linux/pm_domain.h>
  #include <linux/firmware.h>
-#include <linux/vmalloc.h>
  #include "vpu.h"
  #include "vpu_defs.h"
  #include "vpu_core.h"
@@ -265,7 +264,7 @@ static int vpu_core_register(struct device *dev, struct
 vpu_core *core)
  	INIT_WORK(&core->msg_work, vpu_msg_run_work);
  	INIT_DELAYED_WORK(&core->msg_delayed_work, vpu_msg_delayed_work);
  	buffer_size = roundup_pow_of_two(VPU_MSG_BUFFER_SIZE);
-	core->msg_buffer = vzalloc(buffer_size);
+	core->msg_buffer = kzalloc(buffer_size, GFP_KERNEL);
  	if (!core->msg_buffer) {
  		dev_err(core->dev, "failed allocate buffer for fifo\n");

  ret = -ENOMEM;

drivers/media/platform/amphion/vpu_core.c +0 -0
@@ -282,10 +281,8 @@ static int vpu_core_register(struct device *dev, struct
 vpu_core *core)


  return 0;
 error:

drivers/media/platform/amphion/vpu_core.c +2 -4
-	if (core->msg_buffer) {
-		vfree(core->msg_buffer);
-		core->msg_buffer = NULL;
-	}
+	kfree(core->msg_buffer);
+	core->msg_buffer = NULL;

  if (core->workqueue) { destroy_workqueue(core->workqueue); core->workqueue = NULL;

drivers/media/platform/amphion/vpu_core.c +0 -0
@@ -308,7 +305,7 @@ static int vpu_core_unregister(struct device *dev, struct
 vpu_core *core)


  vpu_core_put_vpu(core);
  core->vpu = NULL;

drivers/media/platform/amphion/vpu_core.c +1 -1
-	vfree(core->msg_buffer);
+	kfree(core->msg_buffer);

  core->msg_buffer = NULL;

  if (core->workqueue) {

base-commit: b70886ff5833cf499e77af77d2324ce8f68b60ce

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to [email protected]
Quoted 16 lines · On Mon, Dec 22, 2025 at 04:49:10PM +0800, [email protected] wrote:

From: Ming Qian <[email protected]>

Replace vmalloc/vfree with kmalloc/kfree for allocating small driver structures (vpu_inst, vdec_t, venc_t, vpu_cmd_t, and frame objects).

vmalloc() is designed for large memory allocations and incurs unnecessary overhead for small objects due to virtual memory mapping. kmalloc() is more appropriate as it allocates physically contiguous memory with lower overhead.

ftrace measurements of vpu_alloc_cmd() show significant improvement:

  Before (vmalloc):  35-72 us   (avg ~45.7 us)
  After (kmalloc):   11-26 us   (avg ~16.8 us)
Quoted 6 lines

This reduces allocation time by approximately 63%.

No functional changes are intended.

---

Quoted 249 lines
 drivers/media/platform/amphion/vdec.c     | 16 +++++++---------
 drivers/media/platform/amphion/venc.c     | 20 +++++++++-----------
 drivers/media/platform/amphion/vpu_cmds.c | 15 +++++++--------
 drivers/media/platform/amphion/vpu_core.c | 11 ++++-------
 4 files changed, 27 insertions(+), 35 deletions(-)
drivers/media/platform/amphion/vdec.c +7 -9
index c0d2aabb9e0e..7a1c58cac02d 100644
@@ -9,7 +9,6 @@
 #include <linux/list.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/vmalloc.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-event.h>
@@ -17,7 +16,6 @@
 #include <media/v4l2-ioctl.h>
 #include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
-#include <media/videobuf2-vmalloc.h>
 #include "vpu.h"
 #include "vpu_defs.h"
 #include "vpu_core.h"
@@ -1642,9 +1640,9 @@ static void vdec_cleanup(struct vpu_inst *inst)
 		vdec->slots = NULL;
 		vdec->slot_count = 0;
 	}
-	vfree(vdec);
+	kfree(vdec);
 	inst->priv = NULL;
-	vfree(inst);
+	kfree(inst);
 }
 
 static void vdec_init_params(struct vdec_t *vdec)
@@ -1909,13 +1907,13 @@ static int vdec_open(struct file *file)
 	struct vdec_t *vdec;
 	int ret;
 
-	inst = vzalloc(sizeof(*inst));
+	inst = kzalloc(sizeof(*inst), GFP_KERNEL);
 	if (!inst)
 		return -ENOMEM;
 
-	vdec = vzalloc(sizeof(*vdec));
+	vdec = kzalloc(sizeof(*vdec), GFP_KERNEL);
 	if (!vdec) {
-		vfree(inst);
+		kfree(inst);
 		return -ENOMEM;
 	}
 
@@ -1923,8 +1921,8 @@ static int vdec_open(struct file *file)
 				    sizeof(*vdec->slots),
 				    GFP_KERNEL | __GFP_ZERO);
 	if (!vdec->slots) {
-		vfree(vdec);
-		vfree(inst);
+		kfree(vdec);
+		kfree(inst);
 		return -ENOMEM;
 	}
 	vdec->slot_count = VDEC_SLOT_CNT_DFT;
drivers/media/platform/amphion/venc.c +9 -11
index aced76401b69..9e5cbc2b0d3f 100644
@@ -13,14 +13,12 @@
 #include <linux/videodev2.h>
 #include <linux/ktime.h>
 #include <linux/rational.h>
-#include <linux/vmalloc.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-mem2mem.h>
 #include <media/v4l2-ioctl.h>
 #include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
-#include <media/videobuf2-vmalloc.h>
 #include "vpu.h"
 #include "vpu_defs.h"
 #include "vpu_core.h"
@@ -844,7 +842,7 @@ static int venc_get_encoded_frames(struct vpu_inst *inst)
 					       v4l2_m2m_dst_buf_remove(inst->fh.m2m_ctx)))
 			break;
 		list_del_init(&frame->list);
-		vfree(frame);
+		kfree(frame);
 	}
 
 	return 0;
@@ -860,7 +858,7 @@ static int venc_frame_encoded(struct vpu_inst *inst, void *arg)
 	if (!info)
 		return -EINVAL;
 	venc = inst->priv;
-	frame = vzalloc(sizeof(*frame));
+	frame = kzalloc(sizeof(*frame), GFP_KERNEL);
 	if (!frame)
 		return -ENOMEM;
 
@@ -912,9 +910,9 @@ static void venc_cleanup(struct vpu_inst *inst)
 		return;
 
 	venc = inst->priv;
-	vfree(venc);
+	kfree(venc);
 	inst->priv = NULL;
-	vfree(inst);
+	kfree(inst);
 }
 
 static int venc_start_session(struct vpu_inst *inst, u32 type)
@@ -1067,7 +1065,7 @@ static void venc_cleanup_frames(struct venc_t *venc)
 
 	list_for_each_entry_safe(frame, tmp, &venc->frames, list) {
 		list_del_init(&frame->list);
-		vfree(frame);
+		kfree(frame);
 	}
 }
 
@@ -1151,7 +1149,7 @@ static int venc_process_capture(struct vpu_inst *inst, struct vb2_buffer *vb)
 		return ret;
 
 	list_del_init(&frame->list);
-	vfree(frame);
+	kfree(frame);
 	return 0;
 }
 
@@ -1309,13 +1307,13 @@ static int venc_open(struct file *file)
 	struct venc_t *venc;
 	int ret;
 
-	inst = vzalloc(sizeof(*inst));
+	inst = kzalloc(sizeof(*inst), GFP_KERNEL);
 	if (!inst)
 		return -ENOMEM;
 
-	venc = vzalloc(sizeof(*venc));
+	venc = kzalloc(sizeof(*venc), GFP_KERNEL);
 	if (!venc) {
-		vfree(inst);
+		kfree(inst);
 		return -ENOMEM;
 	}
 
drivers/media/platform/amphion/vpu_cmds.c +7 -8
index 5695f5c1cb3e..ab69412e0aa7 100644
@@ -13,7 +13,6 @@
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/delay.h>
-#include <linux/vmalloc.h>
 #include "vpu.h"
 #include "vpu_defs.h"
 #include "vpu_cmds.h"
@@ -84,13 +83,13 @@ static struct vpu_cmd_t *vpu_alloc_cmd(struct vpu_inst *inst, u32 id, void *data
 	int i;
 	int ret;
 
-	cmd = vzalloc(sizeof(*cmd));
+	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
 	if (!cmd)
 		return NULL;
 
-	cmd->pkt = vzalloc(sizeof(*cmd->pkt));
+	cmd->pkt = kzalloc(sizeof(*cmd->pkt), GFP_KERNEL);
 	if (!cmd->pkt) {
-		vfree(cmd);
+		kfree(cmd);
 		return NULL;
 	}
 
@@ -98,8 +97,8 @@ static struct vpu_cmd_t *vpu_alloc_cmd(struct vpu_inst *inst, u32 id, void *data
 	ret = vpu_iface_pack_cmd(inst->core, cmd->pkt, inst->id, id, data);
 	if (ret) {
 		dev_err(inst->dev, "iface pack cmd %s fail\n", vpu_id_name(id));
-		vfree(cmd->pkt);
-		vfree(cmd);
+		kfree(cmd->pkt);
+		kfree(cmd);
 		return NULL;
 	}
 	for (i = 0; i < ARRAY_SIZE(vpu_cmd_requests); i++) {
@@ -118,8 +117,8 @@ static void vpu_free_cmd(struct vpu_cmd_t *cmd)
 		return;
 	if (cmd->last_response_cmd)
 		atomic_long_set(cmd->last_response_cmd, cmd->key);
-	vfree(cmd->pkt);
-	vfree(cmd);
+	kfree(cmd->pkt);
+	kfree(cmd);
 }
 
 static int vpu_session_process_cmd(struct vpu_inst *inst, struct vpu_cmd_t *cmd)
drivers/media/platform/amphion/vpu_core.c +4 -7
index 168f0514851e..85cc4a14f8ed 100644
@@ -17,7 +17,6 @@
 #include <linux/pm_runtime.h>
 #include <linux/pm_domain.h>
 #include <linux/firmware.h>
-#include <linux/vmalloc.h>
 #include "vpu.h"
 #include "vpu_defs.h"
 #include "vpu_core.h"
@@ -265,7 +264,7 @@ static int vpu_core_register(struct device *dev, struct vpu_core *core)
 	INIT_WORK(&core->msg_work, vpu_msg_run_work);
 	INIT_DELAYED_WORK(&core->msg_delayed_work, vpu_msg_delayed_work);
 	buffer_size = roundup_pow_of_two(VPU_MSG_BUFFER_SIZE);
-	core->msg_buffer = vzalloc(buffer_size);
+	core->msg_buffer = kzalloc(buffer_size, GFP_KERNEL);
 	if (!core->msg_buffer) {
 		dev_err(core->dev, "failed allocate buffer for fifo\n");
 		ret = -ENOMEM;
@@ -282,10 +281,8 @@ static int vpu_core_register(struct device *dev, struct vpu_core *core)
 
 	return 0;
 error:
-	if (core->msg_buffer) {
-		vfree(core->msg_buffer);
-		core->msg_buffer = NULL;
-	}
+	kfree(core->msg_buffer);
+	core->msg_buffer = NULL;
 	if (core->workqueue) {
 		destroy_workqueue(core->workqueue);
 		core->workqueue = NULL;
@@ -308,7 +305,7 @@ static int vpu_core_unregister(struct device *dev, struct vpu_core *core)
 
 	vpu_core_put_vpu(core);
 	core->vpu = NULL;
-	vfree(core->msg_buffer);
+	kfree(core->msg_buffer);
 	core->msg_buffer = NULL;
 
 	if (core->workqueue) {

base-commit: b70886ff5833cf499e77af77d2324ce8f68b60ce --
2.52.0