mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: Jens Axboe <axboe@kernel.dk>,
	idryomov@gmail.com, dongsheng.yang@easystack.cn
Cc: ceph-devel@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Kees Cook <keescook@chromium.org>,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: drivers/block/rbd.c: atomic_inc_return_safe() & atomic_dec_return_safe()
Date: Fri, 2 Oct 2020 17:50:09 -0600	[thread overview]
Message-ID: <a3f6c88f-5b0f-0da0-c5ad-dd40ea36f4a5@linuxfoundation.org> (raw)
In-Reply-To: <c2dd3223-bda1-be8c-fbc4-9c0eec63bc9d@kernel.dk>

On 10/2/20 5:44 PM, Jens Axboe wrote:
> On 10/2/20 4:34 PM, Shuah Khan wrote:
>> All,
>>
>> I came across these atomic_inc_return_safe() & atomic_dec_return_safe()
>> functions that hold the counters at safe values.
>>
>> atomic_inc_return_safe()
>>
>> If the counter is already 0 it will not be incremented.
>> If the counter is already at its maximum value returns
>> -EINVAL without updating it.
>>
>> atomic_dec_return_safe()
>>
>> Decrement the counter.  Return the resulting value, or -EINVAL
>>
>> These two routines are static and only used in rbd.c.
>>
>> Can these become part of atomic_t ops?
> 
> I think you just want to use refcount_t for this use case. They
> have safe guards for under/overflow.
> 

Makes sense. Guess these came before refcount_t.

I will track this for refcount_t conversion.

thanks,
-- Shuah

      reply	other threads:[~2020-10-02 23:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-02 22:34 Shuah Khan
2020-10-02 23:44 ` Jens Axboe
2020-10-02 23:50   ` Shuah Khan [this message]

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=a3f6c88f-5b0f-0da0-c5ad-dd40ea36f4a5@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=axboe@kernel.dk \
    --cc=ceph-devel@vger.kernel.org \
    --cc=dongsheng.yang@easystack.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=idryomov@gmail.com \
    --cc=keescook@chromium.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®