From: Deepak R Varma <drv@mailo.com>
To: "Maciej W. Rozycki" <macro@orcam.me.uk>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Saurabh Singh Sengar <ssengar@microsoft.com>,
Praveen Kumar <kumarpraveen@linux.microsoft.com>,
Deepak R Varma <drv@mailo.com>
Subject: [PATCH 2/2] tty: serial: dz: convert atomic_* to refcount_* APIs for irq_guard
Date: Sat, 24 Dec 2022 22:04:28 +0530 [thread overview]
Message-ID: <51ef854f77779c82010379420139993e12c38776.1671898144.git.drv@mailo.com> (raw)
In-Reply-To: <cover.1671898144.git.drv@mailo.com>
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>
---
Please Note:
1. The patch is compile tested using dec_station.defconfig for MIPS architecture.
2. This patch should be applied after patch 1/2 of this series due to
dependency.
Changes in v3:
1. Include the individual patches in a series and highlight dependency.
Feedback provided by gregkh@linuxfoundation.org
Changes in v2:
1. Separate the combined change into one variable per patch as
suggested by gregkh@linuxfoundation.org
drivers/tty/serial/dz.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/drivers/tty/serial/dz.c b/drivers/tty/serial/dz.c
index b70edc248f8b..0aa59a9beeb7 100644
--- a/drivers/tty/serial/dz.c
+++ b/drivers/tty/serial/dz.c
@@ -46,7 +46,6 @@
#include <linux/tty.h>
#include <linux/tty_flip.h>
-#include <linux/atomic.h>
#include <linux/refcount.h>
#include <linux/io.h>
#include <asm/bootinfo.h>
@@ -77,7 +76,7 @@ struct dz_port {
struct dz_mux {
struct dz_port dport[DZ_NB_PORT];
refcount_t map_guard;
- atomic_t irq_guard;
+ refcount_t irq_guard;
int initialised;
};
@@ -400,18 +399,16 @@ static int dz_startup(struct uart_port *uport)
struct dz_port *dport = to_dport(uport);
struct dz_mux *mux = dport->mux;
unsigned long flags;
- int irq_guard;
int ret;
u16 tmp;
- irq_guard = atomic_add_return(1, &mux->irq_guard);
- if (irq_guard != 1)
+ refcount_inc(&mux->irq_guard);
+ if (refcount_read(&mux->irq_guard) != 1)
return 0;
- ret = request_irq(dport->port.irq, dz_interrupt,
- IRQF_SHARED, "dz", mux);
+ ret = request_irq(dport->port.irq, dz_interrupt, IRQF_SHARED, "dz", mux);
if (ret) {
- atomic_add(-1, &mux->irq_guard);
+ refcount_dec(&mux->irq_guard);
printk(KERN_ERR "dz: Cannot get IRQ %d!\n", dport->port.irq);
return ret;
}
@@ -441,15 +438,13 @@ static void dz_shutdown(struct uart_port *uport)
struct dz_port *dport = to_dport(uport);
struct dz_mux *mux = dport->mux;
unsigned long flags;
- int irq_guard;
u16 tmp;
spin_lock_irqsave(&dport->port.lock, flags);
dz_stop_tx(&dport->port);
spin_unlock_irqrestore(&dport->port.lock, flags);
- irq_guard = atomic_add_return(-1, &mux->irq_guard);
- if (!irq_guard) {
+ if (refcount_dec_and_test(&mux->irq_guard)) {
/* Disable interrupts. */
tmp = dz_in(dport, DZ_CSR);
tmp &= ~(DZ_RIE | DZ_TIE);
--
2.34.1
WARNING: multiple messages have this Message-ID
From: Deepak R Varma <drv@mailo.com>
To: "Maciej W. Rozycki" <macro@orcam.me.uk>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Saurabh Singh Sengar <ssengar@microsoft.com>,
Praveen Kumar <kumarpraveen@linux.microsoft.com>,
Deepak R Varma <drv@mailo.com>
Subject: [PATCH v4 2/2] tty: serial: dz: convert atomic_* to refcount_* APIs for irq_guard
Date: Mon, 26 Dec 2022 11:51:57 +0530 [thread overview]
Message-ID: <51ef854f77779c82010379420139993e12c38776.1671898144.git.drv@mailo.com> (raw)
Message-ID: <20221226062157.SfgrSmDUCW9hr0tjHpQlxSk6qs6yfDJme_9Z8aDprFo@z> (raw)
In-Reply-To: <cover.1671898144.git.drv@mailo.com>
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>
---
Please Note:
1. The patch is compile tested using dec_station.defconfig for MIPS architecture.
2. This patch should be applied after patch 1/2 of this series due to
dependency.
Changes in v4:
1. Add the patch version label.
Changes in v3:
1. Include the individual patches in a series and highlight dependency.
Feedback provided by gregkh@linuxfoundation.org
Changes in v2:
1. Separate the combined change into one variable per patch as
suggested by gregkh@linuxfoundation.org
drivers/tty/serial/dz.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/drivers/tty/serial/dz.c b/drivers/tty/serial/dz.c
index b70edc248f8b..0aa59a9beeb7 100644
--- a/drivers/tty/serial/dz.c
+++ b/drivers/tty/serial/dz.c
@@ -46,7 +46,6 @@
#include <linux/tty.h>
#include <linux/tty_flip.h>
-#include <linux/atomic.h>
#include <linux/refcount.h>
#include <linux/io.h>
#include <asm/bootinfo.h>
@@ -77,7 +76,7 @@ struct dz_port {
struct dz_mux {
struct dz_port dport[DZ_NB_PORT];
refcount_t map_guard;
- atomic_t irq_guard;
+ refcount_t irq_guard;
int initialised;
};
@@ -400,18 +399,16 @@ static int dz_startup(struct uart_port *uport)
struct dz_port *dport = to_dport(uport);
struct dz_mux *mux = dport->mux;
unsigned long flags;
- int irq_guard;
int ret;
u16 tmp;
- irq_guard = atomic_add_return(1, &mux->irq_guard);
- if (irq_guard != 1)
+ refcount_inc(&mux->irq_guard);
+ if (refcount_read(&mux->irq_guard) != 1)
return 0;
- ret = request_irq(dport->port.irq, dz_interrupt,
- IRQF_SHARED, "dz", mux);
+ ret = request_irq(dport->port.irq, dz_interrupt, IRQF_SHARED, "dz", mux);
if (ret) {
- atomic_add(-1, &mux->irq_guard);
+ refcount_dec(&mux->irq_guard);
printk(KERN_ERR "dz: Cannot get IRQ %d!\n", dport->port.irq);
return ret;
}
@@ -441,15 +438,13 @@ static void dz_shutdown(struct uart_port *uport)
struct dz_port *dport = to_dport(uport);
struct dz_mux *mux = dport->mux;
unsigned long flags;
- int irq_guard;
u16 tmp;
spin_lock_irqsave(&dport->port.lock, flags);
dz_stop_tx(&dport->port);
spin_unlock_irqrestore(&dport->port.lock, flags);
- irq_guard = atomic_add_return(-1, &mux->irq_guard);
- if (!irq_guard) {
+ if (refcount_dec_and_test(&mux->irq_guard)) {
/* Disable interrupts. */
tmp = dz_in(dport, DZ_CSR);
tmp &= ~(DZ_RIE | DZ_TIE);
--
2.34.1
next prev parent reply other threads:[~2022-12-24 16:34 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-24 16:32 [PATCH v3 0/2] tty: serial: dz: convert atomic_* to refcount_* Deepak R Varma
2022-12-24 16:33 ` [PATCH v3 1/2] tty: serial: dz: convert atomic_* to refcount_* APIs for map_guard Deepak R Varma
2022-12-26 6:21 ` [PATCH v4 " Deepak R Varma
2023-01-03 8:59 ` Jiri Slaby
2023-01-03 10:05 ` Deepak R Varma
2023-01-04 8:28 ` Greg Kroah-Hartman
2023-01-04 8:59 ` Deepak R Varma
2023-01-10 6:19 ` Deepak R Varma
2023-01-10 7:27 ` Reshetova, Elena
2023-01-10 7:47 ` Deepak R Varma
2023-01-10 7:57 ` Greg Kroah-Hartman
2022-12-24 16:34 ` Deepak R Varma [this message]
2022-12-26 6:21 ` [PATCH v4 2/2] tty: serial: dz: convert atomic_* to refcount_* APIs for irq_guard Deepak R Varma
2023-01-03 9:00 ` Jiri Slaby
2023-01-03 10:09 ` Deepak R Varma
2023-01-04 8:28 ` Greg Kroah-Hartman
2023-01-04 9:00 ` Deepak R Varma
2022-12-26 6:20 ` [PATCH v4 0/2] tty: serial: dz: convert atomic_* to refcount_* Deepak R Varma
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=51ef854f77779c82010379420139993e12c38776.1671898144.git.drv@mailo.com \
--to=drv@mailo.com \
--cc=gregkh@linuxfoundation.org \
--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
all inboxes | Powered by JetHome®