From: Leon Romanovsky <leon-2ukJVAZIZ/Y@public.gmane.org>
To: Nelson Escobar <neescoba-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] IB/usnic: Handle 0 counts in resource allocation
Date: Thu, 10 Dec 2015 08:47:02 +0200 [thread overview]
Message-ID: <20151210064702.GC8662@leon.nu> (raw)
In-Reply-To: <1449686539-29959-6-git-send-email-neescoba-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
On Wed, Dec 09, 2015 at 10:42:19AM -0800, Nelson Escobar wrote:
> - if (usnic_vnic_res_free_cnt(vnic, type) < cnt || cnt < 1 || !owner)
> + if (usnic_vnic_res_free_cnt(vnic, type) < cnt || cnt < 0 || !owner)
Before this change you returned EINVAL if no free_cnt were available,
now you will continue. is this behaviour expected?
> return ERR_PTR(-EINVAL);
>
> ret = kzalloc(sizeof(*ret), GFP_ATOMIC);
> @@ -247,26 +247,28 @@ usnic_vnic_get_resources(struct usnic_vnic *vnic, enum usnic_vnic_res_type type,
> return ERR_PTR(-ENOMEM);
> }
>
> - ret->res = kzalloc(sizeof(*(ret->res))*cnt, GFP_ATOMIC);
> - if (!ret->res) {
> - usnic_err("Failed to allocate resources for %s. Out of memory\n",
> - usnic_vnic_pci_name(vnic));
> - kfree(ret);
> - return ERR_PTR(-ENOMEM);
> - }
> + if (cnt > 0) {
> + ret->res = kcalloc(cnt, sizeof(*(ret->res)), GFP_ATOMIC);
> + if (!ret->res) {
> + usnic_err("Failed to allocate resources for %s. Out of memory\n",
> + usnic_vnic_pci_name(vnic));
You don't need to print OOM messages, failure in memory allocation very hard to miss.
> + kfree(ret);
> + return ERR_PTR(-ENOMEM);
> + }
>
> - spin_lock(&vnic->res_lock);
> - src = &vnic->chunks[type];
> - for (i = 0; i < src->cnt && ret->cnt < cnt; i++) {
> - res = src->res[i];
> - if (!res->owner) {
> - src->free_cnt--;
> - res->owner = owner;
> - ret->res[ret->cnt++] = res;
> + spin_lock(&vnic->res_lock);
> + src = &vnic->chunks[type];
> + for (i = 0; i < src->cnt && ret->cnt < cnt; i++) {
> + res = src->res[i];
> + if (!res->owner) {
> + src->free_cnt--;
It will be negative, because of skip usnic_vnic_res_free_cnt check
before.
> + res->owner = owner;
> + ret->res[ret->cnt++] = res;
> + }
> }
> - }
>
> - spin_unlock(&vnic->res_lock);
> + spin_unlock(&vnic->res_lock);
> + }
> ret->type = type;
> ret->vnic = vnic;
> WARN_ON(ret->cnt != cnt);
> @@ -281,14 +283,16 @@ void usnic_vnic_put_resources(struct usnic_vnic_res_chunk *chunk)
> int i;
> struct usnic_vnic *vnic = chunk->vnic;
>
> - spin_lock(&vnic->res_lock);
> - while ((i = --chunk->cnt) >= 0) {
> - res = chunk->res[i];
> - chunk->res[i] = NULL;
> - res->owner = NULL;
> - vnic->chunks[res->type].free_cnt++;
> + if (chunk->cnt > 0) {
> + spin_lock(&vnic->res_lock);
> + while ((i = --chunk->cnt) >= 0) {
> + res = chunk->res[i];
> + chunk->res[i] = NULL;
> + res->owner = NULL;
> + vnic->chunks[res->type].free_cnt++;
> + }
> + spin_unlock(&vnic->res_lock);
> }
> - spin_unlock(&vnic->res_lock);
>
> kfree(chunk->res);
> kfree(chunk);
> --
> 2.4.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2015-12-10 6:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-09 18:42 [PATCH] IB/usnic: Handle 0 counts in resource allocation Nelson Escobar
[not found] ` <1449686539-29959-6-git-send-email-neescoba-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
2015-12-10 6:47 ` Leon Romanovsky [this message]
[not found] ` <20151210064702.GC8662-2ukJVAZIZ/Y@public.gmane.org>
2015-12-10 19:22 ` Nelson Escobar
[not found] ` <5669D0F0.7010104-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
2015-12-10 19:47 ` leon-2ukJVAZIZ/Y
[not found] ` <20151210194734.GF8662-2ukJVAZIZ/Y@public.gmane.org>
2015-12-10 21:46 ` Nelson Escobar
[not found] ` <5669F2A7.8060502-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
2015-12-12 7:29 ` Leon Romanovsky
2015-12-23 19:48 ` Doug Ledford
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=20151210064702.GC8662@leon.nu \
--to=leon-2ukjvaziz/y@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=neescoba-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org \
/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).