From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
To: Anton Volkov <avolkov@ispras.ru>, isdn@linux-pingi.de
Cc: davem@davemloft.net, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org,
khoroshilov@ispras.ru
Subject: Re: [PATCH] hysdn: fix to a race condition in put_log_buffer
Date: Thu, 3 Aug 2017 15:03:13 +0300 [thread overview]
Message-ID: <a82052eb-2aec-ffa2-2cfd-c02db779d695@cogentembedded.com> (raw)
In-Reply-To: <1501760001-22193-1-git-send-email-avolkov@ispras.ru>
Hello!
On 08/03/2017 02:33 PM, Anton Volkov wrote:
> The synchronization type that was used earlier to guard the loop that
> deletes unused log buffers may lead to a situation that prevents any
> thread from going through the loop.
>
> The patch deletes previously used synchronization mechanism and moves
> the loop under the spin_lock so the similar cases won't be feasible in
> the future.
>
> Found by by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Anton Volkov <avolkov@ispras.ru>
> ---
> drivers/isdn/hysdn/hysdn_proclog.c | 27 ++++++++++++---------------
> 1 file changed, 12 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c
> index 7b5fd8f..b152c6c 100644
> --- a/drivers/isdn/hysdn/hysdn_proclog.c
> +++ b/drivers/isdn/hysdn/hysdn_proclog.c
[...]
> else
> pd->log_tail->next = ib; /* follows existing messages */
> pd->log_tail = ib; /* new tail */
> - i = pd->del_lock++; /* get lock state */
> - spin_unlock_irqrestore(&card->hysdn_lock, flags);
>
> /* delete old entrys */
> - if (!i)
> - while (pd->log_head->next) {
> - if ((pd->log_head->usage_cnt <= 0) &&
> - (pd->log_head->next->usage_cnt <= 0)) {
> - ib = pd->log_head;
> - pd->log_head = pd->log_head->next;
> - kfree(ib);
> - } else
> - break;
> - } /* pd->log_head->next */
> - pd->del_lock--; /* release lock level */
> + while (pd->log_head->next) {
> + if ((pd->log_head->usage_cnt <= 0) &&
> + (pd->log_head->next->usage_cnt <= 0)) {
> + ib = pd->log_head;
> + pd->log_head = pd->log_head->next;
> + kfree(ib);
> + } else
> + break;
> + } /* pd->log_head->next */
Need {} in the *else* branch as *if* had them.
[...]
MBR, Sergei
next prev parent reply other threads:[~2017-08-03 12:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-27 16:19 Possible race in hysdn.ko Anton Volkov
2017-07-28 4:46 ` isdn
2017-07-28 14:53 ` [PATCH] hysdn: fix to a race condition in put_log_buffer Anton Volkov
2017-08-01 0:22 ` David Miller
2017-08-03 11:33 ` Anton Volkov
2017-08-03 12:03 ` Sergei Shtylyov [this message]
2017-08-07 12:54 ` [PATCH v2] " Anton Volkov
2017-08-07 18:25 ` David Miller
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=a82052eb-2aec-ffa2-2cfd-c02db779d695@cogentembedded.com \
--to=sergei.shtylyov@cogentembedded.com \
--cc=avolkov@ispras.ru \
--cc=davem@davemloft.net \
--cc=isdn@linux-pingi.de \
--cc=khoroshilov@ispras.ru \
--cc=ldv-project@linuxtesting.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@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).