All of lore.kernel.org
 help / color / mirror / Atom feed
From: Austin Kim <austindh.kim@gmail.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: mchehab@kernel.org, khilman@baylibre.com, mjourdan@baylibre.com,
	gregkh@linuxfoundation.org, linux-media@vger.kernel.org,
	linux-amlogic@lists.infradead.org, devel@driverdev.osuosl.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: meson: Add NULL check after the call to kmalloc()
Date: Thu, 5 Sep 2019 07:47:39 +0900	[thread overview]
Message-ID: <CADLLry6WYJRWz1mkgO-fvKeRmOhOJQ3S_hXH1sBW11TujT-a1g@mail.gmail.com> (raw)
In-Reply-To: <a9ca05ec-55a9-a58c-267a-334771a1480a@rasmusvillemoes.dk>

2019년 9월 4일 (수) 오후 5:43, Rasmus Villemoes <linux@rasmusvillemoes.dk>님이 작성:
>
> On 04/09/2019 10.22, Austin Kim wrote:
> > If the kmalloc() return NULL, the NULL pointer dereference will occur.
> >       new_ts->ts = ts;
> >
> > Add exception check after the call to kmalloc() is made.
> >
> > Signed-off-by: Austin Kim <austindh.kim@gmail.com>
> > ---
> >  drivers/staging/media/meson/vdec/vdec_helpers.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c
> > index f16948b..e7e56d5 100644
> > --- a/drivers/staging/media/meson/vdec/vdec_helpers.c
> > +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c
> > @@ -206,6 +206,10 @@ void amvdec_add_ts_reorder(struct amvdec_session *sess, u64 ts, u32 offset)
> >       unsigned long flags;
> >
> >       new_ts = kmalloc(sizeof(*new_ts), GFP_KERNEL);
> > +     if (!new_ts) {
> > +             dev_err(sess->core->dev, "Failed to kmalloc()\n");
> > +             return;
> > +     }
> >       new_ts->ts = ts;
> >       new_ts->offset = offset;
>
> No need to printk() on error, AFAIK the mm subsystem should already make
> some noise if an allocation fails.

Thanks for valuable feedback.
BTW, if the kmalloc return NULL, mm subsystem throws error log with 100%?
If no, please share error signature of kernel.

> This is not a proper fix - you need to make the function return an error
> (-ENOMEM) to let the caller know allocation failed, and allow that to
> propagate the error. There's only one caller, which already seems
> capable of returning errors (there's an -EAGAIN), so it shouldn't be
> that hard - though of course one needs to undo what has been done so far.
>
> Also, unrelated to the kmalloc() handling: amvdec_add_ts_reorder() could
> be moved to esparser.c and made static, or at the very least the
> EXPORT_SYMBOL can be removed since vdec_helpers.o is linked in to the
> same module as the sole user. That probably goes for all the
> EXPORT_SYMBOL(amvdec_*).

I agreed with your feedback.
- On memory allocation failure, it should have returned (-ENOMEM)
rather than 'return' statement.
- The call to amvdec_add_ts_reorder() is only made by esparser_queue().

Let me resend the patch if necessary.

Thanks,
Austin Kim
>
> Rasmus

WARNING: multiple messages have this Message-ID (diff)
From: Austin Kim <austindh.kim@gmail.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: mjourdan@baylibre.com, devel@driverdev.osuosl.org,
	khilman@baylibre.com, linux-kernel@vger.kernel.org,
	gregkh@linuxfoundation.org, linux-amlogic@lists.infradead.org,
	mchehab@kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-media@vger.kernel.org
Subject: Re: [PATCH] media: meson: Add NULL check after the call to kmalloc()
Date: Thu, 5 Sep 2019 07:47:39 +0900	[thread overview]
Message-ID: <CADLLry6WYJRWz1mkgO-fvKeRmOhOJQ3S_hXH1sBW11TujT-a1g@mail.gmail.com> (raw)
In-Reply-To: <a9ca05ec-55a9-a58c-267a-334771a1480a@rasmusvillemoes.dk>

2019년 9월 4일 (수) 오후 5:43, Rasmus Villemoes <linux@rasmusvillemoes.dk>님이 작성:
>
> On 04/09/2019 10.22, Austin Kim wrote:
> > If the kmalloc() return NULL, the NULL pointer dereference will occur.
> >       new_ts->ts = ts;
> >
> > Add exception check after the call to kmalloc() is made.
> >
> > Signed-off-by: Austin Kim <austindh.kim@gmail.com>
> > ---
> >  drivers/staging/media/meson/vdec/vdec_helpers.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c
> > index f16948b..e7e56d5 100644
> > --- a/drivers/staging/media/meson/vdec/vdec_helpers.c
> > +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c
> > @@ -206,6 +206,10 @@ void amvdec_add_ts_reorder(struct amvdec_session *sess, u64 ts, u32 offset)
> >       unsigned long flags;
> >
> >       new_ts = kmalloc(sizeof(*new_ts), GFP_KERNEL);
> > +     if (!new_ts) {
> > +             dev_err(sess->core->dev, "Failed to kmalloc()\n");
> > +             return;
> > +     }
> >       new_ts->ts = ts;
> >       new_ts->offset = offset;
>
> No need to printk() on error, AFAIK the mm subsystem should already make
> some noise if an allocation fails.

Thanks for valuable feedback.
BTW, if the kmalloc return NULL, mm subsystem throws error log with 100%?
If no, please share error signature of kernel.

> This is not a proper fix - you need to make the function return an error
> (-ENOMEM) to let the caller know allocation failed, and allow that to
> propagate the error. There's only one caller, which already seems
> capable of returning errors (there's an -EAGAIN), so it shouldn't be
> that hard - though of course one needs to undo what has been done so far.
>
> Also, unrelated to the kmalloc() handling: amvdec_add_ts_reorder() could
> be moved to esparser.c and made static, or at the very least the
> EXPORT_SYMBOL can be removed since vdec_helpers.o is linked in to the
> same module as the sole user. That probably goes for all the
> EXPORT_SYMBOL(amvdec_*).

I agreed with your feedback.
- On memory allocation failure, it should have returned (-ENOMEM)
rather than 'return' statement.
- The call to amvdec_add_ts_reorder() is only made by esparser_queue().

Let me resend the patch if necessary.

Thanks,
Austin Kim
>
> Rasmus
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

WARNING: multiple messages have this Message-ID (diff)
From: Austin Kim <austindh.kim@gmail.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: mjourdan@baylibre.com, devel@driverdev.osuosl.org,
	khilman@baylibre.com, linux-kernel@vger.kernel.org,
	gregkh@linuxfoundation.org, linux-amlogic@lists.infradead.org,
	mchehab@kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-media@vger.kernel.org
Subject: Re: [PATCH] media: meson: Add NULL check after the call to kmalloc()
Date: Thu, 5 Sep 2019 07:47:39 +0900	[thread overview]
Message-ID: <CADLLry6WYJRWz1mkgO-fvKeRmOhOJQ3S_hXH1sBW11TujT-a1g@mail.gmail.com> (raw)
In-Reply-To: <a9ca05ec-55a9-a58c-267a-334771a1480a@rasmusvillemoes.dk>

2019년 9월 4일 (수) 오후 5:43, Rasmus Villemoes <linux@rasmusvillemoes.dk>님이 작성:
>
> On 04/09/2019 10.22, Austin Kim wrote:
> > If the kmalloc() return NULL, the NULL pointer dereference will occur.
> >       new_ts->ts = ts;
> >
> > Add exception check after the call to kmalloc() is made.
> >
> > Signed-off-by: Austin Kim <austindh.kim@gmail.com>
> > ---
> >  drivers/staging/media/meson/vdec/vdec_helpers.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c
> > index f16948b..e7e56d5 100644
> > --- a/drivers/staging/media/meson/vdec/vdec_helpers.c
> > +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c
> > @@ -206,6 +206,10 @@ void amvdec_add_ts_reorder(struct amvdec_session *sess, u64 ts, u32 offset)
> >       unsigned long flags;
> >
> >       new_ts = kmalloc(sizeof(*new_ts), GFP_KERNEL);
> > +     if (!new_ts) {
> > +             dev_err(sess->core->dev, "Failed to kmalloc()\n");
> > +             return;
> > +     }
> >       new_ts->ts = ts;
> >       new_ts->offset = offset;
>
> No need to printk() on error, AFAIK the mm subsystem should already make
> some noise if an allocation fails.

Thanks for valuable feedback.
BTW, if the kmalloc return NULL, mm subsystem throws error log with 100%?
If no, please share error signature of kernel.

> This is not a proper fix - you need to make the function return an error
> (-ENOMEM) to let the caller know allocation failed, and allow that to
> propagate the error. There's only one caller, which already seems
> capable of returning errors (there's an -EAGAIN), so it shouldn't be
> that hard - though of course one needs to undo what has been done so far.
>
> Also, unrelated to the kmalloc() handling: amvdec_add_ts_reorder() could
> be moved to esparser.c and made static, or at the very least the
> EXPORT_SYMBOL can be removed since vdec_helpers.o is linked in to the
> same module as the sole user. That probably goes for all the
> EXPORT_SYMBOL(amvdec_*).

I agreed with your feedback.
- On memory allocation failure, it should have returned (-ENOMEM)
rather than 'return' statement.
- The call to amvdec_add_ts_reorder() is only made by esparser_queue().

Let me resend the patch if necessary.

Thanks,
Austin Kim
>
> Rasmus

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Austin Kim <austindh.kim@gmail.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: mjourdan@baylibre.com, devel@driverdev.osuosl.org,
	khilman@baylibre.com, linux-kernel@vger.kernel.org,
	gregkh@linuxfoundation.org, linux-amlogic@lists.infradead.org,
	mchehab@kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-media@vger.kernel.org
Subject: Re: [PATCH] media: meson: Add NULL check after the call to kmalloc()
Date: Thu, 5 Sep 2019 07:47:39 +0900	[thread overview]
Message-ID: <CADLLry6WYJRWz1mkgO-fvKeRmOhOJQ3S_hXH1sBW11TujT-a1g@mail.gmail.com> (raw)
In-Reply-To: <a9ca05ec-55a9-a58c-267a-334771a1480a@rasmusvillemoes.dk>

2019년 9월 4일 (수) 오후 5:43, Rasmus Villemoes <linux@rasmusvillemoes.dk>님이 작성:
>
> On 04/09/2019 10.22, Austin Kim wrote:
> > If the kmalloc() return NULL, the NULL pointer dereference will occur.
> >       new_ts->ts = ts;
> >
> > Add exception check after the call to kmalloc() is made.
> >
> > Signed-off-by: Austin Kim <austindh.kim@gmail.com>
> > ---
> >  drivers/staging/media/meson/vdec/vdec_helpers.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c
> > index f16948b..e7e56d5 100644
> > --- a/drivers/staging/media/meson/vdec/vdec_helpers.c
> > +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c
> > @@ -206,6 +206,10 @@ void amvdec_add_ts_reorder(struct amvdec_session *sess, u64 ts, u32 offset)
> >       unsigned long flags;
> >
> >       new_ts = kmalloc(sizeof(*new_ts), GFP_KERNEL);
> > +     if (!new_ts) {
> > +             dev_err(sess->core->dev, "Failed to kmalloc()\n");
> > +             return;
> > +     }
> >       new_ts->ts = ts;
> >       new_ts->offset = offset;
>
> No need to printk() on error, AFAIK the mm subsystem should already make
> some noise if an allocation fails.

Thanks for valuable feedback.
BTW, if the kmalloc return NULL, mm subsystem throws error log with 100%?
If no, please share error signature of kernel.

> This is not a proper fix - you need to make the function return an error
> (-ENOMEM) to let the caller know allocation failed, and allow that to
> propagate the error. There's only one caller, which already seems
> capable of returning errors (there's an -EAGAIN), so it shouldn't be
> that hard - though of course one needs to undo what has been done so far.
>
> Also, unrelated to the kmalloc() handling: amvdec_add_ts_reorder() could
> be moved to esparser.c and made static, or at the very least the
> EXPORT_SYMBOL can be removed since vdec_helpers.o is linked in to the
> same module as the sole user. That probably goes for all the
> EXPORT_SYMBOL(amvdec_*).

I agreed with your feedback.
- On memory allocation failure, it should have returned (-ENOMEM)
rather than 'return' statement.
- The call to amvdec_add_ts_reorder() is only made by esparser_queue().

Let me resend the patch if necessary.

Thanks,
Austin Kim
>
> Rasmus

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2019-09-04 22:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-04  8:22 [PATCH] media: meson: Add NULL check after the call to kmalloc() Austin Kim
2019-09-04  8:22 ` Austin Kim
2019-09-04  8:22 ` Austin Kim
2019-09-04  8:22 ` Austin Kim
2019-09-04  8:43 ` Rasmus Villemoes
2019-09-04  8:43   ` Rasmus Villemoes
2019-09-04  8:43   ` Rasmus Villemoes
2019-09-04  8:43   ` Rasmus Villemoes
2019-09-04 22:47   ` Austin Kim [this message]
2019-09-04 22:47     ` Austin Kim
2019-09-04 22:47     ` Austin Kim
2019-09-04 22:47     ` Austin Kim
2019-09-04  8:45 ` Greg KH
2019-09-04  8:45   ` Greg KH
2019-09-04  8:45   ` Greg KH
2019-09-04  8:45   ` Greg KH
2019-09-04 22:39   ` Austin Kim
2019-09-04 22:39     ` Austin Kim
2019-09-04 22:39     ` Austin Kim
2019-09-04 22:39     ` Austin Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADLLry6WYJRWz1mkgO-fvKeRmOhOJQ3S_hXH1sBW11TujT-a1g@mail.gmail.com \
    --to=austindh.kim@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=khilman@baylibre.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mchehab@kernel.org \
    --cc=mjourdan@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.