mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: George Kennedy <george.kennedy@oracle.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: gregkh@linuxfoundation.org, jslaby@suse.cz, sfr@canb.auug.org.au,
	akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	linux-serial@vger.kernel.org
Subject: Re: [PATCH] vc_screen: break from vcs_read() while loop if vcs_vc() returns NULL
Date: Mon, 6 Feb 2023 13:20:28 -0500	[thread overview]
Message-ID: <a305b9e4-349d-8936-b0ba-3dcaa4199ebc@oracle.com> (raw)
In-Reply-To: <CAHk-=wi5h32VBgzYgFy8KoXbcDMa9K_ihDjfxD-iScy7L+M=QQ@mail.gmail.com>



On 2/6/2023 1:12 PM, Linus Torvalds wrote:
> On Mon, Feb 6, 2023 at 9:34 AM George Kennedy <george.kennedy@oracle.com> wrote:
>>
>> -               ret = -ENXIO;
>>                  vc = vcs_vc(inode, &viewed);
>> -               if (!vc)
>> +               if (!vc) {
>> +                       if (read)
>> +                               break;
>> +                       ret = -ENXIO;
>>                          goto unlock_out;
>> +               }
> That works, but the whole "if (read)" thing is already done after the
> loop, so instead of essentially duplicating that logic, I really think
> the patch should be just a plain
>
>                  vc = vcs_vc(inode, &viewed);
>                  if (!vc)
> -                       goto unlock_out;
> +                       break;
>
> and nothing else.
>
> And yes, the pre-existing vcs_size() error handling has that same ugly pattern.
>
> It might be worth cleaning up too, although right now that
>
>                  size = vcs_size(vc, attr, uni_mode);
>                  if (size < 0) {
>                          if (read)
>                                  break;
>
> pattern means that if we 'break' there, 'read' is non-zero, so 'ret'
> doesn't matter. Which is also ugly, but works.
>
> I *think* it could all be rewritten to just use 'break' everywhere in
> the loop, and make 'ret' handling be saner.
>
> Something like the attached patch, but while I tried to think about
> it, I didn't spend a lot of effort on it, and I certainly didn't test
> it. So I'm sending this out as a "Hmm. This _looks_ better to me, but
> whatever" patch.

Thank you Linus,

Will start with your suggested patch and will test it.

George
>
>                 Linus


  reply	other threads:[~2023-02-06 18:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06 17:34 George Kennedy
2023-02-06 18:12 ` Linus Torvalds
2023-02-06 18:20   ` George Kennedy [this message]
2023-02-06 18:31     ` Greg KH

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=a305b9e4-349d-8936-b0ba-3dcaa4199ebc@oracle.com \
    --to=george.kennedy@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=sfr@canb.auug.org.au \
    --cc=torvalds@linux-foundation.org \
    /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®