linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Willy Tarreau <w@1wt.eu>
Subject: [PATCH v3] auxdisplay: Remove in_interrupt() usage.
Date: Sat, 13 Feb 2021 17:50:40 +0100	[thread overview]
Message-ID: <20210213165040.vzzieegx4aliyosd@linutronix.de> (raw)
In-Reply-To: <CANiq72mG3zXA7j9KbC74hQ1BMgw713Hm3WDAcQBjKxgg0fLHeg@mail.gmail.com>

charlcd_write() is invoked as a VFS->write() callback and as such it is
always invoked from preemptible context and may sleep.

charlcd_puts() is invoked from register/unregister callback which is
preemtible. The reboot notifier callback is also invoked from
preemptible context.

Therefore there is no need to use `in_interrupt()' to figure out if it
is save to sleep because it always is. `in_interrupt()` and related
context checks are being removed from non-core code.
Using `schedule()' to schedule (an be friendly to others) is
discouraged and `cond_resched()' should be used instead.

Remove `in_interrupt()' and use `cond_resched()' to schedule every 32
iteration if needed.

Link: https://lkml.kernel.org/r/20200914204209.256266093@linutronix.de
Cc: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
v2…v3: Extend the commit message as suggested by Miguel Ojeda.
v1…v2: Spelling fixes.

On 2021-02-10 22:46:23 [+0100], Miguel Ojeda wrote:
> Hi Sebastian,
Hi Miguel,

> Yeah, it is a bit confusing when reading without the context (it is
> hard to keep up with everything going on unless you work full-time on
> it :-)

Sorry for leaving it out. I though it is not needed since it was not
needed.

> > since this patch was small, simple and removing not required code I kept
> > it out. Is this enough information for you?
> 
> If you don't mind, please add a quick sentence like (I can do it on my
> side too):
> 
>     `in_interrupt()` and related context checks are being removed
>     from non-core code.
> 
> Plus the tag:
> 
>     Link: https://lore.kernel.org/r/20200914204209.256266093@linutronix.de/

Added as suggested.

 drivers/auxdisplay/charlcd.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/auxdisplay/charlcd.c b/drivers/auxdisplay/charlcd.c
index f43430e9dceed..fbfce95919f72 100644
--- a/drivers/auxdisplay/charlcd.c
+++ b/drivers/auxdisplay/charlcd.c
@@ -470,12 +470,8 @@ static ssize_t charlcd_write(struct file *file, const char __user *buf,
 	char c;
 
 	for (; count-- > 0; (*ppos)++, tmp++) {
-		if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
-			/*
-			 * let's be a little nice with other processes
-			 * that need some CPU
-			 */
-			schedule();
+		if (((count + 1) & 0x1f) == 0)
+			cond_resched();
 
 		if (get_user(c, tmp))
 			return -EFAULT;
@@ -537,12 +533,8 @@ static void charlcd_puts(struct charlcd *lcd, const char *s)
 	int count = strlen(s);
 
 	for (; count-- > 0; tmp++) {
-		if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
-			/*
-			 * let's be a little nice with other processes
-			 * that need some CPU
-			 */
-			schedule();
+		if (((count + 1) & 0x1f) == 0)
+			cond_resched();
 
 		charlcd_write_char(lcd, *tmp);
 	}
-- 
2.30.0

  reply	other threads:[~2021-02-13 16:51 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-08 17:58 [PATCH] auxdisplay: Remove in_interrupt() usage Sebastian Andrzej Siewior
2021-02-08 18:38 ` Miguel Ojeda
2021-02-08 19:07   ` Sebastian Andrzej Siewior
2021-02-08 20:14     ` Miguel Ojeda
2021-02-08 20:41       ` Sebastian Andrzej Siewior
2021-02-08 22:26         ` Miguel Ojeda
2021-02-09  9:01           ` Sebastian Andrzej Siewior
2021-02-10 21:46             ` Miguel Ojeda
2021-02-13 16:50               ` Sebastian Andrzej Siewior [this message]
2021-02-16  9:32                 ` [PATCH v3] " Miguel Ojeda
2021-02-16 10:28                   ` Sebastian Andrzej Siewior
2021-02-16 12:42                     ` Miguel Ojeda
2021-02-16 18:26                       ` Sebastian Andrzej Siewior
2021-02-16 18:27                         ` [PATCH v4] " Sebastian Andrzej Siewior
2021-02-16 20:21                         ` [PATCH v3] " Miguel Ojeda
2021-03-10 17:51                           ` Sebastian Andrzej Siewior
2021-03-10 18:04                             ` Miguel Ojeda
2021-02-08 19:37   ` [PATCH v2] " Sebastian Andrzej Siewior

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=20210213165040.vzzieegx4aliyosd@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=w@1wt.eu \
    /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).