Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

use clamp() for counts in csi_?() handlers

The count to process is supposed to be between 1 and vc->vc_cols -
vc->state.x (or rows and .y). clamp() can be used exactly for this,
instead of ifs and min().

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Tested-by: Helge Deller <deller@gmx.de> # parisc STI console
Link: https://lore.kernel.org/r/20240122110401.7289-14-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
eb881eba fe4f6beb

+5 -22
+5 -22
drivers/tty/vt/vt.c
··· 1574 1574 /* erase the following vpar positions */ 1575 1575 static void csi_X(struct vc_data *vc, unsigned int vpar) 1576 1576 { /* not vt100? */ 1577 - unsigned int count; 1578 - 1579 - if (!vpar) 1580 - vpar++; 1581 - 1582 - count = min(vpar, vc->vc_cols - vc->state.x); 1577 + unsigned int count = clamp(vpar, 1, vc->vc_cols - vc->state.x); 1583 1578 1584 1579 vc_uniscr_clear_line(vc, vc->state.x, count); 1585 1580 scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count); ··· 2005 2010 /* console_lock is held */ 2006 2011 static void csi_at(struct vc_data *vc, unsigned int nr) 2007 2012 { 2008 - if (nr > vc->vc_cols - vc->state.x) 2009 - nr = vc->vc_cols - vc->state.x; 2010 - else if (!nr) 2011 - nr = 1; 2013 + nr = clamp(nr, 1, vc->vc_cols - vc->state.x); 2012 2014 insert_char(vc, nr); 2013 2015 } 2014 2016 2015 2017 /* console_lock is held */ 2016 2018 static void csi_L(struct vc_data *vc, unsigned int nr) 2017 2019 { 2018 - if (nr > vc->vc_rows - vc->state.y) 2019 - nr = vc->vc_rows - vc->state.y; 2020 - else if (!nr) 2021 - nr = 1; 2020 + nr = clamp(nr, 1, vc->vc_rows - vc->state.y); 2022 2021 con_scroll(vc, vc->state.y, vc->vc_bottom, SM_DOWN, nr); 2023 2022 vc->vc_need_wrap = 0; 2024 2023 } ··· 2020 2031 /* console_lock is held */ 2021 2032 static void csi_P(struct vc_data *vc, unsigned int nr) 2022 2033 { 2023 - if (nr > vc->vc_cols - vc->state.x) 2024 - nr = vc->vc_cols - vc->state.x; 2025 - else if (!nr) 2026 - nr = 1; 2034 + nr = clamp(nr, 1, vc->vc_cols - vc->state.x); 2027 2035 delete_char(vc, nr); 2028 2036 } 2029 2037 2030 2038 /* console_lock is held */ 2031 2039 static void csi_M(struct vc_data *vc, unsigned int nr) 2032 2040 { 2033 - if (nr > vc->vc_rows - vc->state.y) 2034 - nr = vc->vc_rows - vc->state.y; 2035 - else if (!nr) 2036 - nr=1; 2041 + nr = clamp(nr, 1, vc->vc_rows - vc->state.y); 2037 2042 con_scroll(vc, vc->state.y, vc->vc_bottom, SM_UP, nr); 2038 2043 vc->vc_need_wrap = 0; 2039 2044 }