Skip to contentSkip to conversation

zr364xx: Adjustments for some function implementations

PATCH In review SF Markus Elfring 2 participants 6 messages Aug 29, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover zr364xx: Adjustments for some function implementations

From: Markus Elfring <[email protected]>
Date: Tue, 29 Aug 2017 07:17:07 +0200

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

Markus Elfring (4):
Delete an error message for a failed memory allocation in two functions Improve a size determination in zr364xx_probe()
Adjust ten checks for null pointers
Fix a typo in a comment line of the file header

 drivers/media/usb/zr364xx/zr364xx.c | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)
Signature · 1 line
2.14.1
#1 lore raw

PATCH 1/4 zr364xx: Delete an error message for a failed memory allocation in two functions

From: Markus Elfring <[email protected]>
Date: Mon, 28 Aug 2017 22:23:56 +0200

Omit an extra message for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

---
 drivers/media/usb/zr364xx/zr364xx.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/media/usb/zr364xx/zr364xx.c +2 -6
index efdcd5bd6a4c..97af697dcc81 100644
@@ -212,7 +212,5 @@ static int send_control_msg(struct usb_device *udev, u8 request, u16 value,
-	if (!transfer_buffer) {
-		dev_err(&udev->dev, "kmalloc(%d) failed\n", size);
+	if (!transfer_buffer)
 		return -ENOMEM;
-	}
 
 	memcpy(transfer_buffer, cp, size);
 
@@ -1427,7 +1425,5 @@ static int zr364xx_probe(struct usb_interface *intf,
-	if (cam = NULL) {
-		dev_err(&udev->dev, "cam: out of memory !\n");
+	if (!cam)
 		return -ENOMEM;
-	}
 
 	cam->v4l2_dev.release = zr364xx_release;
 	err = v4l2_device_register(&intf->dev, &cam->v4l2_dev);
Signature · 1 line
2.14.1
#2 lore raw

PATCH 2/4 zr364xx: Improve a size determination in zr364xx_probe()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 28 Aug 2017 22:28:02 +0200

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

This issue was detected by using the Coccinelle software.

---
 drivers/media/usb/zr364xx/zr364xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/zr364xx/zr364xx.c +1 -1
index 97af697dcc81..37cd6e20e68a 100644
@@ -1421,7 +1421,7 @@ static int zr364xx_probe(struct usb_interface *intf,
 		 le16_to_cpu(udev->descriptor.idVendor),
 		 le16_to_cpu(udev->descriptor.idProduct));
 
-	cam = kzalloc(sizeof(struct zr364xx_camera), GFP_KERNEL);
+	cam = kzalloc(sizeof(*cam), GFP_KERNEL);
 	if (!cam)
 		return -ENOMEM;
 
Signature · 1 line
2.14.1
#3 lore raw

PATCH 3/4 zr364xx: Adjust ten checks for null pointers

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 28 Aug 2017 22:40:47 +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.

---
 drivers/media/usb/zr364xx/zr364xx.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/media/usb/zr364xx/zr364xx.c +11 -11
index 37cd6e20e68a..4cc6d2a9d91f 100644
@@ -385,9 +385,9 @@ static int buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
 						  vb);
 	int rc;
 
-	DBG("%s, field=%d, fmt name = %s\n", __func__, field, cam->fmt != NULL ?
-	    cam->fmt->name : "");
-	if (cam->fmt = NULL)
+	DBG("%s, field=%d, fmt name = %s\n", __func__, field,
+	    cam->fmt ? cam->fmt->name : "");
+	if (!cam->fmt)
 		return -EINVAL;
 
 	buf->vb.size = cam->width * cam->height * (cam->fmt->depth >> 3);
@@ -787,7 +787,7 @@ static int zr364xx_vidioc_try_fmt_vid_cap(struct file *file, void *priv,
 	struct zr364xx_camera *cam = video_drvdata(file);
 	char pixelformat_name[5];
 
-	if (cam = NULL)
+	if (!cam)
 		return -ENODEV;
 
 	if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG) {
@@ -817,7 +817,7 @@ static int zr364xx_vidioc_g_fmt_vid_cap(struct file *file, void *priv,
 {
 	struct zr364xx_camera *cam;
 
-	if (file = NULL)
+	if (!file)
 		return -ENODEV;
 	cam = video_drvdata(file);
 
@@ -979,13 +979,13 @@ static void read_pipe_completion(struct urb *purb)
 
 	pipe_info = purb->context;
 	_DBG("%s %p, status %d\n", __func__, purb, purb->status);
-	if (pipe_info = NULL) {
+	if (!pipe_info) {
 		printk(KERN_ERR KBUILD_MODNAME ": no context!\n");
 		return;
 	}
 
 	cam = pipe_info->cam;
-	if (cam = NULL) {
+	if (!cam) {
 		printk(KERN_ERR KBUILD_MODNAME ": no context!\n");
 		return;
 	}
@@ -1069,7 +1069,7 @@ static void zr364xx_stop_readpipe(struct zr364xx_camera *cam)
 {
 	struct zr364xx_pipeinfo *pipe_info;
 
-	if (cam = NULL) {
+	if (!cam) {
 		printk(KERN_ERR KBUILD_MODNAME ": invalid device\n");
 		return;
 	}
@@ -1273,7 +1273,7 @@ static int zr364xx_mmap(struct file *file, struct vm_area_struct *vma)
 	struct zr364xx_camera *cam = video_drvdata(file);
 	int ret;
 
-	if (cam = NULL) {
+	if (!cam) {
 		DBG("%s: cam = NULL\n", __func__);
 		return -ENODEV;
 	}
@@ -1357,7 +1357,7 @@ static int zr364xx_board_init(struct zr364xx_camera *cam)
 
 	pipe->transfer_buffer = kzalloc(pipe->transfer_size,
 					GFP_KERNEL);
-	if (pipe->transfer_buffer = NULL) {
+	if (!pipe->transfer_buffer) {
 		DBG("out of memory!\n");
 		return -ENOMEM;
 	}
@@ -1373,7 +1373,7 @@ static int zr364xx_board_init(struct zr364xx_camera *cam)
 		DBG("valloc %p, idx %lu, pdata %p\n",
 			&cam->buffer.frame[i], i,
 			cam->buffer.frame[i].lpvbits);
-		if (cam->buffer.frame[i].lpvbits = NULL) {
+		if (!cam->buffer.frame[i].lpvbits) {
 			printk(KERN_INFO KBUILD_MODNAME ": out of memory. Using less frames\n");
 			break;
 		}
Signature · 1 line
2.14.1
#4 lore raw

PATCH 4/4 zr364xx: Fix a typo in a comment line of the file header

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 28 Aug 2017 22:46:30 +0200

Fix a word in this description.

---
 drivers/media/usb/zr364xx/zr364xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/zr364xx/zr364xx.c +1 -1
index 4cc6d2a9d91f..4ccf71d8b608 100644
@@ -2,7 +2,7 @@
  * Zoran 364xx based USB webcam module version 0.73
  *
  * Allows you to use your USB webcam with V4L2 applications
- * This is still in heavy developpement !
+ * This is still in heavy development!
  *
  * Copyright (C) 2004  Antoine Jacquet <[email protected]>
  * http://royale.zerezo.com/zr364xx/
Signature · 1 line
2.14.1
#5 lore raw

Re: [PATCH 4/4] [media] zr364xx: Fix a typo in a comment line of the file header

Quoted 15 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 28 Aug 2017 22:46:30 +0200

Fix a word in this description.

---
 drivers/media/usb/zr364xx/zr364xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/zr364xx/zr364xx.c +0 -0
index 4cc6d2a9d91f..4ccf71d8b608 100644

drivers/media/usb/zr364xx/zr364xx.c line 5

Quoted 5 lines
drivers/media/usb/zr364xx/zr364xx.c +1 -1
@@ -2,7 +2,7 @@
  * Zoran 364xx based USB webcam module version 0.73
  *
  * Allows you to use your USB webcam with V4L2 applications
- * This is still in heavy developpement !
+ * This is still in heavy development!

There is almost no development being done here.
Just delete the line.