Skip to contentSkip to conversation

staging: kpc2000: various minor checkpatch fixes

PATCH In review Simon Sandström 3 participants 12 messages Jun 3, 2019 – Jun 10, 2019 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: kpc2000: various minor checkpatch fixes

Here is a bunch of checkpatch fixes for core.c in staging/kpc2000.

Some of these were sent earlier but not applied. Now rebased on top of staging-testing (incl. Jeremy's kpc2000 misc device removal commits).

- Simon

Simon Sandström (7):
staging: kpc2000: simplify comparisons to NULL in core.c
staging: kpc2000: remove unnecessary parentheses in core.c
staging: kpc2000: remove unnecessary oom message in core.c
staging: kpc2000: use __func__ in debug messages in core.c
staging: kpc2000: remove unnecessary include in core.c
staging: kpc2000: use sizeof(var) in kzalloc call
staging: kpc2000: fix incorrect code comment in core.c

 drivers/staging/kpc2000/kpc2000/core.c | 36 ++++++++++++--------------
 1 file changed, 16 insertions(+), 20 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/7 staging: kpc2000: simplify comparisons to NULL in core.c

Fixes checkpatch.pl warnings "Comparison to NULL could be written [...]" and "Comparisons should place the constant on the right side of the test".

---
 drivers/staging/kpc2000/kpc2000/core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/staging/kpc2000/kpc2000/core.c +6 -6
index 7f257c21e0cc..356a272c0b9c 100644
@@ -319,7 +319,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 	 * Step 1: Allocate a struct for the pcard
 	 */
 	pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
-	if (NULL == pcard) {
+	if (!pcard) {
 		dev_err(&pdev->dev,
 			"probe: failed to allocate private card data\n");
 		return -ENOMEM;
@@ -363,7 +363,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 	reg_bar_phys_len = pci_resource_len(pcard->pdev, REG_BAR);
 
 	pcard->regs_bar_base = ioremap_nocache(reg_bar_phys_addr, PAGE_SIZE);
-	if (NULL == pcard->regs_bar_base) {
+	if (!pcard->regs_bar_base) {
 		dev_err(&pcard->pdev->dev,
 			"probe: REG_BAR could not remap memory to virtual space\n");
 		err = -ENODEV;
@@ -396,7 +396,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 
 	pcard->dma_bar_base = ioremap_nocache(dma_bar_phys_addr,
 					      dma_bar_phys_len);
-	if (NULL == pcard->dma_bar_base) {
+	if (!pcard->dma_bar_base) {
 		dev_err(&pcard->pdev->dev,
 			"probe: DMA_BAR could not remap memory to virtual space\n");
 		err = -ENODEV;
@@ -546,7 +546,7 @@ static void kp2000_pcie_remove(struct pci_dev *pdev)
 
 	dev_dbg(&pdev->dev, "kp2000_pcie_remove(pdev=%p)\n", pdev);
 
-	if (pcard == NULL)
+	if (!pcard)
 		return;
 
 	mutex_lock(&pcard->sem);
@@ -555,12 +555,12 @@ static void kp2000_pcie_remove(struct pci_dev *pdev)
 	sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
 	free_irq(pcard->pdev->irq, pcard);
 	pci_disable_msi(pcard->pdev);
-	if (pcard->dma_bar_base != NULL) {
+	if (pcard->dma_bar_base) {
 		iounmap(pcard->dma_bar_base);
 		pci_release_region(pdev, DMA_BAR);
 		pcard->dma_bar_base = NULL;
 	}
-	if (pcard->regs_bar_base != NULL) {
+	if (pcard->regs_bar_base) {
 		iounmap(pcard->regs_bar_base);
 		pci_release_region(pdev, REG_BAR);
 		pcard->regs_bar_base = NULL;
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/7 staging: kpc2000: remove unnecessary parentheses in core.c

In reply to Simon Sandström

Fixes checkpatch.pl check "Unnecessary parentheses around pdev->dev.kobj".

---
 drivers/staging/kpc2000/kpc2000/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/kpc2000/kpc2000/core.c +3 -3
index 356a272c0b9c..dc6940e6c320 100644
@@ -491,7 +491,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 	/*
 	 * Step 9: Setup sysfs attributes
 	 */
-	err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);
+	err = sysfs_create_files(&pdev->dev.kobj, kp_attr_list);
 	if (err) {
 		dev_err(&pdev->dev, "Failed to add sysfs files: %d\n", err);
 		goto out9;
@@ -515,7 +515,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 	return 0;
 
 out10:
-	sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
+	sysfs_remove_files(&pdev->dev.kobj, kp_attr_list);
 out9:
 	free_irq(pcard->pdev->irq, pcard);
 out8b:
@@ -552,7 +552,7 @@ static void kp2000_pcie_remove(struct pci_dev *pdev)
 	mutex_lock(&pcard->sem);
 	kp2000_remove_cores(pcard);
 	mfd_remove_devices(PCARD_TO_DEV(pcard));
-	sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
+	sysfs_remove_files(&pdev->dev.kobj, kp_attr_list);
 	free_irq(pcard->pdev->irq, pcard);
 	pci_disable_msi(pcard->pdev);
 	if (pcard->dma_bar_base) {
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/7 staging: kpc2000: remove unnecessary oom message in core.c

In reply to Simon Sandström

Fixes checkpatch.pl warning "Possible unnecessary 'out of memory' message".

---
 drivers/staging/kpc2000/kpc2000/core.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/staging/kpc2000/kpc2000/core.c +1 -4
index dc6940e6c320..a70665a202c3 100644
@@ -319,11 +319,8 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 	 * Step 1: Allocate a struct for the pcard
 	 */
 	pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
-	if (!pcard) {
-		dev_err(&pdev->dev,
-			"probe: failed to allocate private card data\n");
+	if (!pcard)
 		return -ENOMEM;
-	}
 	dev_dbg(&pdev->dev, "probe: allocated struct kp2000_device @ %p\n",
 		pcard);
 
Signature · 1 line
2.20.1
#4 lore raw

PATCH 4/7 staging: kpc2000: use __func__ in debug messages in core.c

In reply to Simon Sandström

Fixes checkpatch.pl warning "Prefer using '"%s...", __func__' to using '<function name>', this function's name, in a string".

---
 drivers/staging/kpc2000/kpc2000/core.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/staging/kpc2000/kpc2000/core.c +5 -5
index a70665a202c3..6d4fc1f37c9f 100644
@@ -312,8 +312,8 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 	unsigned long dma_bar_phys_len;
 	u16 regval;
 
-	dev_dbg(&pdev->dev, "kp2000_pcie_probe(pdev = [%p], id = [%p])\n",
-		pdev, id);
+	dev_dbg(&pdev->dev, "%s(pdev = [%p], id = [%p])\n",
+		__func__, pdev, id);
 
 	/*
 	 * Step 1: Allocate a struct for the pcard
@@ -481,7 +481,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 			 pcard->name, pcard);
 	if (rv) {
 		dev_err(&pcard->pdev->dev,
-			"kp2000_pcie_probe: failed to request_irq: %d\n", rv);
+			"%s: failed to request_irq: %d\n", __func__, rv);
 		goto out8b;
 	}
 
@@ -507,7 +507,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 	writel(KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE,
 	       pcard->dma_common_regs);
 
-	dev_dbg(&pcard->pdev->dev, "kp2000_pcie_probe() complete!\n");
+	dev_dbg(&pcard->pdev->dev, "%s() complete!\n", __func__);
 	mutex_unlock(&pcard->sem);
 	return 0;
 
@@ -541,7 +541,7 @@ static void kp2000_pcie_remove(struct pci_dev *pdev)
 {
 	struct kp2000_device *pcard = pci_get_drvdata(pdev);
 
-	dev_dbg(&pdev->dev, "kp2000_pcie_remove(pdev=%p)\n", pdev);
+	dev_dbg(&pdev->dev, "%s(pdev=%p)\n", __func__, pdev);
 
 	if (!pcard)
 		return;
Signature · 1 line
2.20.1
maintainer
#5 lore raw

Re: [PATCH 4/7] staging: kpc2000: use __func__ in debug messages in core.c

Quoted 13 lines · Simon Sandström

Fixes checkpatch.pl warning "Prefer using '"%s...", __func__' to using '<function name>', this function's name, in a string".

---
 drivers/staging/kpc2000/kpc2000/core.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/staging/kpc2000/kpc2000/core.c +0 -0
index a70665a202c3..6d4fc1f37c9f 100644

drivers/staging/kpc2000/kpc2000/core.c static int kp2000_pcie_probe(struct pci_dev *pdev, · line 316

Quoted 7 lines
drivers/staging/kpc2000/kpc2000/core.c +2 -2
@@ -312,8 +312,8 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 	unsigned long dma_bar_phys_len;
 	u16 regval;
 
-	dev_dbg(&pdev->dev, "kp2000_pcie_probe(pdev = [%p], id = [%p])\n",
-		pdev, id);
+	dev_dbg(&pdev->dev, "%s(pdev = [%p], id = [%p])\n",
+		__func__, pdev, id);

debugging lines that say "called this function!" can all be removed, as we have ftrace in the kernel tree, we can use that instead. I'll take this, but feel free to clean them up as follow-on patches.

thanks,

greg k-h

#6 lore raw

Re: [PATCH 4/7] staging: kpc2000: use __func__ in debug messages in core.c

Quoted 11 lines · Greg KH

drivers/staging/kpc2000/kpc2000/core.c static int kp2000_pcie_probe(struct pci_dev *pdev, · line 316

Quoted 5 lines · Simon Sandström
drivers/staging/kpc2000/kpc2000/core.c +2 -2
-	dev_dbg(&pdev->dev, "kp2000_pcie_probe(pdev = [%p], id = [%p])\n",
-		pdev, id);
+	dev_dbg(&pdev->dev, "%s(pdev = [%p], id = [%p])\n",
+		__func__, pdev, id);

debugging lines that say "called this function!" can all be removed, as we have ftrace in the kernel tree, we can use that instead. I'll take this, but feel free to clean them up as follow-on patches.

Quoted 3 lines

thanks,

greg k-h

Can they be removed even if they print function arguments or other variables?

- Simon

maintainer
#7 lore raw

Re: [PATCH 4/7] staging: kpc2000: use __func__ in debug messages in core.c

Quoted 12 lines · Simon Sandström
Quoted 11 lines · Greg KH

drivers/staging/kpc2000/kpc2000/core.c static int kp2000_pcie_probe(struct pci_dev *pdev, · line 316

Quoted 5 lines · Simon Sandström
drivers/staging/kpc2000/kpc2000/core.c +2 -2
-	dev_dbg(&pdev->dev, "kp2000_pcie_probe(pdev = [%p], id = [%p])\n",
-		pdev, id);
+	dev_dbg(&pdev->dev, "%s(pdev = [%p], id = [%p])\n",
+		__func__, pdev, id);

debugging lines that say "called this function!" can all be removed, as we have ftrace in the kernel tree, we can use that instead. I'll take this, but feel free to clean them up as follow-on patches.

Quoted 6 lines
Quoted 3 lines

thanks,

greg k-h

Can they be removed even if they print function arguments or other variables?

Of course!

#8 lore raw

PATCH 5/7 staging: kpc2000: remove unnecessary include in core.c

In reply to Simon Sandström

Fixes checkpatch.pl warning "Use #include <linux/io.h> instead of <asm/io.h>".

---
 drivers/staging/kpc2000/kpc2000/core.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/kpc2000/kpc2000/core.c +0 -1
index 6d4fc1f37c9f..3f17566a9d03 100644
@@ -12,7 +12,6 @@
 #include <linux/cdev.h>
 #include <linux/rwsem.h>
 #include <linux/uaccess.h>
-#include <asm/io.h>
 #include <linux/io.h>
 #include <linux/mfd/core.h>
 #include <linux/platform_device.h>
Signature · 1 line
2.20.1
#9 lore raw

PATCH 6/7 staging: kpc2000: use sizeof(var) in kzalloc call

In reply to Simon Sandström

Fixes checkpatch.pl warning "Prefer kzalloc(sizeof(*pcard)...) over kzalloc(sizeof(struct kp2000_device)...)".

---
 drivers/staging/kpc2000/kpc2000/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/kpc2000/kpc2000/core.c +1 -1
index 3f17566a9d03..2d8d188624f7 100644
@@ -317,7 +317,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 	/*
 	 * Step 1: Allocate a struct for the pcard
 	 */
-	pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
+	pcard = kzalloc(sizeof(*pcard), GFP_KERNEL);
 	if (!pcard)
 		return -ENOMEM;
 	dev_dbg(&pdev->dev, "probe: allocated struct kp2000_device @ %p\n",
Signature · 1 line
2.20.1
#10 lore raw

PATCH 7/7 staging: kpc2000: fix incorrect code comment in core.c

In reply to Simon Sandström

Step 11 was removed from kp2000_pcie_probe in a previous commit but the comment was not changed to reflect this, so do it now.

---
 drivers/staging/kpc2000/kpc2000/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/kpc2000/kpc2000/core.c +1 -1
index 2d8d188624f7..cd3876f1ce17 100644
@@ -501,7 +501,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 		goto out10;
 
 	/*
-	 * Step 12: Enable IRQs in HW
+	 * Step 11: Enable IRQs in HW
 	 */
 	writel(KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE,
 	       pcard->dma_common_regs);
Signature · 1 line
2.20.1
#11 lore raw

Re: [PATCH 7/7] staging: kpc2000: fix incorrect code comment in core.c

Quoted 13 lines · Simon Sandström

Step 11 was removed from kp2000_pcie_probe in a previous commit but the comment was not changed to reflect this, so do it now.

---
 drivers/staging/kpc2000/kpc2000/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/kpc2000/kpc2000/core.c +0 -0
index 2d8d188624f7..cd3876f1ce17 100644

drivers/staging/kpc2000/kpc2000/core.c static int kp2000_pcie_probe(struct pci_dev *pdev, · line 504

Quoted 5 lines
drivers/staging/kpc2000/kpc2000/core.c +1 -1
@@ -501,7 +501,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 		goto out10;
 
 	/*
-	 * Step 12: Enable IRQs in HW
+	 * Step 11: Enable IRQs in HW

I don't have a problem with this patch but for the future these numbers don't add any value. And the numbered out labels are sort of ugly. The label name should say what the label does just like a function name says what the function does. Really a lot of these comments in the probe function are very obvious and don't add information (delete them).

   491          /*
   492           * Step 9: Setup sysfs attributes
   493           */
   494          err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);

The comment is probably less informative than the code.

495 if (err) {
496 dev_err(&pdev->dev, "Failed to add sysfs files: %d\n", err);
497 goto out9;

What does goto out9 do?

   498          }
   499  
   500          /*
   501           * Step 10: Probe cores
   502           */
   503          err = kp2000_probe_cores(pcard);
   504          if (err)
   505                  goto out10;

Hopefully, goto out10 deletes the sysfs files but we don't know because the label doesn't give any clues away. We have to search for it and then come back.

506
507 /*
508 * Step 12: Enable IRQs in HW
509 */
510 writel(KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE,
511 pcard->dma_common_regs);
512

   513          dev_dbg(&pcard->pdev->dev, "kp2000_pcie_probe() complete!\n");
   514          mutex_unlock(&pcard->sem);
   515          return 0;

516
517 out10:

err_remove_sysfs:

   518          sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
   519  out9:

err_free_irq:

   520          free_irq(pcard->pdev->irq, pcard);
   521  out8b:

err_disable_msi:

   522          pci_disable_msi(pcard->pdev);
   523  out8a:
   524  out7:
   525  out6:

err_unmap_dma:

   526          iounmap(pcard->dma_bar_base);
   527          pci_release_region(pdev, DMA_BAR);
   528          pcard->dma_bar_base = NULL;

529 out5:

err_unmap_regs:

   530          iounmap(pcard->regs_bar_base);
   531          pci_release_region(pdev, REG_BAR);
   532          pcard->regs_bar_base = NULL;

Something like that is way more useful because then you don't have to scroll back and forth because new the label names are useful.

regards,
dan carpenter