Skip to contentSkip to conversation

staging: ks7010: Remove the explicit NULL comparison

PATCH In review sayli karnik 2 participants 4 messages Sep 12, 2016 – Sep 13, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: ks7010: Remove the explicit NULL comparison

The patch removes the explicit null comparisons entirely for the ks7010 driver. This was detected by checkpatch.pl

---
 drivers/staging/ks7010/ks7010_sdio.c | 14 +++++++-------
 drivers/staging/ks7010/ks_hostif.c   | 30 +++++++++++++++---------------
 drivers/staging/ks7010/ks_wlan_net.c |  2 +-
 3 files changed, 23 insertions(+), 23 deletions(-)
drivers/staging/ks7010/ks7010_sdio.c +7 -7
index b7337fd..129e203 100644
@@ -268,7 +268,7 @@ static int enqueue_txdev(struct ks_wlan_private *priv, unsigned char *p,
 
 	if (priv->dev_state < DEVICE_STATE_BOOT) {
 		kfree(p);
-		if (complete_handler != NULL)
+		if (complete_handler)
 			(*complete_handler) (arg1, arg2);
 		return 1;
 	}
@@ -277,7 +277,7 @@ static int enqueue_txdev(struct ks_wlan_private *priv, unsigned char *p,
 		/* in case of buffer overflow */
 		DPRINTK(1, "tx buffer overflow\n");
 		kfree(p);
-		if (complete_handler != NULL)
+		if (complete_handler)
 			(*complete_handler) (arg1, arg2);
 		return 1;
 	}
@@ -349,7 +349,7 @@ static void tx_device_task(void *dev)
 
 		}
 		kfree(sp->sendp);	/* allocated memory free */
-		if (sp->complete_handler != NULL)	/* TX Complete */
+		if (sp->complete_handler)	/* TX Complete */
 			(*sp->complete_handler) (sp->arg1, sp->arg2);
 		inc_txqhead(priv);
 
@@ -696,7 +696,7 @@ static void trx_device_exit(struct ks_wlan_private *priv)
 	while (cnt_txqbody(priv) > 0) {
 		sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qhead];
 		kfree(sp->sendp);	/* allocated memory free */
-		if (sp->complete_handler != NULL)	/* TX Complete */
+		if (sp->complete_handler)	/* TX Complete */
 			(*sp->complete_handler) (sp->arg1, sp->arg2);
 		inc_txqhead(priv);
 	}
@@ -1029,7 +1029,7 @@ static int ks7010_sdio_probe(struct sdio_func *func,
 
 	/* private memory allocate */
 	netdev = alloc_etherdev(sizeof(*priv));
-	if (netdev == NULL) {
+	if (!netdev) {
 		printk(KERN_ERR "ks7010 : Unable to alloc new net device\n");
 		goto error_release_irq;
 	}
@@ -1146,7 +1146,7 @@ static void ks7010_sdio_remove(struct sdio_func *func)
 
 	card = sdio_get_drvdata(func);
 
-	if (card == NULL)
+	if (!card)
 		return;
 
 	DPRINTK(1, "priv = card->priv\n");
@@ -1168,7 +1168,7 @@ static void ks7010_sdio_remove(struct sdio_func *func)
 			struct hostif_stop_request_t *pp;
 			pp = (struct hostif_stop_request_t *)
 			    kzalloc(hif_align_size(sizeof(*pp)), GFP_KERNEL);
-			if (pp == NULL) {
+			if (!pp) {
 				DPRINTK(3, "allocate memory failed..\n");
 				return;	/* to do goto ni suru */
 			}
drivers/staging/ks7010/ks_hostif.c +15 -15
index a8822fe..f32ce5a 100644
@@ -1176,7 +1176,7 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)
 	    kmalloc(hif_align_size(sizeof(*pp) + 6 + packet_len + 8),
 		    KS_WLAN_MEM_FLAG);
 
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		dev_kfree_skb(packet);
 		return -2;
@@ -1315,7 +1315,7 @@ void hostif_mib_get_request(struct ks_wlan_private *priv,
 	/* make primitive */
 	pp = (struct hostif_mib_get_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1346,7 +1346,7 @@ void hostif_mib_set_request(struct ks_wlan_private *priv,
 	/* make primitive */
 	pp = (struct hostif_mib_set_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp) + size), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1376,7 +1376,7 @@ void hostif_start_request(struct ks_wlan_private *priv, unsigned char mode)
 	/* make primitive */
 	pp = (struct hostif_start_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1404,7 +1404,7 @@ void hostif_ps_adhoc_set_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_ps_adhoc_set_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1448,7 +1448,7 @@ void hostif_infrastructure_set_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_infrastructure_set_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1515,7 +1515,7 @@ void hostif_infrastructure_set2_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_infrastructure_set2_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1585,7 +1585,7 @@ void hostif_adhoc_set_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_adhoc_set_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1631,7 +1631,7 @@ void hostif_adhoc_set2_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_adhoc_set2_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1679,7 +1679,7 @@ void hostif_stop_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_stop_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1702,7 +1702,7 @@ void hostif_phy_information_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_phy_information_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1734,7 +1734,7 @@ void hostif_power_mngmt_request(struct ks_wlan_private *priv,
 	/* make primitive */
 	pp = (struct hostif_power_mngmt_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1761,7 +1761,7 @@ void hostif_sleep_request(struct ks_wlan_private *priv, unsigned long mode)
 		/* make primitive */
 		pp = (struct hostif_sleep_request_t *)
 		    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-		if (pp == NULL) {
+		if (!pp) {
 			DPRINTK(3, "allocate memory failed..\n");
 			return;
 		}
@@ -1795,7 +1795,7 @@ void hostif_bss_scan_request(struct ks_wlan_private *priv,
 	/* make primitive */
 	pp = (struct hostif_bss_scan_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1852,7 +1852,7 @@ void hostif_mic_failure_request(struct ks_wlan_private *priv,
 	/* make primitive */
 	pp = (struct hostif_mic_failure_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
drivers/staging/ks7010/ks_wlan_net.c +1 -1
index 1e21eb1..8462c98 100644
@@ -3366,7 +3366,7 @@ int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
 
-	if (skb == NULL) {
+	if (!skb) {
 		printk(KERN_ERR "ks_wlan:  skb == NULL!!!\n");
 		return 0;
 	}
Signature · 1 line
2.7.4
#1 lore raw
Quoted 2 lines · sayli karnik

The patch removes the explicit null comparisons entirely for the ks7010 driver. This was detected by checkpatch.pl

It's orthogonal to the change you have made here, but there are a lot of ugly casts on the calls to kmalloc. Since kmalloc returns a void * type, its result can be implicitly casted to other types via an assignment.

julia

Quoted 236 lines
---
 drivers/staging/ks7010/ks7010_sdio.c | 14 +++++++-------
 drivers/staging/ks7010/ks_hostif.c   | 30 +++++++++++++++---------------
 drivers/staging/ks7010/ks_wlan_net.c |  2 +-
 3 files changed, 23 insertions(+), 23 deletions(-)
drivers/staging/ks7010/ks7010_sdio.c +7 -7
index b7337fd..129e203 100644
@@ -268,7 +268,7 @@ static int enqueue_txdev(struct ks_wlan_private *priv, unsigned char *p,
 
 	if (priv->dev_state < DEVICE_STATE_BOOT) {
 		kfree(p);
-		if (complete_handler != NULL)
+		if (complete_handler)
 			(*complete_handler) (arg1, arg2);
 		return 1;
 	}
@@ -277,7 +277,7 @@ static int enqueue_txdev(struct ks_wlan_private *priv, unsigned char *p,
 		/* in case of buffer overflow */
 		DPRINTK(1, "tx buffer overflow\n");
 		kfree(p);
-		if (complete_handler != NULL)
+		if (complete_handler)
 			(*complete_handler) (arg1, arg2);
 		return 1;
 	}
@@ -349,7 +349,7 @@ static void tx_device_task(void *dev)
 
 		}
 		kfree(sp->sendp);	/* allocated memory free */
-		if (sp->complete_handler != NULL)	/* TX Complete */
+		if (sp->complete_handler)	/* TX Complete */
 			(*sp->complete_handler) (sp->arg1, sp->arg2);
 		inc_txqhead(priv);
 
@@ -696,7 +696,7 @@ static void trx_device_exit(struct ks_wlan_private *priv)
 	while (cnt_txqbody(priv) > 0) {
 		sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qhead];
 		kfree(sp->sendp);	/* allocated memory free */
-		if (sp->complete_handler != NULL)	/* TX Complete */
+		if (sp->complete_handler)	/* TX Complete */
 			(*sp->complete_handler) (sp->arg1, sp->arg2);
 		inc_txqhead(priv);
 	}
@@ -1029,7 +1029,7 @@ static int ks7010_sdio_probe(struct sdio_func *func,
 
 	/* private memory allocate */
 	netdev = alloc_etherdev(sizeof(*priv));
-	if (netdev == NULL) {
+	if (!netdev) {
 		printk(KERN_ERR "ks7010 : Unable to alloc new net device\n");
 		goto error_release_irq;
 	}
@@ -1146,7 +1146,7 @@ static void ks7010_sdio_remove(struct sdio_func *func)
 
 	card = sdio_get_drvdata(func);
 
-	if (card == NULL)
+	if (!card)
 		return;
 
 	DPRINTK(1, "priv = card->priv\n");
@@ -1168,7 +1168,7 @@ static void ks7010_sdio_remove(struct sdio_func *func)
 			struct hostif_stop_request_t *pp;
 			pp = (struct hostif_stop_request_t *)
 			    kzalloc(hif_align_size(sizeof(*pp)), GFP_KERNEL);
-			if (pp == NULL) {
+			if (!pp) {
 				DPRINTK(3, "allocate memory failed..\n");
 				return;	/* to do goto ni suru */
 			}
drivers/staging/ks7010/ks_hostif.c +15 -15
index a8822fe..f32ce5a 100644
@@ -1176,7 +1176,7 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)
 	    kmalloc(hif_align_size(sizeof(*pp) + 6 + packet_len + 8),
 		    KS_WLAN_MEM_FLAG);
 
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		dev_kfree_skb(packet);
 		return -2;
@@ -1315,7 +1315,7 @@ void hostif_mib_get_request(struct ks_wlan_private *priv,
 	/* make primitive */
 	pp = (struct hostif_mib_get_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1346,7 +1346,7 @@ void hostif_mib_set_request(struct ks_wlan_private *priv,
 	/* make primitive */
 	pp = (struct hostif_mib_set_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp) + size), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1376,7 +1376,7 @@ void hostif_start_request(struct ks_wlan_private *priv, unsigned char mode)
 	/* make primitive */
 	pp = (struct hostif_start_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1404,7 +1404,7 @@ void hostif_ps_adhoc_set_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_ps_adhoc_set_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1448,7 +1448,7 @@ void hostif_infrastructure_set_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_infrastructure_set_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1515,7 +1515,7 @@ void hostif_infrastructure_set2_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_infrastructure_set2_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1585,7 +1585,7 @@ void hostif_adhoc_set_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_adhoc_set_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1631,7 +1631,7 @@ void hostif_adhoc_set2_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_adhoc_set2_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1679,7 +1679,7 @@ void hostif_stop_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_stop_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1702,7 +1702,7 @@ void hostif_phy_information_request(struct ks_wlan_private *priv)
 	/* make primitive */
 	pp = (struct hostif_phy_information_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1734,7 +1734,7 @@ void hostif_power_mngmt_request(struct ks_wlan_private *priv,
 	/* make primitive */
 	pp = (struct hostif_power_mngmt_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1761,7 +1761,7 @@ void hostif_sleep_request(struct ks_wlan_private *priv, unsigned long mode)
 		/* make primitive */
 		pp = (struct hostif_sleep_request_t *)
 		    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-		if (pp == NULL) {
+		if (!pp) {
 			DPRINTK(3, "allocate memory failed..\n");
 			return;
 		}
@@ -1795,7 +1795,7 @@ void hostif_bss_scan_request(struct ks_wlan_private *priv,
 	/* make primitive */
 	pp = (struct hostif_bss_scan_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
@@ -1852,7 +1852,7 @@ void hostif_mic_failure_request(struct ks_wlan_private *priv,
 	/* make primitive */
 	pp = (struct hostif_mic_failure_request_t *)
 	    kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-	if (pp == NULL) {
+	if (!pp) {
 		DPRINTK(3, "allocate memory failed..\n");
 		return;
 	}
drivers/staging/ks7010/ks_wlan_net.c +1 -2
index 1e21eb1..8462c98 100644
@@ -3366,7 +3366,7 @@ int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
 
-	if (skb == NULL) {
+	if (!skb) {
 		printk(KERN_ERR "ks_wlan:  skb == NULL!!!\n");
 		return 0;
 	}
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160912211728.GA13970%40sayli-HP-15-Notebook-PC.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw

One way to do reduce the ugliness of the casts is to use typedefs to structures, but they certainly deteriorate readability according to Documentation/CodingStyle.
Anyway since a void * is implicitly casted to other types, should I remove the casts and send a separate patch for that?

Thanks!

Quoted 249 lines · Julia Lawall
Quoted 2 lines · sayli karnik

The patch removes the explicit null comparisons entirely for the ks7010 driver. This was detected by checkpatch.pl

It's orthogonal to the change you have made here, but there are a lot of ugly casts on the calls to kmalloc. Since kmalloc returns a void * type, its result can be implicitly casted to other types via an assignment.

julia

Quoted 236 lines
---
 drivers/staging/ks7010/ks7010_sdio.c | 14 +++++++-------
 drivers/staging/ks7010/ks_hostif.c   | 30 +++++++++++++++---------------
 drivers/staging/ks7010/ks_wlan_net.c |  2 +-
 3 files changed, 23 insertions(+), 23 deletions(-)
drivers/staging/ks7010/ks7010_sdio.c +7 -7
index b7337fd..129e203 100644
@@ -268,7 +268,7 @@ static int enqueue_txdev(struct ks_wlan_private *priv, unsigned char *p,
 
      if (priv->dev_state < DEVICE_STATE_BOOT) {
              kfree(p);
-             if (complete_handler != NULL)
+             if (complete_handler)
                      (*complete_handler) (arg1, arg2);
              return 1;
      }
@@ -277,7 +277,7 @@ static int enqueue_txdev(struct ks_wlan_private *priv, unsigned char *p,
              /* in case of buffer overflow */
              DPRINTK(1, "tx buffer overflow\n");
              kfree(p);
-             if (complete_handler != NULL)
+             if (complete_handler)
                      (*complete_handler) (arg1, arg2);
              return 1;
      }
@@ -349,7 +349,7 @@ static void tx_device_task(void *dev)
 
              }
              kfree(sp->sendp);       /* allocated memory free */
-             if (sp->complete_handler != NULL)       /* TX Complete */
+             if (sp->complete_handler)       /* TX Complete */
                      (*sp->complete_handler) (sp->arg1, sp->arg2);
              inc_txqhead(priv);
 
@@ -696,7 +696,7 @@ static void trx_device_exit(struct ks_wlan_private *priv)
      while (cnt_txqbody(priv) > 0) {
              sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qhead];
              kfree(sp->sendp);       /* allocated memory free */
-             if (sp->complete_handler != NULL)       /* TX Complete */
+             if (sp->complete_handler)       /* TX Complete */
                      (*sp->complete_handler) (sp->arg1, sp->arg2);
              inc_txqhead(priv);
      }
@@ -1029,7 +1029,7 @@ static int ks7010_sdio_probe(struct sdio_func *func,
 
      /* private memory allocate */
      netdev = alloc_etherdev(sizeof(*priv));
-     if (netdev == NULL) {
+     if (!netdev) {
              printk(KERN_ERR "ks7010 : Unable to alloc new net device\n");
              goto error_release_irq;
      }
@@ -1146,7 +1146,7 @@ static void ks7010_sdio_remove(struct sdio_func *func)
 
      card = sdio_get_drvdata(func);
 
-     if (card == NULL)
+     if (!card)
              return;
 
      DPRINTK(1, "priv = card->priv\n");
@@ -1168,7 +1168,7 @@ static void ks7010_sdio_remove(struct sdio_func *func)
                      struct hostif_stop_request_t *pp;
                      pp = (struct hostif_stop_request_t *)
                          kzalloc(hif_align_size(sizeof(*pp)), GFP_KERNEL);
-                     if (pp == NULL) {
+                     if (!pp) {
                              DPRINTK(3, "allocate memory failed..\n");
                              return; /* to do goto ni suru */
                      }
drivers/staging/ks7010/ks_hostif.c +15 -15
index a8822fe..f32ce5a 100644
@@ -1176,7 +1176,7 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)
          kmalloc(hif_align_size(sizeof(*pp) + 6 + packet_len + 8),
                  KS_WLAN_MEM_FLAG);
 
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              dev_kfree_skb(packet);
              return -2;
@@ -1315,7 +1315,7 @@ void hostif_mib_get_request(struct ks_wlan_private *priv,
      /* make primitive */
      pp = (struct hostif_mib_get_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1346,7 +1346,7 @@ void hostif_mib_set_request(struct ks_wlan_private *priv,
      /* make primitive */
      pp = (struct hostif_mib_set_request_t *)
          kmalloc(hif_align_size(sizeof(*pp) + size), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1376,7 +1376,7 @@ void hostif_start_request(struct ks_wlan_private *priv, unsigned char mode)
      /* make primitive */
      pp = (struct hostif_start_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1404,7 +1404,7 @@ void hostif_ps_adhoc_set_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_ps_adhoc_set_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1448,7 +1448,7 @@ void hostif_infrastructure_set_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_infrastructure_set_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1515,7 +1515,7 @@ void hostif_infrastructure_set2_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_infrastructure_set2_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1585,7 +1585,7 @@ void hostif_adhoc_set_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_adhoc_set_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1631,7 +1631,7 @@ void hostif_adhoc_set2_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_adhoc_set2_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1679,7 +1679,7 @@ void hostif_stop_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_stop_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1702,7 +1702,7 @@ void hostif_phy_information_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_phy_information_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1734,7 +1734,7 @@ void hostif_power_mngmt_request(struct ks_wlan_private *priv,
      /* make primitive */
      pp = (struct hostif_power_mngmt_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1761,7 +1761,7 @@ void hostif_sleep_request(struct ks_wlan_private *priv, unsigned long mode)
              /* make primitive */
              pp = (struct hostif_sleep_request_t *)
                  kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-             if (pp == NULL) {
+             if (!pp) {
                      DPRINTK(3, "allocate memory failed..\n");
                      return;
              }
@@ -1795,7 +1795,7 @@ void hostif_bss_scan_request(struct ks_wlan_private *priv,
      /* make primitive */
      pp = (struct hostif_bss_scan_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1852,7 +1852,7 @@ void hostif_mic_failure_request(struct ks_wlan_private *priv,
      /* make primitive */
      pp = (struct hostif_mic_failure_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
drivers/staging/ks7010/ks_wlan_net.c +1 -2
index 1e21eb1..8462c98 100644
@@ -3366,7 +3366,7 @@ int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
      DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
 
-     if (skb == NULL) {
+     if (!skb) {
              printk(KERN_ERR "ks_wlan:  skb == NULL!!!\n");
              return 0;
      }
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160912211728.GA13970%40sayli-HP-15-Notebook-PC.
For more options, visit https://groups.google.com/d/optout.

#3 lore raw
Quoted 3 lines · sayli karnik

One way to do reduce the ugliness of the casts is to use typedefs to structures, but they certainly deteriorate readability according to Documentation/CodingStyle.

No definitely no typedefs!

Quoted 2 lines

Anyway since a void * is implicitly casted to other types, should I remove the casts and send a separate patch for that?

The casts are just not needed at all. It would be great to make a new patch for that. However, if Greg hasn't applied your previous one, which you can check by updating your staging tree, you would need to make a series, with the original patch and the new one, so that Greg knows in what order to apply them.

julia

Quoted 260 lines

Thanks!

Quoted 242 lines · Julia Lawall
Quoted 2 lines · sayli karnik

The patch removes the explicit null comparisons entirely for the ks7010 driver. This was detected by checkpatch.pl

It's orthogonal to the change you have made here, but there are a lot of ugly casts on the calls to kmalloc. Since kmalloc returns a void * type, its result can be implicitly casted to other types via an assignment.

julia

Quoted 229 lines
---
 drivers/staging/ks7010/ks7010_sdio.c | 14 +++++++-------
 drivers/staging/ks7010/ks_hostif.c   | 30 +++++++++++++++---------------
 drivers/staging/ks7010/ks_wlan_net.c |  2 +-
 3 files changed, 23 insertions(+), 23 deletions(-)
drivers/staging/ks7010/ks7010_sdio.c +7 -7
index b7337fd..129e203 100644
@@ -268,7 +268,7 @@ static int enqueue_txdev(struct ks_wlan_private *priv, unsigned char *p,
 
      if (priv->dev_state < DEVICE_STATE_BOOT) {
              kfree(p);
-             if (complete_handler != NULL)
+             if (complete_handler)
                      (*complete_handler) (arg1, arg2);
              return 1;
      }
@@ -277,7 +277,7 @@ static int enqueue_txdev(struct ks_wlan_private *priv, unsigned char *p,
              /* in case of buffer overflow */
              DPRINTK(1, "tx buffer overflow\n");
              kfree(p);
-             if (complete_handler != NULL)
+             if (complete_handler)
                      (*complete_handler) (arg1, arg2);
              return 1;
      }
@@ -349,7 +349,7 @@ static void tx_device_task(void *dev)
 
              }
              kfree(sp->sendp);       /* allocated memory free */
-             if (sp->complete_handler != NULL)       /* TX Complete */
+             if (sp->complete_handler)       /* TX Complete */
                      (*sp->complete_handler) (sp->arg1, sp->arg2);
              inc_txqhead(priv);
 
@@ -696,7 +696,7 @@ static void trx_device_exit(struct ks_wlan_private *priv)
      while (cnt_txqbody(priv) > 0) {
              sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qhead];
              kfree(sp->sendp);       /* allocated memory free */
-             if (sp->complete_handler != NULL)       /* TX Complete */
+             if (sp->complete_handler)       /* TX Complete */
                      (*sp->complete_handler) (sp->arg1, sp->arg2);
              inc_txqhead(priv);
      }
@@ -1029,7 +1029,7 @@ static int ks7010_sdio_probe(struct sdio_func *func,
 
      /* private memory allocate */
      netdev = alloc_etherdev(sizeof(*priv));
-     if (netdev == NULL) {
+     if (!netdev) {
              printk(KERN_ERR "ks7010 : Unable to alloc new net device\n");
              goto error_release_irq;
      }
@@ -1146,7 +1146,7 @@ static void ks7010_sdio_remove(struct sdio_func *func)
 
      card = sdio_get_drvdata(func);
 
-     if (card == NULL)
+     if (!card)
              return;
 
      DPRINTK(1, "priv = card->priv\n");
@@ -1168,7 +1168,7 @@ static void ks7010_sdio_remove(struct sdio_func *func)
                      struct hostif_stop_request_t *pp;
                      pp = (struct hostif_stop_request_t *)
                          kzalloc(hif_align_size(sizeof(*pp)), GFP_KERNEL);
-                     if (pp == NULL) {
+                     if (!pp) {
                              DPRINTK(3, "allocate memory failed..\n");
                              return; /* to do goto ni suru */
                      }
drivers/staging/ks7010/ks_hostif.c +15 -15
index a8822fe..f32ce5a 100644
@@ -1176,7 +1176,7 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)
          kmalloc(hif_align_size(sizeof(*pp) + 6 + packet_len + 8),
                  KS_WLAN_MEM_FLAG);
 
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              dev_kfree_skb(packet);
              return -2;
@@ -1315,7 +1315,7 @@ void hostif_mib_get_request(struct ks_wlan_private *priv,
      /* make primitive */
      pp = (struct hostif_mib_get_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1346,7 +1346,7 @@ void hostif_mib_set_request(struct ks_wlan_private *priv,
      /* make primitive */
      pp = (struct hostif_mib_set_request_t *)
          kmalloc(hif_align_size(sizeof(*pp) + size), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1376,7 +1376,7 @@ void hostif_start_request(struct ks_wlan_private *priv, unsigned char mode)
      /* make primitive */
      pp = (struct hostif_start_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1404,7 +1404,7 @@ void hostif_ps_adhoc_set_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_ps_adhoc_set_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1448,7 +1448,7 @@ void hostif_infrastructure_set_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_infrastructure_set_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1515,7 +1515,7 @@ void hostif_infrastructure_set2_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_infrastructure_set2_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1585,7 +1585,7 @@ void hostif_adhoc_set_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_adhoc_set_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1631,7 +1631,7 @@ void hostif_adhoc_set2_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_adhoc_set2_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1679,7 +1679,7 @@ void hostif_stop_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_stop_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1702,7 +1702,7 @@ void hostif_phy_information_request(struct ks_wlan_private *priv)
      /* make primitive */
      pp = (struct hostif_phy_information_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1734,7 +1734,7 @@ void hostif_power_mngmt_request(struct ks_wlan_private *priv,
      /* make primitive */
      pp = (struct hostif_power_mngmt_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1761,7 +1761,7 @@ void hostif_sleep_request(struct ks_wlan_private *priv, unsigned long mode)
              /* make primitive */
              pp = (struct hostif_sleep_request_t *)
                  kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-             if (pp == NULL) {
+             if (!pp) {
                      DPRINTK(3, "allocate memory failed..\n");
                      return;
              }
@@ -1795,7 +1795,7 @@ void hostif_bss_scan_request(struct ks_wlan_private *priv,
      /* make primitive */
      pp = (struct hostif_bss_scan_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
@@ -1852,7 +1852,7 @@ void hostif_mic_failure_request(struct ks_wlan_private *priv,
      /* make primitive */
      pp = (struct hostif_mic_failure_request_t *)
          kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
-     if (pp == NULL) {
+     if (!pp) {
              DPRINTK(3, "allocate memory failed..\n");
              return;
      }
drivers/staging/ks7010/ks_wlan_net.c +1 -2
index 1e21eb1..8462c98 100644
@@ -3366,7 +3366,7 @@ int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
      DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
 
-     if (skb == NULL) {
+     if (!skb) {
              printk(KERN_ERR "ks_wlan:  skb == NULL!!!\n");
              return 0;
      }
--

2.7.4

Quoted 7 lines
Quoted 7 lines

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160912211728.GA13970%40sayli-HP-15-Notebook-PC.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAKG5xWi2jK35G%2BVa7NU4_Q8_jNgbanJozASquzpwxDug7SB6MA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.