| .. | .. |
|---|
| 1 | 1 | /* |
|---|
| 2 | | - * Copyright (c) 2006 Oracle. All rights reserved. |
|---|
| 2 | + * Copyright (c) 2006, 2020 Oracle and/or its affiliates. |
|---|
| 3 | 3 | * |
|---|
| 4 | 4 | * This software is available to you under a choice of one of two |
|---|
| 5 | 5 | * licenses. You may choose to be licensed under the terms of the GNU |
|---|
| .. | .. |
|---|
| 104 | 104 | spin_lock_irqsave(&q->lock, flags); |
|---|
| 105 | 105 | head = &q->zcookie_head; |
|---|
| 106 | 106 | if (!list_empty(head)) { |
|---|
| 107 | | - info = list_entry(head, struct rds_msg_zcopy_info, |
|---|
| 108 | | - rs_zcookie_next); |
|---|
| 109 | | - if (info && rds_zcookie_add(info, cookie)) { |
|---|
| 107 | + info = list_first_entry(head, struct rds_msg_zcopy_info, |
|---|
| 108 | + rs_zcookie_next); |
|---|
| 109 | + if (rds_zcookie_add(info, cookie)) { |
|---|
| 110 | 110 | spin_unlock_irqrestore(&q->lock, flags); |
|---|
| 111 | 111 | kfree(rds_info_from_znotifier(znotif)); |
|---|
| 112 | 112 | /* caller invokes rds_wake_sk_sleep() */ |
|---|
| .. | .. |
|---|
| 118 | 118 | ck = &info->zcookies; |
|---|
| 119 | 119 | memset(ck, 0, sizeof(*ck)); |
|---|
| 120 | 120 | WARN_ON(!rds_zcookie_add(info, cookie)); |
|---|
| 121 | | - list_add_tail(&q->zcookie_head, &info->rs_zcookie_next); |
|---|
| 121 | + list_add_tail(&info->rs_zcookie_next, &q->zcookie_head); |
|---|
| 122 | 122 | |
|---|
| 123 | 123 | spin_unlock_irqrestore(&q->lock, flags); |
|---|
| 124 | 124 | /* caller invokes rds_wake_sk_sleep() */ |
|---|
| .. | .. |
|---|
| 162 | 162 | if (rm->rdma.op_active) |
|---|
| 163 | 163 | rds_rdma_free_op(&rm->rdma); |
|---|
| 164 | 164 | if (rm->rdma.op_rdma_mr) |
|---|
| 165 | | - rds_mr_put(rm->rdma.op_rdma_mr); |
|---|
| 165 | + kref_put(&rm->rdma.op_rdma_mr->r_kref, __rds_put_mr_final); |
|---|
| 166 | 166 | |
|---|
| 167 | 167 | if (rm->atomic.op_active) |
|---|
| 168 | 168 | rds_atomic_free_op(&rm->atomic); |
|---|
| 169 | 169 | if (rm->atomic.op_rdma_mr) |
|---|
| 170 | | - rds_mr_put(rm->atomic.op_rdma_mr); |
|---|
| 170 | + kref_put(&rm->atomic.op_rdma_mr->r_kref, __rds_put_mr_final); |
|---|
| 171 | 171 | } |
|---|
| 172 | 172 | |
|---|
| 173 | 173 | void rds_message_put(struct rds_message *rm) |
|---|
| .. | .. |
|---|
| 313 | 313 | struct scatterlist *sg_first = (struct scatterlist *) &rm[1]; |
|---|
| 314 | 314 | struct scatterlist *sg_ret; |
|---|
| 315 | 315 | |
|---|
| 316 | | - WARN_ON(rm->m_used_sgs + nents > rm->m_total_sgs); |
|---|
| 317 | | - WARN_ON(!nents); |
|---|
| 316 | + if (nents <= 0) { |
|---|
| 317 | + pr_warn("rds: alloc sgs failed! nents <= 0\n"); |
|---|
| 318 | + return ERR_PTR(-EINVAL); |
|---|
| 319 | + } |
|---|
| 318 | 320 | |
|---|
| 319 | | - if (rm->m_used_sgs + nents > rm->m_total_sgs) |
|---|
| 320 | | - return NULL; |
|---|
| 321 | + if (rm->m_used_sgs + nents > rm->m_total_sgs) { |
|---|
| 322 | + pr_warn("rds: alloc sgs failed! total %d used %d nents %d\n", |
|---|
| 323 | + rm->m_total_sgs, rm->m_used_sgs, nents); |
|---|
| 324 | + return ERR_PTR(-ENOMEM); |
|---|
| 325 | + } |
|---|
| 321 | 326 | |
|---|
| 322 | 327 | sg_ret = &sg_first[rm->m_used_sgs]; |
|---|
| 323 | 328 | sg_init_table(sg_ret, nents); |
|---|
| .. | .. |
|---|
| 330 | 335 | { |
|---|
| 331 | 336 | struct rds_message *rm; |
|---|
| 332 | 337 | unsigned int i; |
|---|
| 333 | | - int num_sgs = ceil(total_len, PAGE_SIZE); |
|---|
| 338 | + int num_sgs = DIV_ROUND_UP(total_len, PAGE_SIZE); |
|---|
| 334 | 339 | int extra_bytes = num_sgs * sizeof(struct scatterlist); |
|---|
| 335 | 340 | |
|---|
| 336 | 341 | rm = rds_message_alloc(extra_bytes, GFP_NOWAIT); |
|---|
| .. | .. |
|---|
| 339 | 344 | |
|---|
| 340 | 345 | set_bit(RDS_MSG_PAGEVEC, &rm->m_flags); |
|---|
| 341 | 346 | rm->m_inc.i_hdr.h_len = cpu_to_be32(total_len); |
|---|
| 342 | | - rm->data.op_nents = ceil(total_len, PAGE_SIZE); |
|---|
| 347 | + rm->data.op_nents = DIV_ROUND_UP(total_len, PAGE_SIZE); |
|---|
| 343 | 348 | rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs); |
|---|
| 344 | | - if (!rm->data.op_sg) { |
|---|
| 349 | + if (IS_ERR(rm->data.op_sg)) { |
|---|
| 350 | + void *err = ERR_CAST(rm->data.op_sg); |
|---|
| 345 | 351 | rds_message_put(rm); |
|---|
| 346 | | - return ERR_PTR(-ENOMEM); |
|---|
| 352 | + return err; |
|---|
| 347 | 353 | } |
|---|
| 348 | 354 | |
|---|
| 349 | 355 | for (i = 0; i < rm->data.op_nents; ++i) { |
|---|