InfiniBand-ULP: Fine-tuning for several function implementations
Subsystems (4)
cover InfiniBand-ULP: Fine-tuning for several function implementations
From: Markus Elfring <[email protected]>
Date: Fri, 7 Apr 2017 22:34:32 +0200
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (9):
IPoIB: Use kcalloc() in two functions
IPoIB: Delete an error message for a failed memory allocation
IPoIB: Enclose six expressions for the sizeof operator by parentheses
IPoIB: Delete unwanted spaces behind usages of the sizeof operator
IPoIB: Combine substrings for three messages
iser: Use kmalloc_array() in iser_alloc_rx_descriptors()
iser: Add spaces for better code readability
isert: Use kcalloc() in isert_alloc_rx_descriptors()
isert: Improve size determinations in three functions
drivers/infiniband/ulp/ipoib/ipoib_main.c | 49 ++++++++++++++-------------- drivers/infiniband/ulp/iser/iser_initiator.c | 11 ++++--- drivers/infiniband/ulp/isert/ib_isert.c | 11 ++++--- 3 files changed, 36 insertions(+), 35 deletions(-)
Signature · 1 line
2.12.2
PATCH 1/9 IB/IPoIB: Use kcalloc() in two functions
From: Markus Elfring <[email protected]>
Date: Fri, 7 Apr 2017 17:43:51 +0200
Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kcalloc".
This issue was detected by using the Coccinelle software.
--- drivers/infiniband/ulp/ipoib/ipoib_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib_main.c +2 -2
@@ -1484,7 +1484,7 @@ static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv)return -ENOMEM ;set_bit (IPOIB_STOP_NEIGH_GC , &priv->flags); size =roundup_pow_of_two (arp_tbl.gc_thresh3); - buckets =kzalloc (size *sizeof (*buckets),GFP_KERNEL ); + buckets =kcalloc (size,sizeof (*buckets),GFP_KERNEL );if (!buckets) {kfree (htbl);return -ENOMEM ;
@@ -1628,7 +1628,7 @@ int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port)struct ipoib_dev_priv *priv =netdev_priv (dev);/* Allocate RX/TX "rings" to hold queued skbs */ - priv->rx_ring =kzalloc (ipoib_recvq_size *sizeof *priv->rx_ring, + priv->rx_ring =kcalloc (ipoib_recvq_size,sizeof (*priv->rx_ring),GFP_KERNEL );if (!priv->rx_ring) goto out;
Signature · 1 line
2.12.2
Re: [PATCH 1/9] IB/IPoIB: Use kcalloc() in two functions
PATCH 2/9 IB/IPoIB: Delete an error message for a failed memory allocation
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 7 Apr 2017 19:23:55 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: Possible unnecessary 'out of memory' message
Thus remove such a statement here.
--- drivers/infiniband/ulp/ipoib/ipoib_main.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib_main.c +1 -4
@@ -1634,11 +1634,8 @@ int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port) goto out; priv->tx_ring =vzalloc (ipoib_sendq_size *sizeof *priv->tx_ring); -if (!priv->tx_ring) { -printk (KERN_WARNING "%s: failed to allocate TX ring (%d entries)\n" , - ca->name, ipoib_sendq_size); +if (!priv->tx_ring) goto out_rx_ring_cleanup; - }/* priv->tx_head, tx_tail & tx_outstanding are already 0 */
Signature · 1 line
2.12.2
Re: [PATCH 2/9] IB/IPoIB: Delete an error message for a failed memory allocation
PATCH 3/9 IB/IPoIB: Enclose six expressions for the sizeof operator by parentheses
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 7 Apr 2017 19:54:15 +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.
WARNING: sizeof *… should be sizeof(*…)
Thus fix the affected source code places.
--- drivers/infiniband/ulp/ipoib/ipoib_main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib_main.c +6 -6
@@ -581,7 +581,7 @@ struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev) {struct ipoib_path_iter *iter; - iter =kmalloc (sizeof *iter,GFP_KERNEL ); + iter =kmalloc (sizeof (*iter),GFP_KERNEL );if (!iter)return NULL ;
@@ -864,7 +864,7 @@ static struct ipoib_path *path_rec_create(struct net_device *dev, void *gid)if (!priv->broadcast)return NULL ; - path =kzalloc (sizeof *path,GFP_ATOMIC ); + path =kzalloc (sizeof (*path),GFP_ATOMIC );if (!path)return NULL ;
@@ -1161,7 +1161,7 @@ static int ipoib_hard_header(struct sk_buff *skb, {struct ipoib_header *header; - header = (struct ipoib_header *)skb_push (skb,sizeof *header); + header = (struct ipoib_header *)skb_push (skb,sizeof (*header)); header->proto =htons (type); header->reserved =0 ;
@@ -1329,7 +1329,7 @@ static struct ipoib_neigh *ipoib_neigh_ctor(u8 *daddr, {struct ipoib_neigh *neigh; - neigh =kzalloc (sizeof *neigh,GFP_ATOMIC ); + neigh =kzalloc (sizeof (*neigh),GFP_ATOMIC );if (!neigh)return NULL ;
@@ -1633,7 +1633,7 @@ int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port)if (!priv->rx_ring) goto out; - priv->tx_ring =vzalloc (ipoib_sendq_size *sizeof *priv->tx_ring); + priv->tx_ring =vzalloc (ipoib_sendq_size *sizeof (*priv->tx_ring));if (!priv->tx_ring) goto out_rx_ring_cleanup;
@@ -2132,7 +2132,7 @@ static void ipoib_add_one(struct ib_device *device)int p;int count =0 ; - dev_list =kmalloc (sizeof *dev_list,GFP_KERNEL ); + dev_list =kmalloc (sizeof (*dev_list),GFP_KERNEL );if (!dev_list)return ;
Signature · 1 line
2.12.2
Re: [PATCH 3/9] IB/IPoIB: Enclose six expressions for the sizeof operator by parentheses
PATCH 4/9 IB/IPoIB: Delete unwanted spaces behind usages of the sizeof operator
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 7 Apr 2017 20:10:45 +0200
* Replace the source code "sizeof (" by "sizeof("
according to the Linux coding style convention.
* Adjust indentation at a few places.
--- drivers/infiniband/ulp/ipoib/ipoib_main.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib_main.c +8 -7
@@ -514,8 +514,7 @@ struct ipoib_path *__path_find(struct net_device *dev, void *gid) path = rb_entry(n, struct ipoib_path, rb_node); ret =memcmp (gid, path->pathrec.dgid.raw, -sizeof (union ib_gid )); - +sizeof (union ib_gid ));if (ret <0 ) n = n->rb_left;else if (ret >0 )
@@ -540,7 +539,7 @@ static int __path_add(struct net_device *dev, struct ipoib_path *path) tpath = rb_entry(pn, struct ipoib_path, rb_node); ret =memcmp (path->pathrec.dgid.raw, tpath->pathrec.dgid.raw, -sizeof (union ib_gid )); +sizeof (union ib_gid ));if (ret <0 ) n = &pn->rb_left;else if (ret >0 )
@@ -611,7 +610,7 @@ int ipoib_path_iter_next(struct ipoib_path_iter *iter) path = rb_entry(n, struct ipoib_path, rb_node);if (memcmp (iter->path.pathrec.dgid.raw, path->pathrec.dgid.raw, -sizeof (union ib_gid )) <0 ) { +sizeof (union ib_gid )) <0 ) { iter->path = *path; ret =0 ;break ;
@@ -874,7 +873,7 @@ static struct ipoib_path *path_rec_create(struct net_device *dev, void *gid)INIT_LIST_HEAD (&path->neigh_list); -memcpy (path->pathrec.dgid.raw, gid,sizeof (union ib_gid )); +memcpy (path->pathrec.dgid.raw, gid,sizeof (union ib_gid )); path->pathrec.sgid = priv->local_gid; path->pathrec.pkey =cpu_to_be16 (priv->pkey); path->pathrec.numb_path =1 ;
@@ -1541,7 +1540,8 @@ void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid)while ((neigh =rcu_dereference_protected (*np,lockdep_is_held (&priv->lock))) !=NULL ) {/* delete neighs belong to this parent */ -if (!memcmp (gid, neigh->daddr +4 ,sizeof (union ib_gid ))) { +if (!memcmp (gid, neigh->daddr +4 , +sizeof (union ib_gid ))) {rcu_assign_pointer (*np,rcu_dereference_protected (neigh->hnext,lockdep_is_held (&priv->lock)));
@@ -2060,7 +2060,8 @@ static struct net_device *ipoib_add_port(const char *format, hca->name, port, result); goto device_init_failed; }else -memcpy (priv->dev->dev_addr +4 , priv->local_gid.raw,sizeof (union ib_gid )); +memcpy (priv->dev->dev_addr +4 , priv->local_gid.raw, +sizeof (union ib_gid ));set_bit (IPOIB_FLAG_DEV_ADDR_SET , &priv->flags); result =ipoib_dev_init (priv->dev, hca, port);
Signature · 1 line
2.12.2
Re: [PATCH 4/9] IB/IPoIB: Delete unwanted spaces behind usages of the sizeof operator
PATCH 5/9 IB/IPoIB: Combine substrings for three messages
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 7 Apr 2017 21:06:08 +0200
The script "checkpatch.pl" pointed information out like the following.
WARNING: quoted string split across lines
Thus fix affected source code places.
--- drivers/infiniband/ulp/ipoib/ipoib_main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib_main.c +7 -6
@@ -226,8 +226,9 @@ static int ipoib_change_mtu(struct net_device *dev, int new_mtu) priv->admin_mtu = new_mtu;if (priv->mcast_mtu < priv->admin_mtu) -ipoib_dbg (priv,"MTU must be smaller than the underlying " -"link layer MTU - 4 (%u)\n" , priv->mcast_mtu); +ipoib_dbg (priv, +"MTU must be smaller than the underlying link layer MTU - 4 (%u)\n" , + priv->mcast_mtu); dev->mtu =min (priv->mcast_mtu, priv->admin_mtu);
@@ -480,8 +481,8 @@ int ipoib_set_mode(struct net_device *dev, const char *buf)/* flush paths if we switch modes so that connections are restarted */ if (IPOIB_CM_SUPPORTED (dev->dev_addr) && !strcmp (buf,"connected\n" )) {set_bit (IPOIB_FLAG_ADMIN_CM , &priv->flags); -ipoib_warn (priv,"enabling connected mode " -"will cause multicast packet drops\n" ); +ipoib_warn (priv, +"enabling connected mode will cause multicast packet drops\n" );netdev_update_features (dev);dev_set_mtu (dev,ipoib_cm_max_mtu (dev));rtnl_unlock ();
@@ -1855,8 +1856,8 @@ void ipoib_set_umcast(struct net_device *ndev, int umcast_val)if (umcast_val >0 ) {set_bit (IPOIB_FLAG_UMCAST , &priv->flags); -ipoib_warn (priv,"ignoring multicast groups joined directly " -"by userspace\n" ); +ipoib_warn (priv, +"ignoring multicast groups joined directly by userspace\n" ); }else clear_bit (IPOIB_FLAG_UMCAST , &priv->flags); }
Signature · 1 line
2.12.2
Re: [PATCH 5/9] IB/IPoIB: Combine substrings for three messages
Quoted 10 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 7 Apr 2017 21:06:08 +0200The script "checkpatch.pl" pointed information out like the following.
WARNING: quoted string split across lines
Thus fix affected source code places.
Signed-off-by Markus Elfring <[email protected]>
Quoted 45 lines
--- drivers/infiniband/ulp/ipoib/ipoib_main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/infiniband/ulp/ipoib/ipoib_main.c +7
-6@@ -226,8 +226,9 @@ static int ipoib_change_mtu(struct net_device *dev, int new_mtu) priv->admin_mtu = new_mtu;if (priv->mcast_mtu < priv->admin_mtu) -ipoib_dbg (priv,"MTU must be smaller than the underlying " -"link layer MTU - 4 (%u)\n" , priv->mcast_mtu); +ipoib_dbg (priv, +"MTU must be smaller than the underlying link layer MTU - 4 (%u)\n" , + priv->mcast_mtu); dev->mtu =min (priv->mcast_mtu, priv->admin_mtu);@@ -480,8 +481,8 @@ int ipoib_set_mode(struct net_device *dev, const char *buf)/* flush paths if we switch modes so that connections are restarted */ if (IPOIB_CM_SUPPORTED (dev->dev_addr) && !strcmp (buf,"connected\n" )) {set_bit (IPOIB_FLAG_ADMIN_CM , &priv->flags); -ipoib_warn (priv,"enabling connected mode " -"will cause multicast packet drops\n" ); +ipoib_warn (priv, +"enabling connected mode will cause multicast packet drops\n" );netdev_update_features (dev);dev_set_mtu (dev,ipoib_cm_max_mtu (dev));rtnl_unlock ();@@ -1855,8 +1856,8 @@ void ipoib_set_umcast(struct net_device *ndev, int umcast_val)if (umcast_val >0 ) {set_bit (IPOIB_FLAG_UMCAST , &priv->flags); -ipoib_warn (priv,"ignoring multicast groups joined directly " -"by userspace\n" ); +ipoib_warn (priv, +"ignoring multicast groups joined directly by userspace\n" ); }else clear_bit (IPOIB_FLAG_UMCAST , &priv->flags); }Signature · 1 line
2.12.2
PATCH 6/9 IB/iser: Use kmalloc_array() in iser_alloc_rx_descriptors()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 7 Apr 2017 21:23:29 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/infiniband/ulp/iser/iser_initiator.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/iser/iser_initiator.c +3 -2
@@ -257,8 +257,9 @@ int iser_alloc_rx_descriptors(struct iser_conn *iser_conn, goto alloc_login_buf_fail; iser_conn->num_rx_descs = session->cmds_max; - iser_conn->rx_descs =kmalloc (iser_conn->num_rx_descs * -sizeof (struct iser_rx_desc ),GFP_KERNEL ); + iser_conn->rx_descs =kmalloc_array (iser_conn->num_rx_descs, +sizeof (*iser_conn->rx_descs), +GFP_KERNEL );if (!iser_conn->rx_descs) goto rx_desc_alloc_fail;
Signature · 1 line
2.12.2
Re: [PATCH 6/9] IB/iser: Use kmalloc_array() in iser_alloc_rx_descriptors()
PATCH 7/9 IB/iser: Add spaces for better code readability
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 7 Apr 2017 21:37:48 +0200
The script "checkpatch.pl" pointed information out like the following.
ERROR: space required after that ',' (ctx:VxV)
Thus fix the affected source code places.
--- drivers/infiniband/ulp/iser/iser_initiator.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/infiniband/ulp/iser/iser_initiator.c +3 -3
@@ -422,7 +422,7 @@ int iser_send_command(struct iscsi_conn *conn,return 0 ; send_command_error: -iser_err ("conn %p failed task->itt %d err %d\n" ,conn, task->itt, err); +iser_err ("conn %p failed task->itt %d err %d\n" , conn, task->itt, err);return err; }
@@ -448,7 +448,7 @@ int iser_send_data_out(struct iscsi_conn *conn, buf_offset =ntohl (hdr->offset);iser_dbg ("%s itt %d dseg_len %d offset %d\n" , - __func__,(int )itt,(int )data_seg_len,(int )buf_offset); + __func__, (int )itt, (int )data_seg_len, (int )buf_offset); tx_desc =kmem_cache_zalloc (ig.desc_cache,GFP_ATOMIC );if (tx_desc =NULL ) {
@@ -553,7 +553,7 @@ int iser_send_control(struct iscsi_conn *conn,return 0 ; send_control_error: -iser_err ("conn %p failed err %d\n" ,conn, err); +iser_err ("conn %p failed err %d\n" , conn, err);return err; }
Signature · 1 line
2.12.2
Re: [PATCH 7/9] IB/iser: Add spaces for better code readability
PATCH 8/9 IB/isert: Use kcalloc() in isert_alloc_rx_descriptors()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 7 Apr 2017 22:00:43 +0200
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/infiniband/ulp/isert/ib_isert.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/isert/ib_isert.c +3 -2
@@ -181,8 +181,9 @@ isert_alloc_rx_descriptors(struct isert_conn *isert_conn)u64 dma_addr;int i, j; - isert_conn->rx_descs =kzalloc (ISERT_QP_MAX_RECV_DTOS * -sizeof (struct iser_rx_desc ),GFP_KERNEL ); + isert_conn->rx_descs =kcalloc (ISERT_QP_MAX_RECV_DTOS , +sizeof (*isert_conn->rx_descs), +GFP_KERNEL );if (!isert_conn->rx_descs)return -ENOMEM ;
Signature · 1 line
2.12.2
Re: [PATCH 8/9] IB/isert: Use kcalloc() in isert_alloc_rx_descriptors()
PATCH 9/9 IB/isert: Improve size determinations in three functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 7 Apr 2017 22:20:39 +0200
Replace the specification of three data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determinations a bit safer according to the Linux coding style convention.
--- drivers/infiniband/ulp/isert/ib_isert.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/infiniband/ulp/isert/ib_isert.c +3 -3
@@ -368,7 +368,7 @@ isert_device_get(struct rdma_cm_id *cma_id) } } - device =kzalloc (sizeof (struct isert_device ),GFP_KERNEL ); + device =kzalloc (sizeof (*device),GFP_KERNEL );if (!device) {mutex_unlock (&device_list_mutex);return ERR_PTR (-ENOMEM );
@@ -516,7 +516,7 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)isert_dbg ("cma_id: %p, portal: %p\n" , cma_id, cma_id->context); - isert_conn =kzalloc (sizeof (struct isert_conn ),GFP_KERNEL ); + isert_conn =kzalloc (sizeof (*isert_conn),GFP_KERNEL );if (!isert_conn)return -ENOMEM ;
@@ -2306,7 +2306,7 @@ isert_setup_np(struct iscsi_np *np,struct rdma_cm_id *isert_lid;int ret; - isert_np =kzalloc (sizeof (struct isert_np ),GFP_KERNEL ); + isert_np =kzalloc (sizeof (*isert_np),GFP_KERNEL );if (!isert_np)return -ENOMEM ;
Signature · 1 line
2.12.2
Re: [PATCH 9/9] IB/isert: Improve size determinations in three functions