hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I76JHC
--------------------------------
This add the ability to get a unused smc_buf_desc based on the buf size which ensures that the size of obtained smc_buf_desc is the same as the size set.
Signed-off-by: Litao Jiao jiaolitao@sangfor.com.cn --- net/smc/smc_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c index 525dd7543c60..f3f296e206aa 100644 --- a/net/smc/smc_core.c +++ b/net/smc/smc_core.c @@ -1425,7 +1425,7 @@ int smc_uncompress_bufsize(u8 compressed) /* try to reuse a sndbuf or rmb description slot for a certain * buffer size; if not available, return NULL */ -static struct smc_buf_desc *smc_buf_get_slot(int compressed_bufsize, +static struct smc_buf_desc *smc_buf_get_slot(int bufsize, struct mutex *lock, struct list_head *buf_list) { @@ -1433,7 +1433,7 @@ static struct smc_buf_desc *smc_buf_get_slot(int compressed_bufsize,
mutex_lock(lock); list_for_each_entry(buf_slot, buf_list, list) { - if (cmpxchg(&buf_slot->used, 0, 1) == 0) { + if ((buf_slot->len == bufsize) && (cmpxchg(&buf_slot->used, 0, 1) == 0)) { mutex_unlock(lock); return buf_slot; } @@ -1764,7 +1764,7 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb) bufsize = smc_uncompress_bufsize(bufsize_short);
/* check for reusable slot in the link group */ - buf_desc = smc_buf_get_slot(bufsize_short, lock, buf_list); + buf_desc = smc_buf_get_slot(bufsize, lock, buf_list); if (buf_desc) { memset(buf_desc->cpu_addr, 0, bufsize); break; /* found reusable slot */