mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Matias Bjørling" <mb@lightnvm.io>
To: "Hans Holmberg" <hans.ml.holmberg@owltronix.com>,
	"Javier González" <javier@javigon.com>
Cc: Hans Holmberg <hans.holmberg@cnexlabs.com>,
	linux-block@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Javier Gonzalez <javier@cnexlabs.com>
Subject: Re: [PATCH] lightnvm: pblk: avoid ref warning on cache creation
Date: Fri, 30 Nov 2018 09:36:22 +0100	[thread overview]
Message-ID: <a0bacf2c-1405-b70b-828a-f2bbe0ecb271@lightnvm.io> (raw)
In-Reply-To: <CANr-nt2XMzZnd309pY7QJxYXWMSuXXrcWMt8F=pa49BzARb5dg@mail.gmail.com>

On 11/23/2018 11:04 AM, Hans Holmberg wrote:
> Great catch Javier! Nice refactoring work too.
> 
> Reviewed-by: Hans Holmberg <hans.holmberg@cnexlabs.com>
> On Thu, Nov 22, 2018 at 2:47 PM Javier González <javier@javigon.com> wrote:
>>
>> The current kref implementation around pblk global caches triggers a
>> false positive on refcount_inc_checked() (when called) as the kref is
>> initialized to 0. Instead of usint kref_inc() on a 0 reference, which is
>> in principle correct, use kref_init() to avoid the check. This is also
>> more explicit about what actually happens on cache creation.
>>
>> In the process, do a small refactoring to use kref helpers.
>>
>> Signed-off-by: Javier González <javier@cnexlabs.com>
>> ---
>>   drivers/lightnvm/pblk-init.c | 14 +++++---------
>>   1 file changed, 5 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
>> index 13822594647c..e225bd60cbb4 100644
>> --- a/drivers/lightnvm/pblk-init.c
>> +++ b/drivers/lightnvm/pblk-init.c
>> @@ -350,23 +350,19 @@ static int pblk_create_global_caches(void)
>>
>>   static int pblk_get_global_caches(void)
>>   {
>> -       int ret;
>> +       int ret = 0;
>>
>>          mutex_lock(&pblk_caches.mutex);
>>
>> -       if (kref_read(&pblk_caches.kref) > 0) {
>> -               kref_get(&pblk_caches.kref);
>> -               mutex_unlock(&pblk_caches.mutex);
>> -               return 0;
>> -       }
>> +       if (kref_get_unless_zero(&pblk_caches.kref))
>> +               goto out;
>>
>>          ret = pblk_create_global_caches();
>> -
>>          if (!ret)
>> -               kref_get(&pblk_caches.kref);
>> +               kref_init(&pblk_caches.kref);
>>
>> +out:
>>          mutex_unlock(&pblk_caches.mutex);
>> -
>>          return ret;
>>   }
>>
>> --
>> 2.7.4
>>

Picked up for 4.21.

  reply	other threads:[~2018-11-30  8:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-22 13:46 Javier González
2018-11-22 13:46 ` [PATCH] " Javier González
2018-11-23 10:04   ` Hans Holmberg
2018-11-30  8:36     ` Matias Bjørling [this message]
2018-11-23  8:14 ` Matias Bjørling
2018-11-23  8:16   ` Javier Gonzalez
2018-11-23  8:23     ` Matias Bjørling
2018-11-23  8:31       ` Javier Gonzalez
2018-11-23  8:41         ` Matias Bjørling

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=a0bacf2c-1405-b70b-828a-f2bbe0ecb271@lightnvm.io \
    --to=mb@lightnvm.io \
    --cc=hans.holmberg@cnexlabs.com \
    --cc=hans.ml.holmberg@owltronix.com \
    --cc=javier@cnexlabs.com \
    --cc=javier@javigon.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®