From: Kamal Heib <kamalheib1@gmail.com>
To: linux-rdma@vger.kernel.org
Cc: Doug Ledford <dledford@redhat.com>,
Jason Gunthorpe <jgg@ziepe.ca>,
Michal Kalderon <mkalderon@marvell.com>,
Potnuri Bharat Teja <bharat@chelsio.com>,
Shiraz Saleem <shiraz.saleem@intel.com>,
Bernard Metzler <bmt@zurich.ibm.com>,
Kamal Heib <kamalheib1@gmail.com>
Subject: [PATCH for-next v1 2/7] RDMA/core: Allocate the pkey cache only if the pkey_tbl_len is set
Date: Tue, 14 Jul 2020 21:34:09 +0300 [thread overview]
Message-ID: <20200714183414.61069-3-kamalheib1@gmail.com> (raw)
In-Reply-To: <20200714183414.61069-1-kamalheib1@gmail.com>
Allocate the pkey cache only if the pkey_tbl_len is set by the provider,
also add checks to avoid accessing the pkey cache when it not
initialized.
Signed-off-by: Kamal Heib <kamalheib1@gmail.com>
---
drivers/infiniband/core/cache.c | 45 +++++++++++++++++++++------------
1 file changed, 29 insertions(+), 16 deletions(-)
diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c
index a670209bbce6..ffad73bb40ff 100644
--- a/drivers/infiniband/core/cache.c
+++ b/drivers/infiniband/core/cache.c
@@ -1054,7 +1054,7 @@ int ib_get_cached_pkey(struct ib_device *device,
cache = device->port_data[port_num].cache.pkey;
- if (index < 0 || index >= cache->table_len)
+ if (!cache || index < 0 || index >= cache->table_len)
ret = -EINVAL;
else
*pkey = cache->table[index];
@@ -1099,6 +1099,10 @@ int ib_find_cached_pkey(struct ib_device *device,
read_lock_irqsave(&device->cache_lock, flags);
cache = device->port_data[port_num].cache.pkey;
+ if (!cache) {
+ ret = -EINVAL;
+ goto err;
+ }
*index = -1;
@@ -1117,6 +1121,7 @@ int ib_find_cached_pkey(struct ib_device *device,
ret = 0;
}
+err:
read_unlock_irqrestore(&device->cache_lock, flags);
return ret;
@@ -1139,6 +1144,10 @@ int ib_find_exact_cached_pkey(struct ib_device *device,
read_lock_irqsave(&device->cache_lock, flags);
cache = device->port_data[port_num].cache.pkey;
+ if (!cache) {
+ ret = -EINVAL;
+ goto err;
+ }
*index = -1;
@@ -1149,6 +1158,7 @@ int ib_find_exact_cached_pkey(struct ib_device *device,
break;
}
+err:
read_unlock_irqrestore(&device->cache_lock, flags);
return ret;
@@ -1425,23 +1435,26 @@ ib_cache_update(struct ib_device *device, u8 port, bool enforce_security)
goto err;
}
- pkey_cache = kmalloc(struct_size(pkey_cache, table,
- tprops->pkey_tbl_len),
- GFP_KERNEL);
- if (!pkey_cache) {
- ret = -ENOMEM;
- goto err;
- }
+ if (tprops->pkey_tbl_len) {
+ pkey_cache = kmalloc(struct_size(pkey_cache, table,
+ tprops->pkey_tbl_len),
+ GFP_KERNEL);
+ if (!pkey_cache) {
+ ret = -ENOMEM;
+ goto err;
+ }
- pkey_cache->table_len = tprops->pkey_tbl_len;
+ pkey_cache->table_len = tprops->pkey_tbl_len;
- for (i = 0; i < pkey_cache->table_len; ++i) {
- ret = ib_query_pkey(device, port, i, pkey_cache->table + i);
- if (ret) {
- dev_warn(&device->dev,
- "ib_query_pkey failed (%d) for index %d\n",
- ret, i);
- goto err;
+ for (i = 0; i < pkey_cache->table_len; ++i) {
+ ret = ib_query_pkey(device, port, i,
+ pkey_cache->table + i);
+ if (ret) {
+ dev_warn(&device->dev,
+ "ib_query_pkey failed (%d) for index %d\n",
+ ret, i);
+ goto err;
+ }
}
}
--
2.25.4
next prev parent reply other threads:[~2020-07-14 18:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-14 18:34 [PATCH for-next v1 0/7] RDMA: Remove query_pkey from iwarp providers Kamal Heib
2020-07-14 18:34 ` [PATCH for-next v1 1/7] RDMA/core: Expose pkeys sysfs files only if pkey_tbl_len is set Kamal Heib
2020-07-14 18:34 ` Kamal Heib [this message]
2020-07-14 18:34 ` [PATCH for-next v1 3/7] RDMA/core: Remove query_pkey from the mandatory ops Kamal Heib
2020-07-14 18:34 ` [PATCH for-next v1 4/7] RDMA/siw: Remove the query_pkey callback Kamal Heib
2020-07-14 18:34 ` [PATCH for-next v1 5/7] RDMA/cxgb4: " Kamal Heib
2020-07-14 18:34 ` [PATCH for-next v1 6/7] RDMA/i40iw: " Kamal Heib
2020-07-14 18:34 ` [PATCH for-next v1 7/7] RDMA/qedr: " Kamal Heib
2020-07-14 22:34 ` [PATCH for-next v1 0/7] RDMA: Remove query_pkey from iwarp providers Saleem, Shiraz
2020-07-15 7:29 ` [PATCH for-next v1 4/7] RDMA/siw: Remove the query_pkey callback Bernard Metzler
2020-07-20 19:24 ` [PATCH for-next v1 0/7] RDMA: Remove query_pkey from iwarp providers Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200714183414.61069-3-kamalheib1@gmail.com \
--to=kamalheib1@gmail.com \
--cc=bharat@chelsio.com \
--cc=bmt@zurich.ibm.com \
--cc=dledford@redhat.com \
--cc=jgg@ziepe.ca \
--cc=linux-rdma@vger.kernel.org \
--cc=mkalderon@marvell.com \
--cc=shiraz.saleem@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).