Skip to contentSkip to conversation

cx18: Adjustments for seven function implementations

PATCH New SF Markus Elfring 1 participant 4 messages Sep 2, 2017

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

cover cx18: Adjustments for seven function implementations

From: Markus Elfring <[email protected]>
Date: Sat, 2 Sep 2017 20:03:45 +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 Improve a size determination
Adjust ten checks for null pointers

 drivers/media/pci/cx18/cx18-driver.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
Signature · 1 line
2.14.1
#1 lore raw

PATCH 1/3 cx18: Delete an error message for a failed memory allocation in cx18_probe()

From: Markus Elfring <[email protected]>
Date: Sat, 2 Sep 2017 19:39:56 +0200

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

This issue was detected by using the Coccinelle software.

---
 drivers/media/pci/cx18/cx18-driver.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/pci/cx18/cx18-driver.c +2 -4
index 8bce49cdad46..b267590e0877 100644
@@ -913,8 +913,6 @@ static int cx18_probe(struct pci_dev *pci_dev,
-	if (cx = NULL) {
-		printk(KERN_ERR "cx18: cannot manage card %d, out of memory\n",
-		       i);
+	if (!cx)
 		return -ENOMEM;
-	}
+
 	cx->pci_dev = pci_dev;
 	cx->instance = i;
 
Signature · 1 line
2.14.1
#2 lore raw

PATCH 2/3 cx18: Improve a size determination in cx18_probe()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 2 Sep 2017 19:42:12 +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/pci/cx18/cx18-driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/pci/cx18/cx18-driver.c +1 -1
index b267590e0877..49fc9b72ada5 100644
@@ -909,5 +909,5 @@ static int cx18_probe(struct pci_dev *pci_dev,
 		return -ENOMEM;
 	}
 
-	cx = kzalloc(sizeof(struct cx18), GFP_ATOMIC);
+	cx = kzalloc(sizeof(*cx), GFP_ATOMIC);
 	if (!cx)
Signature · 1 line
2.14.1
#3 lore raw

PATCH 3/3 cx18: Adjust ten checks for null pointers

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 2 Sep 2017 19:49:23 +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/pci/cx18/cx18-driver.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/media/pci/cx18/cx18-driver.c +6 -6
index 49fc9b72ada5..c29e8ec880b3 100644
@@ -255,7 +255,7 @@ static void request_module_async(struct work_struct *work)
 	request_module("cx18-alsa");
 
 	/* Initialize cx18-alsa for this instance of the cx18 device */
-	if (cx18_ext_init != NULL)
+	if (cx18_ext_init)
 		cx18_ext_init(dev);
 }
 
@@ -291,11 +291,11 @@ int cx18_msleep_timeout(unsigned int msecs, int intr)
 /* Release ioremapped memory */
 static void cx18_iounmap(struct cx18 *cx)
 {
-	if (cx = NULL)
+	if (!cx)
 		return;
 
 	/* Release io memory */
-	if (cx->enc_mem != NULL) {
+	if (cx->enc_mem) {
 		CX18_DEBUG_INFO("releasing enc_mem\n");
 		iounmap(cx->enc_mem);
 		cx->enc_mem = NULL;
@@ -649,15 +649,15 @@ static void cx18_process_options(struct cx18 *cx)
 		CX18_INFO("User specified %s card\n", cx->card->name);
 	else if (cx->options.cardtype != 0)
 		CX18_ERR("Unknown user specified type, trying to autodetect card\n");
-	if (cx->card = NULL) {
+	if (!cx->card) {
 		if (cx->pci_dev->subsystem_vendor = CX18_PCI_ID_HAUPPAUGE) {
 			cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
 			CX18_INFO("Autodetected Hauppauge card\n");
 		}
 	}
-	if (cx->card = NULL) {
+	if (!cx->card) {
 		for (i = 0; (cx->card = cx18_get_card(i)); i++) {
-			if (cx->card->pci_list = NULL)
+			if (!cx->card->pci_list)
 				continue;
 			for (j = 0; cx->card->pci_list[j].device; j++) {
 				if (cx->pci_dev->device !@@ -676,7 +676,7 @@ static void cx18_process_options(struct cx18 *cx)

}
done:

- if (cx->card = NULL) {
+ if (!cx->card) {
cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); CX18_ERR("Unknown card: vendor/device: [%04x:%04x]\n",
cx->pci_dev->vendor, cx->pci_dev->device);
@@ -698,7 +698,7 @@ static int cx18_create_in_workq(struct cx18 *cx)
snprintf(cx->in_workq_name, sizeof(cx->in_workq_name), "%s-in",
cx->v4l2_dev.name);
cx->in_work_queue = alloc_ordered_workqueue("%s", 0, cx->in_workq_name);
- if (cx->in_work_queue = NULL) {
+ if (!cx->in_work_queue) {
CX18_ERR("Unable to create incoming mailbox handler thread\n"); return -ENOMEM;
}
@@ -1254,7 +1254,7 @@ static void cx18_cancel_out_work_orders(struct cx18 *cx)
{
int i;
for (i = 0; i < CX18_MAX_STREAMS; i++)
- if (&cx->streams[i].video_dev != NULL)
+ if (&cx->streams[i].video_dev)
cancel_work_sync(&cx->streams[i].out_work_order);
}

@@ -1299,7 +1299,7 @@ static void cx18_remove(struct pci_dev *pci_dev)

pci_disable_device(cx->pci_dev);

- if (cx->vbi.sliced_mpeg_data[0] != NULL)
+ if (cx->vbi.sliced_mpeg_data[0])
for (i = 0; i < CX18_VBI_FRAMES; i++)
kfree(cx->vbi.sliced_mpeg_data[i]);

Signature · 1 line
2.14.1