All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: Alex Chen <alex.chen@huawei.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Michael Tokarev <mjt@tls.msk.ru>
Cc: QEMU Trivial <qemu-trivial@nongnu.org>,
	yebiaoxiang@huawei.com, QEMU <qemu-devel@nongnu.org>
Subject: Re: [PATCH V2] util: Remove redundant checks in the openpty()
Date: Wed, 15 Sep 2021 14:44:44 +0200	[thread overview]
Message-ID: <0d0e66e0-1281-d739-da3c-6fb2d93f7a32@vivier.eu> (raw)
In-Reply-To: <614052A9.4060107@huawei.com>

Le 14/09/2021 à 09:43, Alex Chen a écrit :
> Hi all,
> 
> This patch has been reviewed by Peter. who can help merge it?
> 
> Thanks,
> Alex
> 
> On 2020/11/2 18:55, AlexChen wrote:
>> As we can see from the following function call stack, amaster and aslave
>> can not be NULL: char_pty_open() -> qemu_openpty_raw() -> openpty().
>> In addition, according to the API specification for openpty():
>> https://www.gnu.org/software/libc/manual/html_node/Pseudo_002dTerminal-Pairs.html,
>> the arguments name, termp and winp can all be NULL, but arguments amaster or aslave
>> can not be NULL.
>> Finally, amaster and aslave has been dereferenced at the beginning of the openpty().
>> So the checks on amaster and aslave in the openpty() are redundant. Remove them.
>>
>> Reported-by: Euler Robot <euler.robot@huawei.com>
>> Signed-off-by: Alex Chen <alex.chen@huawei.com>
>> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>> ---
>>  util/qemu-openpty.c | 7 +++----
>>  1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/util/qemu-openpty.c b/util/qemu-openpty.c
>> index eb17f5b0bc..427f43a769 100644
>> --- a/util/qemu-openpty.c
>> +++ b/util/qemu-openpty.c
>> @@ -80,10 +80,9 @@ static int openpty(int *amaster, int *aslave, char *name,
>>              (termp != NULL && tcgetattr(sfd, termp) < 0))
>>                  goto err;
>>
>> -        if (amaster)
>> -                *amaster = mfd;
>> -        if (aslave)
>> -                *aslave = sfd;
>> +        *amaster = mfd;
>> +        *aslave = sfd;
>> +
>>          if (winp)
>>                  ioctl(sfd, TIOCSWINSZ, winp);
>>
> 
> 

Applied to my trivial-patches branch.

Thanks,
Laurent


      reply	other threads:[~2021-09-15 12:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-02 10:55 [PATCH V2] util: Remove redundant checks in the openpty() AlexChen
2021-09-14  7:43 ` Alex Chen
2021-09-15 12:44   ` Laurent Vivier [this message]

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=0d0e66e0-1281-d739-da3c-6fb2d93f7a32@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=alex.chen@huawei.com \
    --cc=mjt@tls.msk.ru \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=yebiaoxiang@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.