From: Leon Romanovsky <leon@kernel.org>
To: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Cc: Raju Rangoju <rajur@chelsio.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
yuanxzhang@fudan.edu.cn, Xin Tan <tanxin.ctf@gmail.com>
Subject: Re: [PATCH] cxgb4: Convert from atomic_t to refcount_t on l2t_entry->refcnt
Date: Sun, 18 Jul 2021 13:44:30 +0300 [thread overview]
Message-ID: <YPQGDqQZS2WinPQH@unreal> (raw)
In-Reply-To: <1626517014-42631-1-git-send-email-xiyuyang19@fudan.edu.cn>
On Sat, Jul 17, 2021 at 06:16:54PM +0800, Xiyu Yang wrote:
> refcount_t type and corresponding API can protect refcounters from
> accidental underflow and overflow and further use-after-free situations.
>
> Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
> ---
> drivers/net/ethernet/chelsio/cxgb4/l2t.c | 31 ++++++++++++++++---------------
> drivers/net/ethernet/chelsio/cxgb4/l2t.h | 3 ++-
> 2 files changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/l2t.c b/drivers/net/ethernet/chelsio/cxgb4/l2t.c
> index a10a6862a9a4..cb26a5e315b1 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/l2t.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/l2t.c
> @@ -69,7 +69,8 @@ static inline unsigned int vlan_prio(const struct l2t_entry *e)
>
> static inline void l2t_hold(struct l2t_data *d, struct l2t_entry *e)
> {
> - if (atomic_add_return(1, &e->refcnt) == 1) /* 0 -> 1 transition */
> + refcount_inc(&e->refcnt);
> + if (refcount_read(&e->refcnt) == 1) /* 0 -> 1 transition */
> atomic_dec(&d->nfree);
> }
>
> @@ -270,10 +271,10 @@ static struct l2t_entry *alloc_l2e(struct l2t_data *d)
>
> /* there's definitely a free entry */
> for (e = d->rover, end = &d->l2tab[d->l2t_size]; e != end; ++e)
> - if (atomic_read(&e->refcnt) == 0)
> + if (refcount_read(&e->refcnt) == 0)
This is wrong.
Thanks
prev parent reply other threads:[~2021-07-18 10:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-17 10:16 [PATCH] cxgb4: Convert from atomic_t to refcount_t on l2t_entry->refcnt Xiyu Yang
2021-07-18 10:44 ` Leon Romanovsky [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=YPQGDqQZS2WinPQH@unreal \
--to=leon@kernel.org \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rajur@chelsio.com \
--cc=tanxin.ctf@gmail.com \
--cc=xiyuyang19@fudan.edu.cn \
--cc=yuanxzhang@fudan.edu.cn \
/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).