From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 11:16:54 +0100
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 xpnet_dev_hard_start_xmit()
Use common code in xpnet_dev_hard_start_xmit()
Adjust five checks for null pointers
drivers/misc/sgi-xp/xpnet.c | 36 ++++++++++++++----------------------
1 file changed, 14 insertions(+), 22 deletions(-)
--
2.15.1
From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 10:46:46 +0100
Omit an extra message for a memory allocation failure in these functions.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/sgi-xp/xpnet.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/drivers/misc/sgi-xp/xpnet.c b/drivers/misc/sgi-xp/xpnet.c
index 0c26eaf5f62b..e13aa6c74028 100644
--- a/drivers/misc/sgi-xp/xpnet.c
+++ b/drivers/misc/sgi-xp/xpnet.c
@@ -168,9 +168,6 @@ xpnet_receive(short partid, int channel, struct xpnet_message *msg)
/* reserve an extra cache line */
skb = dev_alloc_skb(msg->size + L1_CACHE_BYTES);
if (!skb) {
- dev_err(xpnet, "failed on dev_alloc_skb(%d)\n",
- msg->size + L1_CACHE_BYTES);
-
xpc_received(partid, channel, (void *)msg);
xpnet_device->stats.rx_errors++;
@@ -432,9 +429,6 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
*/
queued_msg = kmalloc(sizeof(struct xpnet_pending_msg), GFP_ATOMIC);
if (queued_msg == NULL) {
- dev_warn(xpnet, "failed to kmalloc %ld bytes; dropping "
- "packet\n", sizeof(struct xpnet_pending_msg));
-
dev->stats.tx_errors++;
dev_kfree_skb(skb);
return NETDEV_TX_OK;
--
2.15.1
From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 10:48:25 +0100
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.
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/sgi-xp/xpnet.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/misc/sgi-xp/xpnet.c b/drivers/misc/sgi-xp/xpnet.c
index e13aa6c74028..a4415616c03c 100644
--- a/drivers/misc/sgi-xp/xpnet.c
+++ b/drivers/misc/sgi-xp/xpnet.c
@@ -427,7 +427,7 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
* xpc_send_notifies are relying on this skb. When none
* remain, release the skb.
*/
- queued_msg = kmalloc(sizeof(struct xpnet_pending_msg), GFP_ATOMIC);
+ queued_msg = kmalloc(sizeof(*queued_msg), GFP_ATOMIC);
if (queued_msg == NULL) {
dev->stats.tx_errors++;
dev_kfree_skb(skb);
--
2.15.1
From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 10:50:10 +0100
Add a jump target so that a bit of code can be better reused
at the end of this function.
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/sgi-xp/xpnet.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/misc/sgi-xp/xpnet.c b/drivers/misc/sgi-xp/xpnet.c
index a4415616c03c..088c96a883f9 100644
--- a/drivers/misc/sgi-xp/xpnet.c
+++ b/drivers/misc/sgi-xp/xpnet.c
@@ -416,11 +416,8 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
"skb->end=0x%p skb->len=%d\n", (void *)skb->head,
(void *)skb->data, skb_tail_pointer(skb), skb_end_pointer(skb),
skb->len);
-
- if (skb->data[0] == 0x33) {
- dev_kfree_skb(skb);
- return NETDEV_TX_OK; /* nothing needed to be done */
- }
+ if (skb->data[0] == 0x33)
+ goto free_skb;
/*
* The xpnet_pending_msg tracks how many outstanding
@@ -430,8 +427,7 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
queued_msg = kmalloc(sizeof(*queued_msg), GFP_ATOMIC);
if (queued_msg == NULL) {
dev->stats.tx_errors++;
- dev_kfree_skb(skb);
- return NETDEV_TX_OK;
+ goto free_skb;
}
/* get the beginning of the first cacheline and end of last */
@@ -479,11 +475,15 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
dev->stats.tx_bytes += skb->len;
if (atomic_dec_return(&queued_msg->use_count) == 0) {
- dev_kfree_skb(skb);
kfree(queued_msg);
+ goto free_skb;
}
return NETDEV_TX_OK;
+
+free_skb:
+ dev_kfree_skb(skb);
+ return NETDEV_TX_OK;
}
/*
--
2.15.1
From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 11:00:14 +0100
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 <[email protected]>
---
drivers/misc/sgi-xp/xpnet.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/drivers/misc/sgi-xp/xpnet.c b/drivers/misc/sgi-xp/xpnet.c
index 088c96a883f9..038d6bd59840 100644
--- a/drivers/misc/sgi-xp/xpnet.c
+++ b/drivers/misc/sgi-xp/xpnet.c
@@ -260,8 +260,7 @@ xpnet_connection_activity(enum xp_retval reason, short partid, int channel,
switch (reason) {
case xpMsgReceived: /* message received */
- DBUG_ON(data == NULL);
-
+ DBUG_ON(!data);
xpnet_receive(partid, channel, (struct xpnet_message *)data);
break;
@@ -341,8 +340,7 @@ xpnet_send_completed(enum xp_retval reason, short partid, int channel,
{
struct xpnet_pending_msg *queued_msg = (struct xpnet_pending_msg *)__qm;
- DBUG_ON(queued_msg == NULL);
-
+ DBUG_ON(!queued_msg);
dev_dbg(xpnet, "message to %d notified with reason %d\n",
partid, reason);
@@ -425,7 +423,7 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
* remain, release the skb.
*/
queued_msg = kmalloc(sizeof(*queued_msg), GFP_ATOMIC);
- if (queued_msg == NULL) {
+ if (!queued_msg) {
dev->stats.tx_errors++;
goto free_skb;
}
@@ -516,7 +514,7 @@ xpnet_init(void)
xpnet_broadcast_partitions = kzalloc(BITS_TO_LONGS(xp_max_npartitions) *
sizeof(long), GFP_KERNEL);
- if (xpnet_broadcast_partitions == NULL)
+ if (!xpnet_broadcast_partitions)
return -ENOMEM;
/*
@@ -525,7 +523,7 @@ xpnet_init(void)
*/
xpnet_device = alloc_netdev(0, XPNET_DEVICE_NAME, NET_NAME_UNKNOWN,
ether_setup);
- if (xpnet_device == NULL) {
+ if (!xpnet_device) {
kfree(xpnet_broadcast_partitions);
return -ENOMEM;
}
--
2.15.1