Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

IB/mad: Change atomics to refcount API

The refcount API provides better safety than atomics API. Therefore,
change atomic functions to refcount functions.

Link: https://lore.kernel.org/r/20200621104738.54850-4-leon@kernel.org
Signed-off-by: Shay Drory <shayd@mellanox.com>
Reviewed-by: Maor Gottlieb <maorg@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Shay Drory and committed by
Jason Gunthorpe
e41c4253 b9af0e2d

+14 -14
+8 -8
drivers/infiniband/core/mad.c
··· 402 402 INIT_DELAYED_WORK(&mad_agent_priv->timed_work, timeout_sends); 403 403 INIT_LIST_HEAD(&mad_agent_priv->local_list); 404 404 INIT_WORK(&mad_agent_priv->local_work, local_completions); 405 - atomic_set(&mad_agent_priv->refcount, 1); 405 + refcount_set(&mad_agent_priv->refcount, 1); 406 406 init_completion(&mad_agent_priv->comp); 407 407 408 408 ret2 = ib_mad_agent_security_setup(&mad_agent_priv->agent, qp_type); ··· 484 484 485 485 static inline void deref_mad_agent(struct ib_mad_agent_private *mad_agent_priv) 486 486 { 487 - if (atomic_dec_and_test(&mad_agent_priv->refcount)) 487 + if (refcount_dec_and_test(&mad_agent_priv->refcount)) 488 488 complete(&mad_agent_priv->comp); 489 489 } 490 490 ··· 718 718 * Reference MAD agent until receive 719 719 * side of local completion handled 720 720 */ 721 - atomic_inc(&mad_agent_priv->refcount); 721 + refcount_inc(&mad_agent_priv->refcount); 722 722 } else 723 723 kfree(mad_priv); 724 724 break; ··· 758 758 local->return_wc_byte_len = mad_size; 759 759 } 760 760 /* Reference MAD agent until send side of local completion handled */ 761 - atomic_inc(&mad_agent_priv->refcount); 761 + refcount_inc(&mad_agent_priv->refcount); 762 762 /* Queue local completion to local list */ 763 763 spin_lock_irqsave(&mad_agent_priv->lock, flags); 764 764 list_add_tail(&local->completion_list, &mad_agent_priv->local_list); ··· 916 916 } 917 917 918 918 mad_send_wr->send_buf.mad_agent = mad_agent; 919 - atomic_inc(&mad_agent_priv->refcount); 919 + refcount_inc(&mad_agent_priv->refcount); 920 920 return &mad_send_wr->send_buf; 921 921 } 922 922 EXPORT_SYMBOL(ib_create_send_mad); ··· 1131 1131 mad_send_wr->status = IB_WC_SUCCESS; 1132 1132 1133 1133 /* Reference MAD agent until send completes */ 1134 - atomic_inc(&mad_agent_priv->refcount); 1134 + refcount_inc(&mad_agent_priv->refcount); 1135 1135 spin_lock_irqsave(&mad_agent_priv->lock, flags); 1136 1136 list_add_tail(&mad_send_wr->agent_list, 1137 1137 &mad_agent_priv->send_list); ··· 1554 1554 hi_tid = be64_to_cpu(mad_hdr->tid) >> 32; 1555 1555 rcu_read_lock(); 1556 1556 mad_agent = xa_load(&ib_mad_clients, hi_tid); 1557 - if (mad_agent && !atomic_inc_not_zero(&mad_agent->refcount)) 1557 + if (mad_agent && !refcount_inc_not_zero(&mad_agent->refcount)) 1558 1558 mad_agent = NULL; 1559 1559 rcu_read_unlock(); 1560 1560 } else { ··· 1606 1606 } 1607 1607 } 1608 1608 if (mad_agent) 1609 - atomic_inc(&mad_agent->refcount); 1609 + refcount_inc(&mad_agent->refcount); 1610 1610 out: 1611 1611 spin_unlock_irqrestore(&port_priv->reg_lock, flags); 1612 1612 }
+1 -1
drivers/infiniband/core/mad_priv.h
··· 103 103 struct work_struct local_work; 104 104 struct list_head rmpp_list; 105 105 106 - atomic_t refcount; 106 + refcount_t refcount; 107 107 union { 108 108 struct completion comp; 109 109 struct rcu_head rcu;
+5 -5
drivers/infiniband/core/mad_rmpp.c
··· 52 52 struct completion comp; 53 53 enum rmpp_state state; 54 54 spinlock_t lock; 55 - atomic_t refcount; 55 + refcount_t refcount; 56 56 57 57 struct ib_ah *ah; 58 58 struct ib_mad_recv_wc *rmpp_wc; ··· 73 73 74 74 static inline void deref_rmpp_recv(struct mad_rmpp_recv *rmpp_recv) 75 75 { 76 - if (atomic_dec_and_test(&rmpp_recv->refcount)) 76 + if (refcount_dec_and_test(&rmpp_recv->refcount)) 77 77 complete(&rmpp_recv->comp); 78 78 } 79 79 ··· 305 305 INIT_DELAYED_WORK(&rmpp_recv->cleanup_work, recv_cleanup_handler); 306 306 spin_lock_init(&rmpp_recv->lock); 307 307 rmpp_recv->state = RMPP_STATE_ACTIVE; 308 - atomic_set(&rmpp_recv->refcount, 1); 308 + refcount_set(&rmpp_recv->refcount, 1); 309 309 310 310 rmpp_recv->rmpp_wc = mad_recv_wc; 311 311 rmpp_recv->cur_seg_buf = &mad_recv_wc->recv_buf; ··· 357 357 spin_lock_irqsave(&agent->lock, flags); 358 358 rmpp_recv = find_rmpp_recv(agent, mad_recv_wc); 359 359 if (rmpp_recv) 360 - atomic_inc(&rmpp_recv->refcount); 360 + refcount_inc(&rmpp_recv->refcount); 361 361 spin_unlock_irqrestore(&agent->lock, flags); 362 362 return rmpp_recv; 363 363 } ··· 553 553 destroy_rmpp_recv(rmpp_recv); 554 554 return continue_rmpp(agent, mad_recv_wc); 555 555 } 556 - atomic_inc(&rmpp_recv->refcount); 556 + refcount_inc(&rmpp_recv->refcount); 557 557 558 558 if (get_last_flag(&mad_recv_wc->recv_buf)) { 559 559 rmpp_recv->state = RMPP_STATE_COMPLETE;