From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Deepak R Varma <drv@mailo.com>
Cc: "Maciej W. Rozycki" <macro@orcam.me.uk>,
Jiri Slaby <jirislaby@kernel.org>,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
Saurabh Singh Sengar <ssengar@microsoft.com>,
Praveen Kumar <kumarpraveen@linux.microsoft.com>
Subject: Re: [PATCH v2] tty: serial: zs: convert atomic_* to refcount_* APIs for irq_guard
Date: Thu, 19 Jan 2023 14:52:36 +0100 [thread overview]
Message-ID: <Y8lLJK3RH+oX8RgE@kroah.com> (raw)
In-Reply-To: <Y6cvHgOlkcG90j1J@qemulion>
On Sat, Dec 24, 2022 at 10:25:58PM +0530, Deepak R Varma wrote:
> The refcount_* APIs are designed to address known issues with the
> atomic_t APIs for reference counting. They provide following distinct
> advantages:
> - protect the reference counters from overflow/underflow
> - avoid use-after-free errors
> - provide improved memory ordering guarantee schemes
> - neater and safer.
> Hence, replace the atomic_* APIs by their equivalent refcount_t
> API functions.
>
> This patch proposal address the following warnings generated by
> the atomic_as_refcounter.cocci coccinelle script
> atomic_add_return(-1, ...)
>
> Signed-off-by: Deepak R Varma <drv@mailo.com>
> ---
>
> Changes in v2:
> 1. Separate the combined change into one variable per patch as
> suggested by gregkh@linuxfoundation.org
> 2. There was additional feedback on validating the change as it appeared to
> modify the existing logic. However, I found that the logic does not
> change with the proposed refcount_* APIs used in this change. Hence that
> feedback is not applied in this version.
>
> Please Note:
> The patch is compile tested using dec_station.defconfig for MIPS architecture.
>
> drivers/tty/serial/zs.c | 14 +++++---------
> drivers/tty/serial/zs.h | 2 +-
> 2 files changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/tty/serial/zs.c b/drivers/tty/serial/zs.c
> index 730c648e32ff..6be9933eff5c 100644
> --- a/drivers/tty/serial/zs.c
> +++ b/drivers/tty/serial/zs.c
> @@ -753,17 +753,15 @@ static int zs_startup(struct uart_port *uport)
> struct zs_port *zport = to_zport(uport);
> struct zs_scc *scc = zport->scc;
> unsigned long flags;
> - int irq_guard;
> int ret;
>
> - irq_guard = atomic_add_return(1, &scc->irq_guard);
> - if (irq_guard == 1) {
> + refcount_inc(&scc->irq_guard);
> + if (refcount_read(&scc->irq_guard) == 1) {
This conversion is wrong :(
prev parent reply other threads:[~2023-01-20 5:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-24 16:55 [PATCH v2] tty: serial: zs: convert atomic_* to refcount_* APIs for irq_guard Deepak R Varma
2023-01-19 13:52 ` Greg Kroah-Hartman [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=Y8lLJK3RH+oX8RgE@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=drv@mailo.com \
--cc=jirislaby@kernel.org \
--cc=kumarpraveen@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=macro@orcam.me.uk \
--cc=ssengar@microsoft.com \
/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