2017-09-08 12:29:15

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/3] [media] DaVinci-VPBE-Display: Adjustments for some function implementations

From: Markus Elfring <[email protected]>
Date: Fri, 8 Sep 2017 14:12:10 +0200

Three update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Delete an error message for a failed memory allocation in init_vpbe_layer()
Improve a size determination in two functions
Adjust 12 checks for null pointers

drivers/media/platform/davinci/vpbe_display.c | 37 +++++++++++----------------
1 file changed, 15 insertions(+), 22 deletions(-)

--
2.14.1


2017-09-08 12:31:24

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/3] [media] DaVinci-VPBE-Display: Delete an error message for a failed memory allocation in init_vpbe_layer()

From: Markus Elfring <[email protected]>
Date: Thu, 7 Sep 2017 22:37:16 +0200

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/platform/davinci/vpbe_display.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index 13d027031ff0..5b6fc550736b 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -1313,7 +1313,6 @@ static int init_vpbe_layer(int i, struct vpbe_display *disp_dev,
- if (!disp_dev->dev[i]) {
- printk(KERN_ERR "ran out of memory\n");
+ if (!disp_dev->dev[i])
return -ENOMEM;
- }
+
spin_lock_init(&disp_dev->dev[i]->irqlock);
mutex_init(&disp_dev->dev[i]->opslock);

--
2.14.1

2017-09-08 12:32:37

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/3] [media] DaVinci-VPBE-Display: Improve a size determination in two functions

From: Markus Elfring <[email protected]>
Date: Fri, 8 Sep 2017 10:50:32 +0200

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/platform/davinci/vpbe_display.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index 5b6fc550736b..afe31900f5de 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -1305,9 +1305,5 @@ static int init_vpbe_layer(int i, struct vpbe_display *disp_dev,
struct video_device *vbd = NULL;

/* Allocate memory for four plane display objects */
-
- disp_dev->dev[i] =
- kzalloc(sizeof(struct vpbe_layer), GFP_KERNEL);
-
- /* If memory allocation fails, return error */
+ disp_dev->dev[i] = kzalloc(sizeof(*disp_dev->dev[i]), GFP_KERNEL);
if (!disp_dev->dev[i])
@@ -1396,6 +1392,5 @@ static int vpbe_display_probe(struct platform_device *pdev)

printk(KERN_DEBUG "vpbe_display_probe\n");
/* Allocate memory for vpbe_display */
- disp_dev = devm_kzalloc(&pdev->dev, sizeof(struct vpbe_display),
- GFP_KERNEL);
+ disp_dev = devm_kzalloc(&pdev->dev, sizeof(*disp_dev), GFP_KERNEL);
if (!disp_dev)
--
2.14.1

2017-09-08 12:33:38

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/3] [media] DaVinci-VPBE-Display: Adjust 12 checks for null pointers

From: Markus Elfring <[email protected]>
Date: Fri, 8 Sep 2017 14:00:20 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script “checkpatch.pl” pointed information out like the following.

Comparison to NULL could be written …

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/media/platform/davinci/vpbe_display.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index afe31900f5de..6aabd21fe69f 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -122,7 +122,7 @@ static irqreturn_t venc_isr(int irq, void *arg)
int fid;
int i;

- if ((NULL == arg) || (NULL == disp_dev->dev[0]))
+ if (!arg || !disp_dev->dev[0])
return IRQ_HANDLED;

if (venc_is_second_field(disp_dev))
@@ -337,10 +337,10 @@ static void vpbe_stop_streaming(struct vb2_queue *vq)
vb2_buffer_done(&layer->cur_frm->vb.vb2_buf,
VB2_BUF_STATE_ERROR);
} else {
- if (layer->cur_frm != NULL)
+ if (layer->cur_frm)
vb2_buffer_done(&layer->cur_frm->vb.vb2_buf,
VB2_BUF_STATE_ERROR);
- if (layer->next_frm != NULL)
+ if (layer->next_frm)
vb2_buffer_done(&layer->next_frm->vb.vb2_buf,
VB2_BUF_STATE_ERROR);
}
@@ -947,7 +947,7 @@ static int vpbe_display_s_std(struct file *file, void *priv,
if (vb2_is_busy(&layer->buffer_queue))
return -EBUSY;

- if (NULL != vpbe_dev->ops.s_std) {
+ if (vpbe_dev->ops.s_std) {
ret = vpbe_dev->ops.s_std(vpbe_dev, std_id);
if (ret) {
v4l2_err(&vpbe_dev->v4l2_dev,
@@ -1000,8 +1000,7 @@ static int vpbe_display_enum_output(struct file *file, void *priv,
v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_OUTPUT\n");

/* Enumerate outputs */
-
- if (NULL == vpbe_dev->ops.enum_outputs)
+ if (!vpbe_dev->ops.enum_outputs)
return -EINVAL;

ret = vpbe_dev->ops.enum_outputs(vpbe_dev, output);
@@ -1030,7 +1029,7 @@ static int vpbe_display_s_output(struct file *file, void *priv,
if (vb2_is_busy(&layer->buffer_queue))
return -EBUSY;

- if (NULL == vpbe_dev->ops.set_output)
+ if (!vpbe_dev->ops.set_output)
return -EINVAL;

ret = vpbe_dev->ops.set_output(vpbe_dev, i);
@@ -1077,7 +1076,7 @@ vpbe_display_enum_dv_timings(struct file *file, void *priv,
v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "VIDIOC_ENUM_DV_TIMINGS\n");

/* Enumerate outputs */
- if (NULL == vpbe_dev->ops.enum_dv_timings)
+ if (!vpbe_dev->ops.enum_dv_timings)
return -EINVAL;

ret = vpbe_dev->ops.enum_dv_timings(vpbe_dev, timings);
@@ -1292,7 +1291,7 @@ static int vpbe_device_get(struct device *dev, void *data)
if (strcmp("vpbe_controller", pdev->name) == 0)
vpbe_disp->vpbe_dev = platform_get_drvdata(pdev);

- if (strstr(pdev->name, "vpbe-osd") != NULL)
+ if (strstr(pdev->name, "vpbe-osd"))
vpbe_disp->osd_device = platform_get_drvdata(pdev);

return 0;
@@ -1408,7 +1407,7 @@ static int vpbe_display_probe(struct platform_device *pdev)

v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev;
/* Initialize the vpbe display controller */
- if (NULL != disp_dev->vpbe_dev->ops.initialize) {
+ if (disp_dev->vpbe_dev->ops.initialize) {
err = disp_dev->vpbe_dev->ops.initialize(&pdev->dev,
disp_dev->vpbe_dev);
if (err) {
@@ -1476,7 +1475,7 @@ static int vpbe_display_probe(struct platform_device *pdev)
probe_out:
for (k = 0; k < VPBE_DISPLAY_MAX_DEVICES; k++) {
/* Unregister video device */
- if (disp_dev->dev[k] != NULL) {
+ if (disp_dev->dev[k]) {
video_unregister_device(&disp_dev->dev[k]->video_dev);
kfree(disp_dev->dev[k]);
}
@@ -1498,7 +1497,7 @@ static int vpbe_display_remove(struct platform_device *pdev)
v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_remove\n");

/* deinitialize the vpbe display controller */
- if (NULL != vpbe_dev->ops.deinitialize)
+ if (vpbe_dev->ops.deinitialize)
vpbe_dev->ops.deinitialize(&pdev->dev, vpbe_dev);
/* un-register device */
for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
--
2.14.1

2017-09-11 13:21:15

by Lad, Prabhakar

[permalink] [raw]
Subject: Re: [PATCH 1/3] [media] DaVinci-VPBE-Display: Delete an error message for a failed memory allocation in init_vpbe_layer()

On Fri, Sep 8, 2017 at 1:31 PM, SF Markus Elfring
<[email protected]> wrote:
>
> From: Markus Elfring <[email protected]>
> Date: Thu, 7 Sep 2017 22:37:16 +0200
>
> Omit an extra message for a memory allocation failure in this function.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <[email protected]>

Acked-by: Lad, Prabhakar <[email protected]>

Cheers,
--Prabhakar Lad

2017-09-11 13:24:19

by Lad, Prabhakar

[permalink] [raw]
Subject: Re: [PATCH 2/3] [media] DaVinci-VPBE-Display: Improve a size determination in two functions

On Fri, Sep 8, 2017 at 1:32 PM, SF Markus Elfring
<[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Fri, 8 Sep 2017 10:50:32 +0200
>
> Replace the specification of data structures by pointer dereferences
> as the parameter for the operator "sizeof" to make the corresponding size
> determination a bit safer according to the Linux coding style convention.
>
> Signed-off-by: Markus Elfring <[email protected]>

Acked-by: Lad, Prabhakar <[email protected]>

Cheers,
--Prabhakar Lad

2017-09-11 13:27:07

by Lad, Prabhakar

[permalink] [raw]
Subject: Re: [PATCH 3/3] [media] DaVinci-VPBE-Display: Adjust 12 checks for null pointers

On Fri, Sep 8, 2017 at 1:33 PM, SF Markus Elfring
<[email protected]> wrote:
> From: Markus Elfring <[email protected]>
> Date: Fri, 8 Sep 2017 14:00:20 +0200
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> The script “checkpatch.pl” pointed information out like the following.
>
> Comparison to NULL could be written …
>
> Thus fix the affected source code places.
>
> Signed-off-by: Markus Elfring <[email protected]>

Acked-by: Lad, Prabhakar <[email protected]>

Cheers,
--Prabhakar Lad