linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jiri Slaby <jslaby@suse.cz>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org
Subject: [PATCH 16/44] net: nfc: nci: drop nci_uart_ops::recv_buf
Date: Tue,  2 Mar 2021 07:21:46 +0100	[thread overview]
Message-ID: <20210302062214.29627-16-jslaby@suse.cz> (raw)
In-Reply-To: <20210302062214.29627-1-jslaby@suse.cz>

There is noone setting nci_uart_ops::recv_buf, so the default one
(nci_uart_default_recv_buf) is always used. So drop this hook, move
nci_uart_default_recv_buf before the use in nci_uart_tty_receive and
remove unused parameter flags.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org
---
 include/net/nfc/nci_core.h |   2 -
 net/nfc/nci/uart.c         | 136 ++++++++++++++++++-------------------
 2 files changed, 67 insertions(+), 71 deletions(-)

diff --git a/include/net/nfc/nci_core.h b/include/net/nfc/nci_core.h
index 43c9c5d2bedb..bd76e8e082c0 100644
--- a/include/net/nfc/nci_core.h
+++ b/include/net/nfc/nci_core.h
@@ -430,8 +430,6 @@ struct nci_uart_ops {
 	int (*open)(struct nci_uart *nci_uart);
 	void (*close)(struct nci_uart *nci_uart);
 	int (*recv)(struct nci_uart *nci_uart, struct sk_buff *skb);
-	int (*recv_buf)(struct nci_uart *nci_uart, const u8 *data, char *flags,
-			int count);
 	int (*send)(struct nci_uart *nci_uart, struct sk_buff *skb);
 	void (*tx_start)(struct nci_uart *nci_uart);
 	void (*tx_done)(struct nci_uart *nci_uart);
diff --git a/net/nfc/nci/uart.c b/net/nfc/nci/uart.c
index c9987d1cccdf..5cf7d3729d5f 100644
--- a/net/nfc/nci/uart.c
+++ b/net/nfc/nci/uart.c
@@ -229,6 +229,72 @@ static void nci_uart_tty_wakeup(struct tty_struct *tty)
 	nci_uart_tx_wakeup(nu);
 }
 
+/* -- Default recv_buf handler --
+ *
+ * This handler supposes that NCI frames are sent over UART link without any
+ * framing. It reads NCI header, retrieve the packet size and once all packet
+ * bytes are received it passes it to nci_uart driver for processing.
+ */
+static int nci_uart_default_recv_buf(struct nci_uart *nu, const u8 *data,
+				     int count)
+{
+	int chunk_len;
+
+	if (!nu->ndev) {
+		nfc_err(nu->tty->dev,
+			"receive data from tty but no NCI dev is attached yet, drop buffer\n");
+		return 0;
+	}
+
+	/* Decode all incoming data in packets
+	 * and enqueue then for processing.
+	 */
+	while (count > 0) {
+		/* If this is the first data of a packet, allocate a buffer */
+		if (!nu->rx_skb) {
+			nu->rx_packet_len = -1;
+			nu->rx_skb = nci_skb_alloc(nu->ndev,
+						   NCI_MAX_PACKET_SIZE,
+						   GFP_ATOMIC);
+			if (!nu->rx_skb)
+				return -ENOMEM;
+		}
+
+		/* Eat byte after byte till full packet header is received */
+		if (nu->rx_skb->len < NCI_CTRL_HDR_SIZE) {
+			skb_put_u8(nu->rx_skb, *data++);
+			--count;
+			continue;
+		}
+
+		/* Header was received but packet len was not read */
+		if (nu->rx_packet_len < 0)
+			nu->rx_packet_len = NCI_CTRL_HDR_SIZE +
+				nci_plen(nu->rx_skb->data);
+
+		/* Compute how many bytes are missing and how many bytes can
+		 * be consumed.
+		 */
+		chunk_len = nu->rx_packet_len - nu->rx_skb->len;
+		if (count < chunk_len)
+			chunk_len = count;
+		skb_put_data(nu->rx_skb, data, chunk_len);
+		data += chunk_len;
+		count -= chunk_len;
+
+		/* Chcek if packet is fully received */
+		if (nu->rx_packet_len == nu->rx_skb->len) {
+			/* Pass RX packet to driver */
+			if (nu->ops.recv(nu, nu->rx_skb) != 0)
+				nfc_err(nu->tty->dev, "corrupted RX packet\n");
+			/* Next packet will be a new one */
+			nu->rx_skb = NULL;
+		}
+	}
+
+	return 0;
+}
+
 /* nci_uart_tty_receive()
  *
  *     Called by tty low level driver when receive data is
@@ -250,7 +316,7 @@ static void nci_uart_tty_receive(struct tty_struct *tty, const u8 *data,
 		return;
 
 	spin_lock(&nu->rx_lock);
-	nu->ops.recv_buf(nu, (void *)data, flags, count);
+	nci_uart_default_recv_buf(nu, data, count);
 	spin_unlock(&nu->rx_lock);
 
 	tty_unthrottle(tty);
@@ -321,72 +387,6 @@ static int nci_uart_send(struct nci_uart *nu, struct sk_buff *skb)
 	return 0;
 }
 
-/* -- Default recv_buf handler --
- *
- * This handler supposes that NCI frames are sent over UART link without any
- * framing. It reads NCI header, retrieve the packet size and once all packet
- * bytes are received it passes it to nci_uart driver for processing.
- */
-static int nci_uart_default_recv_buf(struct nci_uart *nu, const u8 *data,
-				     char *flags, int count)
-{
-	int chunk_len;
-
-	if (!nu->ndev) {
-		nfc_err(nu->tty->dev,
-			"receive data from tty but no NCI dev is attached yet, drop buffer\n");
-		return 0;
-	}
-
-	/* Decode all incoming data in packets
-	 * and enqueue then for processing.
-	 */
-	while (count > 0) {
-		/* If this is the first data of a packet, allocate a buffer */
-		if (!nu->rx_skb) {
-			nu->rx_packet_len = -1;
-			nu->rx_skb = nci_skb_alloc(nu->ndev,
-						   NCI_MAX_PACKET_SIZE,
-						   GFP_ATOMIC);
-			if (!nu->rx_skb)
-				return -ENOMEM;
-		}
-
-		/* Eat byte after byte till full packet header is received */
-		if (nu->rx_skb->len < NCI_CTRL_HDR_SIZE) {
-			skb_put_u8(nu->rx_skb, *data++);
-			--count;
-			continue;
-		}
-
-		/* Header was received but packet len was not read */
-		if (nu->rx_packet_len < 0)
-			nu->rx_packet_len = NCI_CTRL_HDR_SIZE +
-				nci_plen(nu->rx_skb->data);
-
-		/* Compute how many bytes are missing and how many bytes can
-		 * be consumed.
-		 */
-		chunk_len = nu->rx_packet_len - nu->rx_skb->len;
-		if (count < chunk_len)
-			chunk_len = count;
-		skb_put_data(nu->rx_skb, data, chunk_len);
-		data += chunk_len;
-		count -= chunk_len;
-
-		/* Chcek if packet is fully received */
-		if (nu->rx_packet_len == nu->rx_skb->len) {
-			/* Pass RX packet to driver */
-			if (nu->ops.recv(nu, nu->rx_skb) != 0)
-				nfc_err(nu->tty->dev, "corrupted RX packet\n");
-			/* Next packet will be a new one */
-			nu->rx_skb = NULL;
-		}
-	}
-
-	return 0;
-}
-
 /* -- Default recv handler -- */
 static int nci_uart_default_recv(struct nci_uart *nu, struct sk_buff *skb)
 {
@@ -403,8 +403,6 @@ int nci_uart_register(struct nci_uart *nu)
 	nu->ops.send = nci_uart_send;
 
 	/* Install default handlers if not overridden */
-	if (!nu->ops.recv_buf)
-		nu->ops.recv_buf = nci_uart_default_recv_buf;
 	if (!nu->ops.recv)
 		nu->ops.recv = nci_uart_default_recv;
 
-- 
2.30.1


  parent reply	other threads:[~2021-03-02  8:26 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-02  6:21 [PATCH 01/44] MAINTAINERS: orphan mxser Jiri Slaby
2021-03-02  6:21 ` [PATCH 02/44] MAINTAINERS: drop cyclades.com reference Jiri Slaby
2021-03-02  6:21 ` [PATCH 03/44] PCI: remove synclink entries from pci_ids Jiri Slaby
2021-03-06 23:47   ` Krzysztof Wilczyński
2021-03-12 22:12   ` Bjorn Helgaas
2021-03-02  6:21 ` [PATCH 04/44] vgacon: comment on vga_rolled_over Jiri Slaby
2021-03-11 13:08   ` Daniel Vetter
2021-03-02  6:21 ` [PATCH 05/44] tty: cyclades, remove this orphan Jiri Slaby
2021-03-02  6:21 ` [PATCH 06/44] tty: isicom, " Jiri Slaby
2021-03-02  6:21 ` [PATCH 07/44] tty: rocket, remove the driver Jiri Slaby
2021-03-02  6:21 ` [PATCH 08/44] tty: remove TTY_LDISC_MAGIC Jiri Slaby
2021-03-02  6:21 ` [PATCH 09/44] tty: n_tty, set tty_ldisc_ops::owner Jiri Slaby
2021-03-02  6:21 ` [PATCH 10/44] tty: imx, use ms_to_ktime Jiri Slaby
2021-03-02  6:59   ` Uwe Kleine-König
2021-03-02  6:21 ` [PATCH 11/44] tty: 8250, " Jiri Slaby
2021-03-02  6:21 ` [PATCH 12/44] tty: 8250, cleanup em485 timers Jiri Slaby
2021-03-02  6:21 ` [PATCH 13/44] tty: 8250/serial_cs, propagate errors in simple_config Jiri Slaby
2021-03-02  6:21 ` [PATCH 14/44] net: caif: inline register_ldisc Jiri Slaby
2021-03-02  6:21 ` [PATCH 15/44] net: nfc: nci: remove memset of nci_uart_drivers Jiri Slaby
2021-03-02  6:21 ` Jiri Slaby [this message]
2021-03-02  6:21 ` [PATCH 17/44] net: nfc: nci: drop nci_uart_default_recv Jiri Slaby
2021-03-02  6:21 ` [PATCH 18/44] tty: con3215, remove tasklet for tty_wakeup Jiri Slaby
2021-03-02  6:21 ` [PATCH 19/44] tty: con3215, remove unneeded tty checks Jiri Slaby
2021-03-02  6:21 ` [PATCH 20/44] tty: con3215, remove tty->driver_data casts Jiri Slaby
2021-03-02  6:21 ` [PATCH 21/44] tty: jsm_tty, make char+error handling readable Jiri Slaby
2021-03-02  6:21 ` [PATCH 22/44] tty: nozomi, remove struct buffer Jiri Slaby
2021-03-02  6:21 ` [PATCH 23/44] tty: nozomi, remove init/exit messages Jiri Slaby
2021-03-02  6:21 ` [PATCH 24/44] tty: nozomi, remove useless debug prints Jiri Slaby
2021-03-02  6:21 ` [PATCH 25/44] tty: vcc, make globals static Jiri Slaby
2021-03-02  6:21 ` [PATCH 26/44] tty: vcc, drop version dump Jiri Slaby
2021-03-02  6:21 ` [PATCH 27/44] tty: vcc, use name strings directly Jiri Slaby
2021-03-02  6:21 ` [PATCH 28/44] tty: vcc, remove useless tty checks Jiri Slaby
2021-03-02  6:21 ` [PATCH 29/44] tty: xtensa/iss, drop serial_version & serial_name Jiri Slaby
2021-03-02  6:45   ` Max Filippov
2021-03-02  6:22 ` [PATCH 30/44] tty: xtensa/iss, don't reassign to tty->port Jiri Slaby
2021-03-02  7:12   ` Max Filippov
2021-03-02  6:22 ` [PATCH 31/44] tty: xtensa/iss, remove stale comments Jiri Slaby
2021-03-02  6:49   ` Max Filippov
2021-03-02  6:22 ` [PATCH 32/44] tty: xtensa/iss, setup the timer statically Jiri Slaby
2021-03-02  6:52   ` Max Filippov
2021-03-02  6:22 ` [PATCH 33/44] tty: xtensa/iss, make rs_init static Jiri Slaby
2021-03-02  6:55   ` Max Filippov
2021-03-02  6:22 ` [PATCH 34/44] tty: do not check tty_unregister_driver's return value Jiri Slaby
2021-03-02  6:57   ` Max Filippov
2021-03-02 11:14   ` David Sterba
2021-03-02  6:22 ` [PATCH 35/44] tty: let tty_unregister_driver return void Jiri Slaby
2021-03-02  6:22 ` [PATCH 36/44] tty: localise ptychar and make it const Jiri Slaby
2021-03-02  6:22 ` [PATCH 37/44] USB: serial/keyspan, drop unneeded forward declarations Jiri Slaby
2021-03-03 19:17   ` Greg KH
2021-03-05 10:10     ` Johan Hovold
2021-03-15  8:43     ` Johan Hovold
2021-03-02  6:22 ` [PATCH 38/44] USB: serial/io_edgeport, " Jiri Slaby
2021-03-03 19:17   ` Greg KH
2021-03-02  6:22 ` [PATCH 39/44] tty: synclink_gt, " Jiri Slaby
2021-03-02  6:22 ` [PATCH 40/44] tty: hvc, " Jiri Slaby
2021-03-02 19:09   ` Tyrel Datwyler
2021-03-03  7:44   ` Uwe Kleine-König
2021-03-02  6:22 ` [PATCH 41/44] tty: n_gsm, remove duplicates of parameters Jiri Slaby
2021-03-02  6:22 ` [PATCH 42/44] tty: cleanup tty_chars_in_buffer Jiri Slaby
2021-03-02  6:22 ` [PATCH 43/44] tty: make everyone's chars_in_buffer return >= 0 Jiri Slaby
2021-03-02  6:22 ` [PATCH 44/44] tty: make everyone's write_room " Jiri Slaby
2021-03-05 10:18   ` Johan Hovold
2021-03-03 19:19 ` [PATCH 01/44] MAINTAINERS: orphan mxser Greg KH

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=20210302062214.29627-16-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@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).