Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp953172yba; Thu, 16 May 2019 11:34:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1H7etzqtgzMjjkaQx0CEWzjXEj7cL55i+ObkWcHfAZZo/0dU/Nu4MaAoswHKVusRJ8lXZ X-Received: by 2002:a17:902:12d:: with SMTP id 42mr45920243plb.4.1558031658566; Thu, 16 May 2019 11:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558031658; cv=none; d=google.com; s=arc-20160816; b=eOvP6La/9E/oAtNtRhO7YErz1vg/QAWRrk8+5eKfjsvUu4lFH0Kr3+NtoBSunH6D16 dIhR427OJKYz0bVt/FyQh6sFwikeOnIQlcww9pCN+Ke9StbPHgHIGvLgPviueg405B78 kp72mWy0E2xybutwMXb4TPcSuhEMh90NZnJRhHkDSPHpoHIOjoVlAn53pm80s+DL6Ufv qEMOfr1UWXcnffKLxdgi6e7IuQ4KNNepkDrc+dnm7lNPoofX9tjKMrzFNN4XUg61tsQk H1cRPjXvurRb9BxYKmTN6N5Xxq2EUe8JplZzU5/fN1cRzNn7+o84tT6CTobNXGWdN+pQ AhDg== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=1UVG29Cpn0UcuR4fmA0/80QDLkp8YCl2YIjCaryh7RQ=; b=Z8lKOZK46bZsU1dB7+bpLrh/F8ZJexvogitHGxFMKOK1FEQr+CA7m0qoiwVipGtAmL Du2/T/uDDGaskOqrfFMMni88cj9JRc+9dCAhAlhH31mMCn16CtccBNGZmio63LHR0K0d VaiAEdObujqc2/+iPFldExOUzDvJnH+ffpAJFu9/c7OAxuiwhOhPXCfPDpNsewlCXGCO o+Gppi4OGzFWLci+tT0SEvCgFDeAaLI2/K5CQyuEVOizaDNYq/GIzdBcH/NcGwvOZEbu q+W4IhOg660vs477ulhHQUkTSS3cs2Yg2nhUyNVzGaWlqawnFgeUQG9xZhz5vtrS1zj0 E6CQ== 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 o33si6015992plb.230.2019.05.16.11.34.03; Thu, 16 May 2019 11:34:18 -0700 (PDT) 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 S1727333AbfEPRVT (ORCPT + 99 others); Thu, 16 May 2019 13:21:19 -0400 Received: from www.llwyncelyn.cymru ([82.70.14.225]:42792 "EHLO fuzix.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726807AbfEPRVT (ORCPT ); Thu, 16 May 2019 13:21:19 -0400 Received: from alans-desktop (82-70-14-226.dsl.in-addr.zen.co.uk [82.70.14.226]) by fuzix.org (8.15.2/8.15.2) with ESMTP id x4GHKxbf002968; Thu, 16 May 2019 18:20:59 +0100 Date: Thu, 16 May 2019 18:20:58 +0100 From: Alan Cox To: Arnaud Pouliquen Cc: Ohad Ben-Cohen , Bjorn Andersson , Greg Kroah-Hartman , Jiri Slaby , xiang xiao , , , Fabien DESSENNE Subject: Re: [PATCH v2 2/2] tty: add rpmsg driver Message-ID: <20190516182058.2a565748@alans-desktop> In-Reply-To: <1557500577-22366-3-git-send-email-arnaud.pouliquen@st.com> References: <1557500577-22366-1-git-send-email-arnaud.pouliquen@st.com> <1557500577-22366-3-git-send-email-arnaud.pouliquen@st.com> Organization: Intel Corporation X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > +static int rpmsg_tty_data_handler(struct rpmsg_device *rpdev, void *data, > + int len, void *priv, u32 src) > +{ > + struct rpmsg_tty_port *cport = dev_get_drvdata(&rpdev->dev); > + u8 *cbuf; > + int space; > + > + dev_dbg(&rpdev->dev, "msg(<- src 0x%x) len %d\n", src, len); > + > + if (!len) > + return 0; > + > + dev_dbg(&rpdev->dev, "space available: %d\n", > + tty_buffer_space_avail(&cport->port)); > + > + space = tty_prepare_flip_string(&cport->port, &cbuf, len); > + if (space <= 0) { > + dev_err(&rpdev->dev, "No memory for tty_prepare_flip_string\n"); > + return -ENOMEM; > + } Really bad idea. 1. It's not an 'error'. It's normal that in the case the consumer is blocked you can run out of processing space 2. You will trigger this when being hit by a very large fast flow of data so responding by burning CPU spewing messages (possibly even out of this tty) is bad. It's not a bug - just keep statistics and throw it away. If anyone cares they will do flow control. > + > +static int rpmsg_tty_write_control(struct tty_struct *tty, u8 ctrl, u8 *values, > + unsigned int n_value) > +{ > + struct rpmsg_tty_port *cport = idr_find(&tty_idr, tty->index); > + struct rpmsg_tty_payload *msg; > + struct rpmsg_tty_ctrl *m_ctrl; > + struct rpmsg_device *rpdev; > + unsigned int msg_size; > + int ret; > + > + if (!cport) { > + dev_err(tty->dev, "cannot get cport\n"); > + return -ENODEV; > + } > + > + rpdev = cport->rpdev; > + > + msg_size = sizeof(*msg) + sizeof(*m_ctrl) + n_value; > + msg = kzalloc(msg_size, GFP_KERNEL); Out of memory check ? > +static int rpmsg_tty_write(struct tty_struct *tty, const u8 *buf, int len) > +{ > + struct rpmsg_tty_port *cport = idr_find(&tty_idr, tty->index); > + struct rpmsg_device *rpdev; > + int msg_size, msg_max_size, ret = 0; > + int cmd_sz = sizeof(struct rpmsg_tty_payload); > + u8 *tmpbuf; > + > + if (!cport) { > + dev_err(tty->dev, "cannot get cport\n"); > + return -ENODEV; > + } > + > + /* If cts not set, the message is not sent*/ > + if (!cport->cts) > + return 0; > + > + rpdev = cport->rpdev; > + > + dev_dbg(&rpdev->dev, "%s: send msg from tty->index = %d, len = %d\n", > + __func__, tty->index, len); > + if (!buf) { > + dev_err(&rpdev->dev, "buf shouldn't be null.\n"); > + return -ENOMEM; > + } > + > + msg_max_size = rpmsg_get_buf_payload_size(rpdev->ept); > + if (msg_max_size < 0) > + return msg_max_size; > + > + msg_size = min(len + cmd_sz, msg_max_size); > + tmpbuf = kzalloc(msg_size, GFP_KERNEL); Allocation failure check ?