Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp613708imu; Thu, 3 Jan 2019 04:07:21 -0800 (PST) X-Google-Smtp-Source: ALg8bN4gU8zR+k6/x5lqtTv66kIjw29OHY3pDoOEq6jiwd6zeI8KmKKwtmXDptRRSd4CWpIPxBBX X-Received: by 2002:a63:4a0a:: with SMTP id x10mr16787413pga.237.1546517241078; Thu, 03 Jan 2019 04:07:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546517241; cv=none; d=google.com; s=arc-20160816; b=qyGDfD0XqK3iFARAzh6QhndJ2eNAGuJiybD64N6I4fpK9FSE48fIYoDo7X8P26uNJd lhoutXzJEqMzb1qU111N9wLlFpW5OSDhGN1egHHUocXszsMsgaKT0NmAM70TkORxSzhB 7eZXwaOXeI01ud0EhP1JLkA9G37b92RgNBbhE/p0LPOHRkMP5SQcwRPb9Po+axSQRV/f meDsMQSslPPyB9TLpTg1jlEaG55SxKISGHBOCp73qpAKgwZGkj/UsRGf1vUgeOJNqqFu 3WXqkZwQ70MMh3Wev2YWnknHXRJAAaCtVGAYfEofy9vi8TyN8+8PbSApHWICX+mhKSuo h+JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=pQqlWlJObUFmfp62/GvZebXdx8AXlXpB4xlCOortMec=; b=zeQZlWt8pRINGsNeTdnRbKgZJK+aJk+CfDCzjOUGko4EXc7VFIgGcerHxmeCF6X9LK obZmPTkahYifr2exXJhz9L/KI3UxZ633Ge9FUB/ptK6hisQsSUTINqMr94fK6ivk3A/9 lti6bq11W/Gmv81q5ReyEXbOJdpVBJUMgfUfJNYEi88OTHt6p148E97KCrLgIjA4PgYc gps7wckftjAJ2BgxsU/6bI53G26lNMlvFHjxYOD1mHbRoOAKQ0LKSEsELONs2nVF9SaS 4g3XUPa7sxV8XGbULckHYy1FPH7CMc3Eaky+LPDUnCE1JKMux4AAhq4jC3i5IpRDnCN+ cjfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h75si54166547pfj.257.2019.01.03.04.07.04; Thu, 03 Jan 2019 04:07:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729866AbfACJKA (ORCPT + 99 others); Thu, 3 Jan 2019 04:10:00 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50392 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727888AbfACJKA (ORCPT ); Thu, 3 Jan 2019 04:10:00 -0500 Received: by mail-wm1-f66.google.com with SMTP id n190so28685002wmd.0 for ; Thu, 03 Jan 2019 01:09:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=pQqlWlJObUFmfp62/GvZebXdx8AXlXpB4xlCOortMec=; b=GVEzofbE9ChdPfZoXn8rY2xppeVcRThRg1zZptMJO7Z+3Iwz1MlY1DtTjatYaIv1kq 1J4qxfwt+Pm4qXrRJafm+ryMMhUF7q5Y2oohtto2Y9iGVWs4okzpL1vDNrrrtH6SqTfG DhBotlrUq9TniOj9mdtpuR5xsWnnV6yTFLkImN+I2+I5oFVBqUNpB2nfcQRjbAJs4yMi k9KQ3/J+hhsWyuQSqoXVv/rGQCgIYfPrFFfRofEBuMnqVMV6rm2HP10/BiWrrSD+/RAE rj0pcrhPFhwfiaw81ayiRmsQC99NUf/w5pUuAyOU+vc/u+gC6vnM4O2g6BHp7Nvty/38 GDXw== X-Gm-Message-State: AJcUukd3E/GqvizvVsl69PJBayhpHK8yiouc1ZaJpehQIXuZ0qC+3LB7 b+b17CnepOYFoaKmbc4eCcaOacPY X-Received: by 2002:a1c:4807:: with SMTP id v7mr38535187wma.53.1546506597294; Thu, 03 Jan 2019 01:09:57 -0800 (PST) Received: from [192.168.1.104] (185-219-167-241-static.vivo.cz. [185.219.167.241]) by smtp.gmail.com with ESMTPSA id r12sm52577679wrq.3.2019.01.03.01.09.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Jan 2019 01:09:56 -0800 (PST) Subject: Re: [PATCH] tty/n_hdlc: fix sleep in !TASK_RUNNING state warning To: Tetsuo Handa , Paul Fulghum Cc: Arnd Bergmann , gregkh@linuxfoundation.org, Alan Cox , linux-kernel@vger.kernel.org References: <000000000000449587057e1e6f8b@google.com> <49b3b189-a51f-6a97-0e1f-bc3f2c305299@I-love.SAKURA.ne.jp> From: Jiri Slaby Openpgp: preference=signencrypt Autocrypt: addr=jslaby@suse.cz; prefer-encrypt=mutual; keydata= mQINBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ0D2KYK/uhfc6neJ i0WqPlbtIlIrpvWxckucNu6ZwXjFY0f3qIRg3Vqh5QxPkojGsq9tXVFVLEkSVz6FoqCHrUTx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W/RcI/WC8Y4Z/7FS ITZhASwaCOzy/vX2yC6iTx4AMFt+a6Z6uH/xGE8pG5NbGtd02r+m7SfuEDoG3Hs1iMGecPyV XxCVvSV6dwRQFc0UOZ1a6ywwCWfGOYqFnJvfSbUiCMV8bfRSWhnNQYLIuSv/nckyi8CzCYIg c21cfBvnwiSfWLZTTj1oWyj5a0PPgGOdgGoIvVjYXul3yXYeYOqbYjiC5t99JpEeIFupxIGV ciMk6t3pDrq7n7Vi/faqT+c4vnjazJi0UMfYnnAzYBa9+NkfW0w5W9Uy7kW/v7SffH/2yFiK 9HKkJqkN9xYEYaxtfl5pelF8idoxMZpTvCZY7jhnl2IemZCBMs6s338wS12Qro5WEAxV6cjD VSdmcD5l9plhKGLmgVNCTe8DPv81oDn9s0cIRLg9wNnDtj8aIiH8lBHwfUkpn32iv0uMV6Ae sLxhDWfOR4N+wu1gzXWgLel4drkCJcuYK5IL1qaZDcuGR8RPo3jbFO7Y Message-ID: Date: Thu, 3 Jan 2019 10:09:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.3 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02. 01. 19, 16:04, Tetsuo Handa wrote: > + if (wait_event_interruptible(tty->read_wait, > + (ret = -EIO, test_bit(TTY_OTHER_CLOSED, &tty->flags)) || > + (ret = 0, tty_hung_up_p(file)) || > + (rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list)) != NULL || > + (ret = -EAGAIN, tty_io_nonblock(tty, file)))) > + return -EINTR; Oh, that looks really ugly. Could you move all this to a function returning a bool and taking &ret and &rbuf as parameters? > + if (rbuf) { > + if (rbuf->count > nr) > + /* too large for caller's buffer */ > + ret = -EOVERFLOW; > + else if (copy_to_user(buf, rbuf->buf, rbuf->count)) > + ret = -EFAULT; > + else > + ret = rbuf->count; > + if (n_hdlc->rx_free_buf_list.count > DEFAULT_RX_BUF_COUNT) > + kfree(rbuf); > + else > + n_hdlc_buf_put(&n_hdlc->rx_free_buf_list, rbuf); > } > - > - remove_wait_queue(&tty->read_wait, &wait); > - __set_current_state(TASK_RUNNING); > - > return ret; > - > } /* end of n_hdlc_tty_read() */ > > /** > @@ -645,21 +612,13 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file, > static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file, > const unsigned char *data, size_t count) > { > - struct n_hdlc *n_hdlc = tty2n_hdlc (tty); > + struct n_hdlc *n_hdlc; > int error = 0; > - DECLARE_WAITQUEUE(wait, current); > - struct n_hdlc_buf *tbuf; > + struct n_hdlc_buf *tbuf = NULL; > > if (debuglevel >= DEBUG_LEVEL_INFO) > printk("%s(%d)n_hdlc_tty_write() called count=%zd\n", > __FILE__,__LINE__,count); > - > - /* Verify pointers */ > - if (!n_hdlc) > - return -EIO; > - > - if (n_hdlc->magic != HDLC_MAGIC) > - return -EIO; > > /* verify frame size */ > if (count > maxframe ) { > @@ -670,40 +629,14 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file, > maxframe ); > count = maxframe; > } > - > - add_wait_queue(&tty->write_wait, &wait); > > - for (;;) { > - set_current_state(TASK_INTERRUPTIBLE); > - > - tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list); > - if (tbuf) > - break; > - > - if (tty_io_nonblock(tty, file)) { > - error = -EAGAIN; > - break; > - } > - schedule(); > - > - n_hdlc = tty2n_hdlc (tty); > - if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC || > - tty != n_hdlc->tty) { > - printk("n_hdlc_tty_write: %p invalid after wait!\n", n_hdlc); > - error = -EIO; > - break; > - } > - > - if (signal_pending(current)) { > - error = -EINTR; > - break; > - } > - } > - > - __set_current_state(TASK_RUNNING); > - remove_wait_queue(&tty->write_wait, &wait); > - > - if (!error) { > + if (wait_event_interruptible(tty->write_wait, > + (error = -EIO, n_hdlc = tty2n_hdlc(tty), /* Verify pointers */ > + !n_hdlc || n_hdlc->magic != HDLC_MAGIC || tty != n_hdlc->tty) || > + (tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list)) != NULL || > + (error = -EAGAIN, tty_io_nonblock(tty, file)))) > + return -EINTR; This is even worse. So detto as above? > + if (tbuf) { > /* Retrieve the user's buffer */ > memcpy(tbuf->buf, data, count); > > @@ -711,8 +644,9 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file, > tbuf->count = error = count; > n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf); > n_hdlc_send_frames(n_hdlc,tty); > + } else if (error == -EIO) { > + printk("n_hdlc_tty_write: %p invalid!\n", n_hdlc); > } > - > return error; > > } /* end of n_hdlc_tty_write() */ > thanks, -- js suse labs