2023-02-07 12:49:07

by George Kennedy

[permalink] [raw]
Subject: [PATCH v2] vc_screen: break from vcs_read() while loop if vcs_vc() returns NULL

If vcs_vc() returns NULL in vcs_read(), break from while loop if partial
read, else if no reads have been done, go to unlock_out and return -ENXIO.
In addition, change the goto unlock_out after vcs_size() to a break
to conform to the break handling after vcs_vc().

Fixes: ac751efa6a0d ("console: rename acquire/release_console_sem() to console_lock/unlock()")
Reported-by: Linus Torvalds <[email protected]>
Suggested-by: Linus Torvalds <[email protected]>
Signed-off-by: George Kennedy <[email protected]>
---
drivers/tty/vt/vc_screen.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
index f566eb1839dc..c599b452969f 100644
--- a/drivers/tty/vt/vc_screen.c
+++ b/drivers/tty/vt/vc_screen.c
@@ -406,19 +406,17 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
ret = -ENXIO;
vc = vcs_vc(inode, &viewed);
if (!vc)
- goto unlock_out;
+ break;

/* Check whether we are above size each round,
* as copy_to_user at the end of this loop
* could sleep.
*/
- size = vcs_size(vc, attr, uni_mode);
- if (size < 0) {
- if (read)
- break;
- ret = size;
- goto unlock_out;
- }
+ ret = vcs_size(vc, attr, uni_mode);
+ if (ret < 0)
+ break;
+ size = ret;
+ ret = 0;
if (pos >= size)
break;
if (count > size - pos)
--
2.31.1



2023-02-08 05:48:19

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH v2] vc_screen: break from vcs_read() while loop if vcs_vc() returns NULL

On 07. 02. 23, 13:48, George Kennedy wrote:
> If vcs_vc() returns NULL in vcs_read(), break from while loop if partial
> read, else if no reads have been done, go to unlock_out and return -ENXIO.
> In addition, change the goto unlock_out after vcs_size() to a break
> to conform to the break handling after vcs_vc().
>
> Fixes: ac751efa6a0d ("console: rename acquire/release_console_sem() to console_lock/unlock()")
> Reported-by: Linus Torvalds <[email protected]>
> Suggested-by: Linus Torvalds <[email protected]>
> Signed-off-by: George Kennedy <[email protected]>
> ---
> drivers/tty/vt/vc_screen.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
> index f566eb1839dc..c599b452969f 100644
> --- a/drivers/tty/vt/vc_screen.c
> +++ b/drivers/tty/vt/vc_screen.c
> @@ -406,19 +406,17 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
> ret = -ENXIO;
> vc = vcs_vc(inode, &viewed);
> if (!vc)
> - goto unlock_out;
> + break;
>
> /* Check whether we are above size each round,
> * as copy_to_user at the end of this loop
> * could sleep.
> */
> - size = vcs_size(vc, attr, uni_mode);
> - if (size < 0) {
> - if (read)
> - break;
> - ret = size;
> - goto unlock_out;
> - }
> + ret = vcs_size(vc, attr, uni_mode);
> + if (ret < 0)
> + break;
> + size = ret;
> + ret = 0;

I think the previous "size = vcs_size()" and "ret = size" in the error
path looked better than this "size = ret" and "ret = 0" here. I mean why
not to preserve:

size = vcs_size(vc, attr, uni_mode);
if (size < 0) {
ret = size;
break;
}

?

thanks,
--
js
suse labs