Commit 7dba9203 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by David S. Miller

net/rds: Use ERR_PTR for rds_message_alloc_sgs()

Returning the error code via a 'int *ret' when the function returns a
pointer is very un-kernely and causes gcc 10's static analysis to choke:

net/rds/message.c: In function ‘rds_message_map_pages’:
net/rds/message.c:358:10: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  358 |   return ERR_PTR(ret);

Use a typical ERR_PTR return instead.
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
Acked-by: default avatarSantosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 87b0f983
...@@ -308,26 +308,20 @@ struct rds_message *rds_message_alloc(unsigned int extra_len, gfp_t gfp) ...@@ -308,26 +308,20 @@ struct rds_message *rds_message_alloc(unsigned int extra_len, gfp_t gfp)
/* /*
* RDS ops use this to grab SG entries from the rm's sg pool. * RDS ops use this to grab SG entries from the rm's sg pool.
*/ */
struct scatterlist *rds_message_alloc_sgs(struct rds_message *rm, int nents, struct scatterlist *rds_message_alloc_sgs(struct rds_message *rm, int nents)
int *ret)
{ {
struct scatterlist *sg_first = (struct scatterlist *) &rm[1]; struct scatterlist *sg_first = (struct scatterlist *) &rm[1];
struct scatterlist *sg_ret; struct scatterlist *sg_ret;
if (WARN_ON(!ret))
return NULL;
if (nents <= 0) { if (nents <= 0) {
pr_warn("rds: alloc sgs failed! nents <= 0\n"); pr_warn("rds: alloc sgs failed! nents <= 0\n");
*ret = -EINVAL; return ERR_PTR(-EINVAL);
return NULL;
} }
if (rm->m_used_sgs + nents > rm->m_total_sgs) { if (rm->m_used_sgs + nents > rm->m_total_sgs) {
pr_warn("rds: alloc sgs failed! total %d used %d nents %d\n", pr_warn("rds: alloc sgs failed! total %d used %d nents %d\n",
rm->m_total_sgs, rm->m_used_sgs, nents); rm->m_total_sgs, rm->m_used_sgs, nents);
*ret = -ENOMEM; return ERR_PTR(-ENOMEM);
return NULL;
} }
sg_ret = &sg_first[rm->m_used_sgs]; sg_ret = &sg_first[rm->m_used_sgs];
...@@ -343,7 +337,6 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in ...@@ -343,7 +337,6 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in
unsigned int i; unsigned int i;
int num_sgs = DIV_ROUND_UP(total_len, PAGE_SIZE); int num_sgs = DIV_ROUND_UP(total_len, PAGE_SIZE);
int extra_bytes = num_sgs * sizeof(struct scatterlist); int extra_bytes = num_sgs * sizeof(struct scatterlist);
int ret;
rm = rds_message_alloc(extra_bytes, GFP_NOWAIT); rm = rds_message_alloc(extra_bytes, GFP_NOWAIT);
if (!rm) if (!rm)
...@@ -352,10 +345,10 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in ...@@ -352,10 +345,10 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in
set_bit(RDS_MSG_PAGEVEC, &rm->m_flags); set_bit(RDS_MSG_PAGEVEC, &rm->m_flags);
rm->m_inc.i_hdr.h_len = cpu_to_be32(total_len); rm->m_inc.i_hdr.h_len = cpu_to_be32(total_len);
rm->data.op_nents = DIV_ROUND_UP(total_len, PAGE_SIZE); rm->data.op_nents = DIV_ROUND_UP(total_len, PAGE_SIZE);
rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs, &ret); rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs);
if (!rm->data.op_sg) { if (IS_ERR(rm->data.op_sg)) {
rds_message_put(rm); rds_message_put(rm);
return ERR_PTR(ret); return ERR_CAST(rm->data.op_sg);
} }
for (i = 0; i < rm->data.op_nents; ++i) { for (i = 0; i < rm->data.op_nents; ++i) {
......
...@@ -665,9 +665,11 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm, ...@@ -665,9 +665,11 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
op->op_odp_mr = NULL; op->op_odp_mr = NULL;
WARN_ON(!nr_pages); WARN_ON(!nr_pages);
op->op_sg = rds_message_alloc_sgs(rm, nr_pages, &ret); op->op_sg = rds_message_alloc_sgs(rm, nr_pages);
if (!op->op_sg) if (IS_ERR(op->op_sg)) {
ret = PTR_ERR(op->op_sg);
goto out_pages; goto out_pages;
}
if (op->op_notify || op->op_recverr) { if (op->op_notify || op->op_recverr) {
/* We allocate an uninitialized notifier here, because /* We allocate an uninitialized notifier here, because
...@@ -906,9 +908,11 @@ int rds_cmsg_atomic(struct rds_sock *rs, struct rds_message *rm, ...@@ -906,9 +908,11 @@ int rds_cmsg_atomic(struct rds_sock *rs, struct rds_message *rm,
rm->atomic.op_silent = !!(args->flags & RDS_RDMA_SILENT); rm->atomic.op_silent = !!(args->flags & RDS_RDMA_SILENT);
rm->atomic.op_active = 1; rm->atomic.op_active = 1;
rm->atomic.op_recverr = rs->rs_recverr; rm->atomic.op_recverr = rs->rs_recverr;
rm->atomic.op_sg = rds_message_alloc_sgs(rm, 1, &ret); rm->atomic.op_sg = rds_message_alloc_sgs(rm, 1);
if (!rm->atomic.op_sg) if (IS_ERR(rm->atomic.op_sg)) {
ret = PTR_ERR(rm->atomic.op_sg);
goto err; goto err;
}
/* verify 8 byte-aligned */ /* verify 8 byte-aligned */
if (args->local_addr & 0x7) { if (args->local_addr & 0x7) {
......
...@@ -844,8 +844,7 @@ rds_conn_connecting(struct rds_connection *conn) ...@@ -844,8 +844,7 @@ rds_conn_connecting(struct rds_connection *conn)
/* message.c */ /* message.c */
struct rds_message *rds_message_alloc(unsigned int nents, gfp_t gfp); struct rds_message *rds_message_alloc(unsigned int nents, gfp_t gfp);
struct scatterlist *rds_message_alloc_sgs(struct rds_message *rm, int nents, struct scatterlist *rds_message_alloc_sgs(struct rds_message *rm, int nents);
int *ret);
int rds_message_copy_from_user(struct rds_message *rm, struct iov_iter *from, int rds_message_copy_from_user(struct rds_message *rm, struct iov_iter *from,
bool zcopy); bool zcopy);
struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned int total_len); struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned int total_len);
......
...@@ -1274,9 +1274,11 @@ int rds_sendmsg(struct socket *sock, struct msghdr *msg, size_t payload_len) ...@@ -1274,9 +1274,11 @@ int rds_sendmsg(struct socket *sock, struct msghdr *msg, size_t payload_len)
/* Attach data to the rm */ /* Attach data to the rm */
if (payload_len) { if (payload_len) {
rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs, &ret); rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs);
if (!rm->data.op_sg) if (IS_ERR(rm->data.op_sg)) {
ret = PTR_ERR(rm->data.op_sg);
goto out; goto out;
}
ret = rds_message_copy_from_user(rm, &msg->msg_iter, zcopy); ret = rds_message_copy_from_user(rm, &msg->msg_iter, zcopy);
if (ret) if (ret)
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment