From: "Måns Rullgård" <mans@mansr.com>
To: Christian Riesch <christian.riesch@omicron.at>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"linux-kernel\@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Peter Hurley <peter@hurleysoftware.com>,
stable <stable@vger.kernel.org>
Subject: Re: [PATCH v2] n_tty: Fix read_buf race condition, increment read_head after pushing data
Date: Wed, 12 Nov 2014 11:53:59 +0000 [thread overview]
Message-ID: <yw1x1tp8hbxk.fsf@unicorn.mansr.com> (raw)
In-Reply-To: <CABkLObqGP2488XYCATKE_U-uDjo=tWgEAaU2+YkwstDTnoeetA@mail.gmail.com> (Christian Riesch's message of "Wed, 12 Nov 2014 08:28:56 +0100")
Christian Riesch <christian.riesch@omicron.at> writes:
> On Tue, Nov 11, 2014 at 2:04 PM, Måns Rullgård <mans@mansr.com> wrote:
>> Christian Riesch <christian.riesch@omicron.at> writes:
> [...]>> diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
>>> index 2e900a9..b09f326 100644
>>> --- a/drivers/tty/n_tty.c
>>> +++ b/drivers/tty/n_tty.c
>>> @@ -321,7 +321,9 @@ static void n_tty_check_unthrottle(struct tty_struct *tty)
>>>
>>> static inline void put_tty_queue(unsigned char c, struct n_tty_data *ldata)
>>> {
>>> - *read_buf_addr(ldata, ldata->read_head++) = c;
>>> + *read_buf_addr(ldata, ldata->read_head) = c;
>>> + /* increment read_head _after_ placing the character in the buffer */
>>> + ldata->read_head++;
>>> }
>>
>> Is that comment really necessary?
>
> No, I am pretty sure that removing the comment would not break the code ;-)
>
> I just thought it would be good to have some kind of reminder here.
> Otherwise someone may think: Hey, it would be a good idea to do the
> increment right in the first line. And submit a patch for it.
The intent all along was to increment after the write. Nobody needs
reminding of that. The problem was a misunderstanding of when the
post-increment takes effect. As much as we'd like for everybody to have
a thorough knowledge of C, a random tty driver doesn't seem the place to
educate them.
--
Måns Rullgård
mans@mansr.com
next prev parent reply other threads:[~2014-11-12 11:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-11 7:24 [PATCH v2] n_tty: Fix read_buf race condition, increment read_head after pushing data Christian Riesch
2014-11-11 13:04 ` Måns Rullgård
2014-11-12 7:28 ` Christian Riesch
2014-11-12 11:53 ` Måns Rullgård [this message]
2014-11-12 20:03 ` Christian Riesch
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=yw1x1tp8hbxk.fsf@unicorn.mansr.com \
--to=mans@mansr.com \
--cc=christian.riesch@omicron.at \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peter@hurleysoftware.com \
--cc=stable@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).