2023-04-11 05:56:35

by Irui Wang (王瑞)

[permalink] [raw]
Subject: [PATCH v2, 0/2] fix coverity issues in encoder driver

two coverity issues in encoder driver, submit two changes for fix them.

changes compared with v1:
- separate into two changes.
---

Irui Wang (2):
media: mediatek: vcodec: make sure array index is in valid range
media: mediatek: vcodec: make sure pointer isn't NULL before used

.../platform/mediatek/vcodec/mtk_vcodec_enc.c | 2 +-
.../mediatek/vcodec/mtk_vcodec_enc_drv.c | 16 ++++++++++++----
2 files changed, 13 insertions(+), 5 deletions(-)

--
2.18.0


2023-04-11 05:56:36

by Irui Wang (王瑞)

[permalink] [raw]
Subject: [PATCH v2, 2/2] media: mediatek: vcodec: make sure pointer isn't NULL before used

CERT-C Expression check:
Dereferencing buf, which is known to be NULL, check buf is not NULL
before used.

Signed-off-by: Irui Wang <[email protected]>
---
drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
index d65800a3b89d..db65e77bd373 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
@@ -943,7 +943,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
* FIXME: This check is not needed as only active buffers
* can be marked as done.
*/
- if (buf->state == VB2_BUF_STATE_ACTIVE) {
+ if (buf && buf->state == VB2_BUF_STATE_ACTIVE) {
mtk_v4l2_debug(0, "[%d] id=%d, type=%d, %d -> VB2_BUF_STATE_QUEUED",
ctx->id, i, q->type,
(int)buf->state);
--
2.18.0

2023-04-11 06:35:20

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: Re: [PATCH v2, 0/2] fix coverity issues in encoder driver

Hi Irui,

On Tue, 2023-04-11 at 13:54 +0800, Irui Wang wrote:
> two coverity issues in encoder driver, submit two changes for fix
> them.
>
Maybe better:

Submit two changes to fix two kind of coverity issues in encoder
driver.

Best Regards,
Yunfei Dong
> changes compared with v1:
> - separate into two changes.
> ---
>
> Irui Wang (2):
> media: mediatek: vcodec: make sure array index is in valid range
> media: mediatek: vcodec: make sure pointer isn't NULL before used
>
> .../platform/mediatek/vcodec/mtk_vcodec_enc.c | 2 +-
> .../mediatek/vcodec/mtk_vcodec_enc_drv.c | 16 ++++++++++++
> ----
> 2 files changed, 13 insertions(+), 5 deletions(-)
>

2023-04-11 07:23:35

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: Re: [PATCH v2, 2/2] media: mediatek: vcodec: make sure pointer isn't NULL before used

Hi Irui,

On Tue, 2023-04-11 at 13:54 +0800, Irui Wang wrote:
> CERT-C Expression check:
> Dereferencing buf, which is known to be NULL, check buf is not NULL
> before used.
>
Whether 'dereferencing buf' is one kind of CERT-C Expression check?
You can re-write commit message and subject.

CERT-C Expression check (Dereferencing buf):
Making sure the pointer is not NULL before to be used.

Best Regards,
Yunfei Dong
> Signed-off-by: Irui Wang <[email protected]>
> ---
> drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
> b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
> index d65800a3b89d..db65e77bd373 100644
> --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
> +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
> @@ -943,7 +943,7 @@ static int vb2ops_venc_start_streaming(struct
> vb2_queue *q, unsigned int count)
> * FIXME: This check is not needed as only active
> buffers
> * can be marked as done.
> */
> - if (buf->state == VB2_BUF_STATE_ACTIVE) {
> + if (buf && buf->state == VB2_BUF_STATE_ACTIVE) {
> mtk_v4l2_debug(0, "[%d] id=%d, type=%d, %d ->
> VB2_BUF_STATE_QUEUED",
> ctx->id, i, q->type,
> (int)buf->state);

2023-04-11 07:42:11

by Irui Wang (王瑞)

[permalink] [raw]
Subject: Re: [PATCH v2, 2/2] media: mediatek: vcodec: make sure pointer isn't NULL before used

Dear Yunfei,

Thanks for your reviewing.

On Tue, 2023-04-11 at 07:22 +0000, Yunfei Dong (董云飞) wrote:
> Hi Irui,
>
> On Tue, 2023-04-11 at 13:54 +0800, Irui Wang wrote:
> > CERT-C Expression check:
> > Dereferencing buf, which is known to be NULL, check buf is not NULL
> > before used.
> >
>
> Whether 'dereferencing buf' is one kind of CERT-C Expression check?
> You can re-write commit message and subject.
>
> CERT-C Expression check (Dereferencing buf):
no, 'buf' is the used variable name, this coverity is 'Dereference null
return value(NULL RETURNS)' .
> Making sure the pointer is not NULL before to be used.
>
> Best Regards,
> Yunfei Dong

Thanks
Best Regards
> > Signed-off-by: Irui Wang <[email protected]>
> > ---
> > drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git
> > a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
> > b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
> > index d65800a3b89d..db65e77bd373 100644
> > --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
> > +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
> > @@ -943,7 +943,7 @@ static int vb2ops_venc_start_streaming(struct
> > vb2_queue *q, unsigned int count)
> > * FIXME: This check is not needed as only active
> > buffers
> > * can be marked as done.
> > */
> > - if (buf->state == VB2_BUF_STATE_ACTIVE) {
> > + if (buf && buf->state == VB2_BUF_STATE_ACTIVE) {
> > mtk_v4l2_debug(0, "[%d] id=%d, type=%d, %d ->
> > VB2_BUF_STATE_QUEUED",
> > ctx->id, i, q->type,
> > (int)buf->state);