Skip to contentSkip to conversation

drivers: tty: vt: vt.c: fixed segmentation fault in vt.c

PATCH In review [email protected] 2 participants 2 messages Nov 2, 2023 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 drivers: tty: vt: vt.c: fixed segmentation fault in vt.c

From: Dima <[email protected]>

The previous code lacked proper synchronization, leading to potential data corruption and crashes. Added a spin lock to protect shared variable 'scrollback_delta' to prevent concurrent access.

---
 drivers/tty/vt/vt.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/tty/vt/vt.c +4 -3
index 5c47f77804f0..29cf7fe11662 100644
@@ -301,12 +301,13 @@ static inline unsigned short *screenpos(const struct vc_data *vc, int offset,
 }
 
 /* Called  from the keyboard irq path.. */
+static DEFINE_SPINLOCK(scrolldelta_lock);
+
 static inline void scrolldelta(int lines)
 {
-	/* FIXME */
-	/* scrolldelta needs some kind of consistency lock, but the BKL was
-	   and still is not protecting versus the scheduled back end */
+	spin_lock(&scrolldelta_lock);
 	scrollback_delta += lines;
+	spin_unlock(&scrolldelta_lock);
 	schedule_console_callback();
 }
 
Signature · 1 line
2.42.0
#1 lore raw

Where is patch 1/2?

Quoted 1 line · On Thu, Nov 02, 2023 at 12:39:26PM +0100, [email protected] wrote:

From: Dima <[email protected]>

Is that your full name?

Quoted 2 lines

The previous code lacked proper synchronization, leading to potential data corruption and crashes. Added a spin lock to protect shared variable 'scrollback_delta' to prevent concurrent access.

Please wrap your lines properly, as your editor hinted that you should.

And always run scripts/checkpatch.pl on your patch before submitting it.

Quoted 14 lines
---
 drivers/tty/vt/vt.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/tty/vt/vt.c +0 -0
index 5c47f77804f0..29cf7fe11662 100644
@@ -301,12 +301,13 @@ static inline unsigned short *screenpos(const struct vc_data *vc, int offset,
 }
 
 /* Called  from the keyboard irq path.. */

drivers/tty/vt/vt.c static inline unsigned short *screenpos(const struct vc_data *vc, int offset, · line 310

Quoted 10 lines
drivers/tty/vt/vt.c +4 -3
+static DEFINE_SPINLOCK(scrolldelta_lock);
+
 static inline void scrolldelta(int lines)
 {
-	/* FIXME */
-	/* scrolldelta needs some kind of consistency lock, but the BKL was
-	   and still is not protecting versus the scheduled back end */
+	spin_lock(&scrolldelta_lock);
 	scrollback_delta += lines;
+	spin_unlock(&scrolldelta_lock);

How exactly did you test this? This patch does not do anything that I can determine.

And what "crashes" have you fixed here? What "data corruption"? Your changelog text does not match this actual change at all from what I can tell.

thanks,

greg k-h