netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] atm: idt77252: Adjustments for some function implementations
@ 2017-08-05 12:24 SF Markus Elfring
  2017-08-05 12:26 ` [PATCH 1/4] atm: idt77252: Adjust four function calls together with a variable assignment SF Markus Elfring
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-05 12:24 UTC (permalink / raw)
  To: linux-atm-general, netdev, Chas Williams; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 5 Aug 2017 14:22:33 +0200

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

Markus Elfring (4):
  Adjust four function calls together with a variable assignment
  Delete an error message for a failed memory allocation in seven functions
  Improve seven size determinations
  Adjust ten checks for null pointers

 drivers/atm/idt77252.c | 68 ++++++++++++++++++++++----------------------------
 1 file changed, 30 insertions(+), 38 deletions(-)

-- 
2.13.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] atm: idt77252: Adjust four function calls together with a variable assignment
  2017-08-05 12:24 [PATCH 0/4] atm: idt77252: Adjustments for some function implementations SF Markus Elfring
@ 2017-08-05 12:26 ` SF Markus Elfring
  2017-08-05 12:28 ` [PATCH 2/4] atm: idt77252: Delete an error message for a failed memory allocation in seven functions SF Markus Elfring
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-05 12:26 UTC (permalink / raw)
  To: linux-atm-general, netdev, Chas Williams; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 4 Aug 2017 22:20:08 +0200

The script "checkpatch.pl" pointed information out like the following.

ERROR: do not use assignment in if condition

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/atm/idt77252.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index b7a168c46692..6a051f5909d0 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -1070,7 +1070,8 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
 
 		cell = skb->data;
 		for (i = (stat & SAR_RSQE_CELLCNT); i; i--) {
-			if ((sb = dev_alloc_skb(64)) == NULL) {
+			sb = dev_alloc_skb(64);
+			if (!sb) {
 				printk("%s: Can't allocate buffers for aal0.\n",
 				       card->name);
 				atomic_add(i, &vcc->stats->rx_drop);
@@ -1304,7 +1305,8 @@ idt77252_rx_raw(struct idt77252_dev *card)
 			goto drop;
 		}
 	
-		if ((sb = dev_alloc_skb(64)) == NULL) {
+		sb = dev_alloc_skb(64);
+		if (!sb) {
 			printk("%s: Can't allocate buffers for AAL0.\n",
 			       card->name);
 			atomic_inc(&vcc->stats->rx_err);
@@ -3600,13 +3602,14 @@ static int idt77252_init_one(struct pci_dev *pcidev,
 	struct atm_dev *dev;
 	int i, err;
 
-
-	if ((err = pci_enable_device(pcidev))) {
+	err = pci_enable_device(pcidev);
+	if (err) {
 		printk("idt77252: can't enable PCI device at %s\n", pci_name(pcidev));
 		return err;
 	}
 
-	if ((err = dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32)))) {
+	err = dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32));
+	if (err) {
 		printk("idt77252: can't enable DMA for PCI device at %s\n", pci_name(pcidev));
 		return err;
 	}
-- 
2.13.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] atm: idt77252: Delete an error message for a failed memory allocation in seven functions
  2017-08-05 12:24 [PATCH 0/4] atm: idt77252: Adjustments for some function implementations SF Markus Elfring
  2017-08-05 12:26 ` [PATCH 1/4] atm: idt77252: Adjust four function calls together with a variable assignment SF Markus Elfring
@ 2017-08-05 12:28 ` SF Markus Elfring
  2017-08-06 19:06   ` kbuild test robot
  2017-08-05 12:30 ` [PATCH 3/4] atm: idt77252: Improve seven size determinations SF Markus Elfring
  2017-08-05 12:32 ` [PATCH 4/4] atm: idt77252: Adjust ten checks for null pointers SF Markus Elfring
  3 siblings, 1 reply; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-05 12:28 UTC (permalink / raw)
  To: linux-atm-general, netdev, Chas Williams; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 5 Aug 2017 12:45:34 +0200

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

This issue was detected by using the Coccinelle software.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/atm/idt77252.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index 6a051f5909d0..434dc4ee5f15 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -1307,8 +1307,6 @@ idt77252_rx_raw(struct idt77252_dev *card)
 	
 		sb = dev_alloc_skb(64);
 		if (!sb) {
-			printk("%s: Can't allocate buffers for AAL0.\n",
-			       card->name);
 			atomic_inc(&vcc->stats->rx_err);
 			goto drop;
 		}
@@ -2007,7 +2005,6 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
 
 	skb = dev_alloc_skb(64);
 	if (!skb) {
-		printk("%s: Out of memory in send_oam().\n", card->name);
 		atomic_inc(&vcc->stats->tx_err);
 		return -ENOMEM;
 	}
@@ -2427,7 +2424,6 @@ idt77252_open(struct atm_vcc *vcc)
 	if (!card->vcs[index]) {
 		card->vcs[index] = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
 		if (!card->vcs[index]) {
-			printk("%s: can't alloc vc in open()\n", card->name);
 			mutex_unlock(&card->mutex);
 			return -ENOMEM;
 		}
@@ -2857,10 +2853,9 @@ open_card_oam(struct idt77252_dev *card)
 			index = VPCI2VC(card, vpi, vci);
 
 			vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
-			if (!vc) {
-				printk("%s: can't alloc vc\n", card->name);
+			if (!vc)
 				return -ENOMEM;
-			}
+
 			vc->index = index;
 			card->vcs[index] = vc;
 
@@ -2924,10 +2919,9 @@ open_card_ubr0(struct idt77252_dev *card)
 	struct vc_map *vc;
 
 	vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
-	if (!vc) {
-		printk("%s: can't alloc vc\n", card->name);
+	if (!vc)
 		return -ENOMEM;
-	}
+
 	card->vcs[0] = vc;
 	vc->class = SCHED_UBR0;
 
@@ -3410,7 +3404,6 @@ static int init_card(struct atm_dev *dev)
 	IPRINTK("%s: allocate %d byte for VC map.\n", card->name, size);
 	card->vcs = vzalloc(size);
 	if (!card->vcs) {
-		printk("%s: memory allocation failure.\n", card->name);
 		deinit_card(card);
 		return -1;
 	}
@@ -3420,7 +3413,6 @@ static int init_card(struct atm_dev *dev)
 	        card->name, size);
 	card->scd2vc = vzalloc(size);
 	if (!card->scd2vc) {
-		printk("%s: memory allocation failure.\n", card->name);
 		deinit_card(card);
 		return -1;
 	}
@@ -3430,7 +3422,6 @@ static int init_card(struct atm_dev *dev)
 		card->name, size);
 	card->soft_tst = vmalloc(size);
 	if (!card->soft_tst) {
-		printk("%s: memory allocation failure.\n", card->name);
 		deinit_card(card);
 		return -1;
 	}
@@ -3616,7 +3607,6 @@ static int idt77252_init_one(struct pci_dev *pcidev,
 
 	card = kzalloc(sizeof(struct idt77252_dev), GFP_KERNEL);
 	if (!card) {
-		printk("idt77252-%d: can't allocate private data\n", index);
 		err = -ENOMEM;
 		goto err_out_disable_pdev;
 	}
-- 
2.13.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] atm: idt77252: Improve seven size determinations
  2017-08-05 12:24 [PATCH 0/4] atm: idt77252: Adjustments for some function implementations SF Markus Elfring
  2017-08-05 12:26 ` [PATCH 1/4] atm: idt77252: Adjust four function calls together with a variable assignment SF Markus Elfring
  2017-08-05 12:28 ` [PATCH 2/4] atm: idt77252: Delete an error message for a failed memory allocation in seven functions SF Markus Elfring
@ 2017-08-05 12:30 ` SF Markus Elfring
  2017-08-05 12:32 ` [PATCH 4/4] atm: idt77252: Adjust ten checks for null pointers SF Markus Elfring
  3 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-05 12:30 UTC (permalink / raw)
  To: linux-atm-general, netdev, Chas Williams; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 5 Aug 2017 13:51:04 +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 <elfring@users.sourceforge.net>
---
 drivers/atm/idt77252.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index 434dc4ee5f15..e26e36a934e9 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -638,7 +638,7 @@ alloc_scq(struct idt77252_dev *card, int class)
 {
 	struct scq_info *scq;
 
-	scq = kzalloc(sizeof(struct scq_info), GFP_KERNEL);
+	scq = kzalloc(sizeof(*scq), GFP_KERNEL);
 	if (!scq)
 		return NULL;
 	scq->base = dma_zalloc_coherent(&card->pcidev->dev, SCQ_SIZE,
@@ -2119,7 +2119,7 @@ idt77252_init_est(struct vc_map *vc, int pcr)
 {
 	struct rate_estimator *est;
 
-	est = kzalloc(sizeof(struct rate_estimator), GFP_KERNEL);
+	est = kzalloc(sizeof(*est), GFP_KERNEL);
 	if (!est)
 		return NULL;
 	est->maxcps = pcr < 0 ? -pcr : pcr;
@@ -2422,7 +2422,8 @@ idt77252_open(struct atm_vcc *vcc)
 
 	index = VPCI2VC(card, vpi, vci);
 	if (!card->vcs[index]) {
-		card->vcs[index] = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
+		card->vcs[index] = kzalloc(sizeof(*card->vcs[index]),
+					   GFP_KERNEL);
 		if (!card->vcs[index]) {
 			mutex_unlock(&card->mutex);
 			return -ENOMEM;
@@ -2612,8 +2613,7 @@ idt77252_change_qos(struct atm_vcc *vcc, struct atm_qos *qos, int flags)
 			goto out;
 	}
 
-	memcpy(&vcc->qos, qos, sizeof(struct atm_qos));
-
+	memcpy(&vcc->qos, qos, sizeof(*qos));
 	set_bit(ATM_VF_HASQOS, &vcc->flags);
 
 out:
@@ -2851,8 +2851,7 @@ open_card_oam(struct idt77252_dev *card)
 	for (vpi = 0; vpi < (1 << card->vpibits); vpi++) {
 		for (vci = 3; vci < 5; vci++) {
 			index = VPCI2VC(card, vpi, vci);
-
-			vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
+			vc = kzalloc(sizeof(*vc), GFP_KERNEL);
 			if (!vc)
 				return -ENOMEM;
 
@@ -2918,7 +2917,7 @@ open_card_ubr0(struct idt77252_dev *card)
 {
 	struct vc_map *vc;
 
-	vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
+	vc = kzalloc(sizeof(*vc), GFP_KERNEL);
 	if (!vc)
 		return -ENOMEM;
 
@@ -3605,7 +3604,7 @@ static int idt77252_init_one(struct pci_dev *pcidev,
 		return err;
 	}
 
-	card = kzalloc(sizeof(struct idt77252_dev), GFP_KERNEL);
+	card = kzalloc(sizeof(*card), GFP_KERNEL);
 	if (!card) {
 		err = -ENOMEM;
 		goto err_out_disable_pdev;
-- 
2.13.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] atm: idt77252: Adjust ten checks for null pointers
  2017-08-05 12:24 [PATCH 0/4] atm: idt77252: Adjustments for some function implementations SF Markus Elfring
                   ` (2 preceding siblings ...)
  2017-08-05 12:30 ` [PATCH 3/4] atm: idt77252: Improve seven size determinations SF Markus Elfring
@ 2017-08-05 12:32 ` SF Markus Elfring
  3 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-05 12:32 UTC (permalink / raw)
  To: linux-atm-general, netdev, Chas Williams; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 5 Aug 2017 14:04:42 +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 <elfring@users.sourceforge.net>
---
 drivers/atm/idt77252.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index e26e36a934e9..184934e05193 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -643,7 +643,7 @@ alloc_scq(struct idt77252_dev *card, int class)
 		return NULL;
 	scq->base = dma_zalloc_coherent(&card->pcidev->dev, SCQ_SIZE,
 					&scq->paddr, GFP_KERNEL);
-	if (scq->base == NULL) {
+	if (!scq->base) {
 		kfree(scq);
 		return NULL;
 	}
@@ -973,7 +973,7 @@ init_rsq(struct idt77252_dev *card)
 
 	card->rsq.base = dma_zalloc_coherent(&card->pcidev->dev, RSQSIZE,
 					     &card->rsq.paddr, GFP_KERNEL);
-	if (card->rsq.base == NULL) {
+	if (!card->rsq.base) {
 		printk("%s: can't allocate RSQ.\n", card->name);
 		return -1;
 	}
@@ -1026,7 +1026,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
 	}
 
 	skb = sb_pool_skb(card, le32_to_cpu(rsqe->word_2));
-	if (skb == NULL) {
+	if (!skb) {
 		printk("%s: NULL skb in %s, rsqe: %08x %08x %08x %08x\n",
 		       card->name, __func__,
 		       le32_to_cpu(rsqe->word_1), le32_to_cpu(rsqe->word_2),
@@ -1242,7 +1242,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
 	struct vc_map	*vc;
 	struct sk_buff	*sb;
 
-	if (card->raw_cell_head == NULL) {
+	if (!card->raw_cell_head) {
 		u32 handle = le32_to_cpu(*(card->raw_cell_hnd + 1));
 		card->raw_cell_head = sb_pool_skb(card, handle);
 	}
@@ -1375,7 +1375,7 @@ init_tsq(struct idt77252_dev *card)
 
 	card->tsq.base = dma_alloc_coherent(&card->pcidev->dev, RSQSIZE,
 					    &card->tsq.paddr, GFP_KERNEL);
-	if (card->tsq.base == NULL) {
+	if (!card->tsq.base) {
 		printk("%s: can't allocate TSQ.\n", card->name);
 		return -1;
 	}
@@ -1601,7 +1601,7 @@ __fill_tst(struct idt77252_dev *card, struct vc_map *vc,
 
 	avail = card->tst_size - 2;
 	for (e = 0; e < avail; e++) {
-		if (card->soft_tst[e].vc == NULL)
+		if (!card->soft_tst[e].vc)
 			break;
 	}
 	if (e >= avail) {
@@ -1624,7 +1624,7 @@ __fill_tst(struct idt77252_dev *card, struct vc_map *vc,
 	 * Fill Soft TST.
 	 */
 	while (r > 0) {
-		if ((cl >= avail) && (card->soft_tst[e].vc == NULL)) {
+		if ((cl >= avail) && !card->soft_tst[e].vc) {
 			if (vc)
 				card->soft_tst[e].vc = vc;
 			else
@@ -1948,7 +1948,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
 	struct vc_map *vc = vcc->dev_data;
 	int err;
 
-	if (vc == NULL) {
+	if (!vc) {
 		printk("%s: NULL connection in send().\n", card->name);
 		atomic_inc(&vcc->stats->tx_err);
 		dev_kfree_skb(skb);
@@ -3429,12 +3429,12 @@ static int init_card(struct atm_dev *dev)
 		card->soft_tst[i].vc = NULL;
 	}
 
-	if (dev->phy == NULL) {
+	if (!dev->phy) {
 		printk("%s: No LT device defined.\n", card->name);
 		deinit_card(card);
 		return -1;
 	}
-	if (dev->phy->ioctl == NULL) {
+	if (!dev->phy->ioctl) {
 		printk("%s: LT had no IOCTL function defined.\n", card->name);
 		deinit_card(card);
 		return -1;
-- 
2.13.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/4] atm: idt77252: Delete an error message for a failed memory allocation in seven functions
  2017-08-05 12:28 ` [PATCH 2/4] atm: idt77252: Delete an error message for a failed memory allocation in seven functions SF Markus Elfring
@ 2017-08-06 19:06   ` kbuild test robot
  0 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2017-08-06 19:06 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: kbuild-all, linux-atm-general, netdev, Chas Williams, LKML,
	kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 2450 bytes --]

Hi Markus,

[auto build test WARNING on linus/master]
[also build test WARNING on v4.13-rc3 next-20170804]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/atm-idt77252-Adjust-four-function-calls-together-with-a-variable-assignment/20170806-081417
config: x86_64-randconfig-b0-08070032 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   drivers//atm/idt77252.c: In function 'idt77252_send_oam':
>> drivers//atm/idt77252.c:2003: warning: unused variable 'card'

vim +/card +2003 drivers//atm/idt77252.c

^1da177e Linus Torvalds   2005-04-16  1998  
^1da177e Linus Torvalds   2005-04-16  1999  static int
^1da177e Linus Torvalds   2005-04-16  2000  idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
^1da177e Linus Torvalds   2005-04-16  2001  {
^1da177e Linus Torvalds   2005-04-16  2002  	struct atm_dev *dev = vcc->dev;
^1da177e Linus Torvalds   2005-04-16 @2003  	struct idt77252_dev *card = dev->dev_data;
^1da177e Linus Torvalds   2005-04-16  2004  	struct sk_buff *skb;
^1da177e Linus Torvalds   2005-04-16  2005  
^1da177e Linus Torvalds   2005-04-16  2006  	skb = dev_alloc_skb(64);
^1da177e Linus Torvalds   2005-04-16  2007  	if (!skb) {
^1da177e Linus Torvalds   2005-04-16  2008  		atomic_inc(&vcc->stats->tx_err);
^1da177e Linus Torvalds   2005-04-16  2009  		return -ENOMEM;
^1da177e Linus Torvalds   2005-04-16  2010  	}
14afee4b Reshetova, Elena 2017-06-30  2011  	refcount_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
^1da177e Linus Torvalds   2005-04-16  2012  
59ae1d12 Johannes Berg    2017-06-16  2013  	skb_put_data(skb, cell, 52);
^1da177e Linus Torvalds   2005-04-16  2014  
^1da177e Linus Torvalds   2005-04-16  2015  	return idt77252_send_skb(vcc, skb, 1);
^1da177e Linus Torvalds   2005-04-16  2016  }
^1da177e Linus Torvalds   2005-04-16  2017  

:::::: The code at line 2003 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <torvalds@ppc970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@ppc970.osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 34611 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-08-06 19:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-05 12:24 [PATCH 0/4] atm: idt77252: Adjustments for some function implementations SF Markus Elfring
2017-08-05 12:26 ` [PATCH 1/4] atm: idt77252: Adjust four function calls together with a variable assignment SF Markus Elfring
2017-08-05 12:28 ` [PATCH 2/4] atm: idt77252: Delete an error message for a failed memory allocation in seven functions SF Markus Elfring
2017-08-06 19:06   ` kbuild test robot
2017-08-05 12:30 ` [PATCH 3/4] atm: idt77252: Improve seven size determinations SF Markus Elfring
2017-08-05 12:32 ` [PATCH 4/4] atm: idt77252: Adjust ten checks for null pointers SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).