linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: meson: add missing allocation failure check on new_buf
@ 2019-12-04 14:11 Colin King
  2019-12-05  2:39 ` Kevin Hilman
  2019-12-05  8:06 ` Sergey Senozhatsky
  0 siblings, 2 replies; 4+ messages in thread
From: Colin King @ 2019-12-04 14:11 UTC (permalink / raw)
  To: Maxime Jourdan, Mauro Carvalho Chehab, Greg Kroah-Hartman,
	Kevin Hilman, Hans Verkuil, linux-media, linux-amlogic, devel,
	linux-arm-kernel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently if the allocation of new_buf fails then a null pointer
dereference occurs when assiging new_buf->vb. Avoid this by returning
early on a memory allocation failure as there is not much more can
be done at this point.

Addresses-Coverity: ("Dereference null return")
Fixes: 3e7f51bd9607 ("media: meson: add v4l2 m2m video decoder driver")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/staging/media/meson/vdec/vdec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/media/meson/vdec/vdec.c b/drivers/staging/media/meson/vdec/vdec.c
index 0a1a04fd5d13..8dd1396909d7 100644
--- a/drivers/staging/media/meson/vdec/vdec.c
+++ b/drivers/staging/media/meson/vdec/vdec.c
@@ -133,6 +133,8 @@ vdec_queue_recycle(struct amvdec_session *sess, struct vb2_buffer *vb)
 	struct amvdec_buffer *new_buf;
 
 	new_buf = kmalloc(sizeof(*new_buf), GFP_KERNEL);
+	if (!new_buf)
+		return;
 	new_buf->vb = vb;
 
 	mutex_lock(&sess->bufs_recycle_lock);
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: meson: add missing allocation failure check on new_buf
  2019-12-04 14:11 [PATCH] media: meson: add missing allocation failure check on new_buf Colin King
@ 2019-12-05  2:39 ` Kevin Hilman
  2019-12-05  8:06 ` Sergey Senozhatsky
  1 sibling, 0 replies; 4+ messages in thread
From: Kevin Hilman @ 2019-12-05  2:39 UTC (permalink / raw)
  To: Colin King, Maxime Jourdan, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Hans Verkuil, linux-media, linux-amlogic,
	devel, linux-arm-kernel
  Cc: kernel-janitors, linux-kernel

Colin King <colin.king@canonical.com> writes:

> From: Colin Ian King <colin.king@canonical.com>
>
> Currently if the allocation of new_buf fails then a null pointer
> dereference occurs when assiging new_buf->vb. Avoid this by returning
> early on a memory allocation failure as there is not much more can
> be done at this point.
>
> Addresses-Coverity: ("Dereference null return")
> Fixes: 3e7f51bd9607 ("media: meson: add v4l2 m2m video decoder driver")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Reviewed-by: Kevin Hilman <khilman@baylibre.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: meson: add missing allocation failure check on new_buf
  2019-12-04 14:11 [PATCH] media: meson: add missing allocation failure check on new_buf Colin King
  2019-12-05  2:39 ` Kevin Hilman
@ 2019-12-05  8:06 ` Sergey Senozhatsky
  2019-12-13  7:47   ` Maxime Jourdan
  1 sibling, 1 reply; 4+ messages in thread
From: Sergey Senozhatsky @ 2019-12-05  8:06 UTC (permalink / raw)
  To: Colin King
  Cc: Maxime Jourdan, Mauro Carvalho Chehab, Greg Kroah-Hartman,
	Kevin Hilman, Hans Verkuil, linux-media, linux-amlogic, devel,
	linux-arm-kernel, kernel-janitors, linux-kernel

On (19/12/04 14:11), Colin King wrote:
[..]
> diff --git a/drivers/staging/media/meson/vdec/vdec.c b/drivers/staging/media/meson/vdec/vdec.c
> index 0a1a04fd5d13..8dd1396909d7 100644
> --- a/drivers/staging/media/meson/vdec/vdec.c
> +++ b/drivers/staging/media/meson/vdec/vdec.c
> @@ -133,6 +133,8 @@ vdec_queue_recycle(struct amvdec_session *sess, struct vb2_buffer *vb)
>  	struct amvdec_buffer *new_buf;
>
>  	new_buf = kmalloc(sizeof(*new_buf), GFP_KERNEL);
> +	if (!new_buf)
> +		return;
>  	new_buf->vb = vb;

So the buffer is not getting recycled? IOW is leaked?

	-ss

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: meson: add missing allocation failure check on new_buf
  2019-12-05  8:06 ` Sergey Senozhatsky
@ 2019-12-13  7:47   ` Maxime Jourdan
  0 siblings, 0 replies; 4+ messages in thread
From: Maxime Jourdan @ 2019-12-13  7:47 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Colin King, Mauro Carvalho Chehab, Greg Kroah-Hartman,
	Kevin Hilman, Hans Verkuil, Linux Media Mailing List,
	linux-amlogic, devel, linux-arm-kernel, kernel-janitors,
	Linux Kernel Mailing List

On Thu, Dec 5, 2019 at 9:06 AM Sergey Senozhatsky
<sergey.senozhatsky.work@gmail.com> wrote:
>
> On (19/12/04 14:11), Colin King wrote:
> [..]
> > diff --git a/drivers/staging/media/meson/vdec/vdec.c b/drivers/staging/media/meson/vdec/vdec.c
> > index 0a1a04fd5d13..8dd1396909d7 100644
> > --- a/drivers/staging/media/meson/vdec/vdec.c
> > +++ b/drivers/staging/media/meson/vdec/vdec.c
> > @@ -133,6 +133,8 @@ vdec_queue_recycle(struct amvdec_session *sess, struct vb2_buffer *vb)
> >       struct amvdec_buffer *new_buf;
> >
> >       new_buf = kmalloc(sizeof(*new_buf), GFP_KERNEL);
> > +     if (!new_buf)
> > +             return;
> >       new_buf->vb = vb;

Thanks for the patch Colin.

>
> So the buffer is not getting recycled? IOW is leaked?
>
>         -ss

The "recycle" mechanism in the meson vdec is a way to tell the
firmware that "hey, both userspace and kernel are done using this
buffer, you can start using it again".

Not queuing it for recycling means that the firmware won't use this
buffer again, it's not desirable of course, but if there is no memory
left to allocate a simple list element then there are bigger problems
at hand.

Either way, failing this allocation and returning instantly doesn't
leak anything or do any damage kernel-side.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-13  7:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-04 14:11 [PATCH] media: meson: add missing allocation failure check on new_buf Colin King
2019-12-05  2:39 ` Kevin Hilman
2019-12-05  8:06 ` Sergey Senozhatsky
2019-12-13  7:47   ` Maxime Jourdan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).