]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
media: vidtv: Check for null return of vzalloc
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Fri, 14 Jan 2022 06:28:40 +0000 (07:28 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 12:38:31 +0000 (14:38 +0200)
BugLink: https://bugs.launchpad.net/bugs/1969110
[ Upstream commit e6a21a14106d9718aa4f8e115b1e474888eeba44 ]

As the possible failure of the vzalloc(), e->encoder_buf might be NULL.
Therefore, it should be better to check it in order
to guarantee the success of the initialization.
If fails, we need to free not only 'e' but also 'e->name'.
Also, if the allocation for ctx fails, we need to free 'e->encoder_buf'
else.

Fixes: f90cf6079bf6 ("media: vidtv: add a bridge driver")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 9dd2fd7a1f84c947561af29424c5ddcecfcf2cbe)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
drivers/media/test-drivers/vidtv/vidtv_s302m.c

index d79b65854627cc18c60c5172430c40369e687c68..4676083cee3b8aa58f01845c9839d91505d24850 100644 (file)
@@ -455,6 +455,9 @@ struct vidtv_encoder
                e->name = kstrdup(args.name, GFP_KERNEL);
 
        e->encoder_buf = vzalloc(VIDTV_S302M_BUF_SZ);
+       if (!e->encoder_buf)
+               goto out_kfree_e;
+
        e->encoder_buf_sz = VIDTV_S302M_BUF_SZ;
        e->encoder_buf_offset = 0;
 
@@ -467,10 +470,8 @@ struct vidtv_encoder
        e->is_video_encoder = false;
 
        ctx = kzalloc(priv_sz, GFP_KERNEL);
-       if (!ctx) {
-               kfree(e);
-               return NULL;
-       }
+       if (!ctx)
+               goto out_kfree_buf;
 
        e->ctx = ctx;
        ctx->last_duration = 0;
@@ -498,6 +499,14 @@ struct vidtv_encoder
        e->next = NULL;
 
        return e;
+
+out_kfree_buf:
+       kfree(e->encoder_buf);
+
+out_kfree_e:
+       kfree(e->name);
+       kfree(e);
+       return NULL;
 }
 
 void vidtv_s302m_encoder_destroy(struct vidtv_encoder *e)