blob: dd6ead7b86473fdb406007dbe39db5fcec83c396 [file] [log] [blame]
From b717816885270bfe80ed184cb894b14c10c3f48f Mon Sep 17 00:00:00 2001
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Thu, 24 Jan 2019 12:32:05 +0100
Subject: [PATCH 05/15] tty: n_r3964: split rx and tx header structures
It's really confusing to try to figure out what structure is what type
of header when both the tx and rx queues are using the same header
structure, but not all of the fields in it.
So split this into two different structures. That makes it much more
obvious what variable and queue and type of message is being kept track
of where.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/tty/n_r3964.c | 78 +++++++++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 39 deletions(-)
--- a/drivers/tty/n_r3964.c
+++ b/drivers/tty/n_r3964.c
@@ -101,6 +101,8 @@ enum {
/* All open file-handles are 'clients' and are stored in a linked list: */
struct r3964_message;
+struct rx_block_header;
+struct tx_block_header;
struct r3964_client_info {
spinlock_t lock;
@@ -111,30 +113,35 @@ struct r3964_client_info {
struct r3964_message *first_msg;
struct r3964_message *last_msg;
- struct r3964_block_header *next_block_to_read;
+ struct rx_block_header *next_block_to_read;
int msg_count;
};
-struct r3964_block_header;
-
/* internal version of client_message: */
struct r3964_message {
int msg_id;
int arg;
int error_code;
- struct r3964_block_header *block;
+ struct rx_block_header *block;
struct r3964_message *next;
};
-/* Header of received block in rx_buf/tx_buf: */
-struct r3964_block_header {
+/* Header of received block in rx_buf: */
+struct rx_block_header {
unsigned int length; /* length in chars without header */
unsigned char *data; /* usually data is located immediately
* behind this struct */
unsigned int locks; /* only used in rx_buffer */
- struct r3964_block_header *next;
- struct r3964_client_info *owner; /* =NULL in rx_buffer */
+ struct rx_block_header *next;
+};
+
+/* Header of received block in tx_buf: */
+struct tx_block_header {
+ unsigned int length; /* length in chars without header */
+ unsigned char *data;
+ struct tx_block_header *next;
+ struct r3964_client_info *owner;
};
/*
@@ -162,10 +169,10 @@ struct r3964_info {
unsigned char *rx_buf; /* ring buffer */
unsigned char *tx_buf;
- struct r3964_block_header *rx_first;
- struct r3964_block_header *rx_last;
- struct r3964_block_header *tx_first;
- struct r3964_block_header *tx_last;
+ struct rx_block_header *rx_first;
+ struct rx_block_header *rx_last;
+ struct tx_block_header *tx_first;
+ struct tx_block_header *tx_last;
unsigned int tx_position;
unsigned int rx_position;
unsigned char last_rx;
@@ -182,8 +189,6 @@ struct r3964_info {
int nRetry;
};
-static void add_tx_queue(struct r3964_info *, struct r3964_block_header *);
-static void remove_from_tx_queue(struct r3964_info *pInfo, int error_code);
static void put_char(struct r3964_info *pInfo, unsigned char ch);
static void trigger_transmit(struct r3964_info *pInfo);
static void retry_transmit(struct r3964_info *pInfo);
@@ -195,7 +200,7 @@ static int enable_signals(struct r3964_i
static int read_telegram(struct r3964_info *pInfo, struct pid *pid,
unsigned char __user * buf);
static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg,
- int error_code, struct r3964_block_header *pBlock);
+ int error_code, struct rx_block_header *pBlock);
static struct r3964_message *remove_msg(struct r3964_info *pInfo,
struct r3964_client_info *pClient);
static void remove_client_block(struct r3964_info *pInfo,
@@ -306,7 +311,7 @@ module_exit(r3964_exit);
*************************************************************/
static void add_tx_queue(struct r3964_info *pInfo,
- struct r3964_block_header *pHeader)
+ struct tx_block_header *pHeader)
{
unsigned long flags;
@@ -329,10 +334,10 @@ static void add_tx_queue(struct r3964_in
static void remove_from_tx_queue(struct r3964_info *pInfo, int error_code)
{
- struct r3964_block_header *pHeader;
+ struct tx_block_header *pHeader;
unsigned long flags;
#ifdef DEBUG_QUEUE
- struct r3964_block_header *pDump;
+ struct tx_block_header *pDump;
#endif
pHeader = pInfo->tx_first;
@@ -376,7 +381,7 @@ static void remove_from_tx_queue(struct
}
static void add_rx_queue(struct r3964_info *pInfo,
- struct r3964_block_header *pHeader)
+ struct rx_block_header *pHeader)
{
unsigned long flags;
@@ -400,10 +405,10 @@ static void add_rx_queue(struct r3964_in
}
static void remove_from_rx_queue(struct r3964_info *pInfo,
- struct r3964_block_header *pHeader)
+ struct rx_block_header *pHeader)
{
unsigned long flags;
- struct r3964_block_header *pFind;
+ struct rx_block_header *pFind;
if (pHeader == NULL)
return;
@@ -517,7 +522,7 @@ static void retry_transmit(struct r3964_
static void transmit_block(struct r3964_info *pInfo)
{
struct tty_struct *tty = pInfo->tty;
- struct r3964_block_header *pBlock = pInfo->tx_first;
+ struct tx_block_header *pBlock = pInfo->tx_first;
int room = 0;
if (tty == NULL || pBlock == NULL) {
@@ -558,7 +563,7 @@ static void on_receive_block(struct r396
{
unsigned int length;
struct r3964_client_info *pClient;
- struct r3964_block_header *pBlock;
+ struct rx_block_header *pBlock;
unsigned long flags;
length = pInfo->rx_position;
@@ -596,20 +601,17 @@ static void on_receive_block(struct r396
del_timer_sync(&pInfo->tmr);
TRACE_PS(" rx success: got %d chars", length);
- /* prepare struct r3964_block_header: */
- pBlock = kmalloc(length + sizeof(struct r3964_block_header),
- GFP_KERNEL);
+ /* prepare struct rx_block_header: */
+ pBlock = kmalloc(length + sizeof(*pBlock), GFP_KERNEL);
TRACE_M("on_receive_block - kmalloc %p", pBlock);
if (pBlock == NULL)
return;
pBlock->length = length;
- pBlock->data = ((unsigned char *)pBlock) +
- sizeof(struct r3964_block_header);
+ pBlock->data = ((unsigned char *)pBlock) + sizeof(*pBlock);
pBlock->locks = 0;
pBlock->next = NULL;
- pBlock->owner = NULL;
memcpy(pBlock->data, pInfo->rx_buf, length);
@@ -905,7 +907,7 @@ static int read_telegram(struct r3964_in
unsigned char __user * buf)
{
struct r3964_client_info *pClient;
- struct r3964_block_header *block;
+ struct rx_block_header *block;
if (!buf) {
return -EINVAL;
@@ -931,7 +933,7 @@ static int read_telegram(struct r3964_in
}
static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg,
- int error_code, struct r3964_block_header *pBlock)
+ int error_code, struct rx_block_header *pBlock)
{
struct r3964_message *pMsg;
unsigned long flags;
@@ -1014,7 +1016,7 @@ static struct r3964_message *remove_msg(
static void remove_client_block(struct r3964_info *pInfo,
struct r3964_client_info *pClient)
{
- struct r3964_block_header *block;
+ struct rx_block_header *block;
TRACE_PS("remove_client_block PID %d", pid_nr(pClient->pid));
@@ -1098,7 +1100,7 @@ static void r3964_close(struct tty_struc
struct r3964_info *pInfo = tty->disc_data;
struct r3964_client_info *pClient, *pNext;
struct r3964_message *pMsg;
- struct r3964_block_header *pHeader, *pNextHeader;
+ struct tx_block_header *pHeader, *pNextHeader;
unsigned long flags;
TRACE_L("close");
@@ -1214,7 +1216,7 @@ static ssize_t r3964_write(struct tty_st
const unsigned char *data, size_t count)
{
struct r3964_info *pInfo = tty->disc_data;
- struct r3964_block_header *pHeader;
+ struct tx_block_header *pHeader;
struct r3964_client_info *pClient;
unsigned char *new_data;
@@ -1239,8 +1241,7 @@ static ssize_t r3964_write(struct tty_st
/*
* Allocate a buffer for the data and copy it from the buffer with header prepended
*/
- new_data = kmalloc(count + sizeof(struct r3964_block_header),
- GFP_KERNEL);
+ new_data = kmalloc(count + sizeof(*pHeader), GFP_KERNEL);
TRACE_M("r3964_write - kmalloc %p", new_data);
if (new_data == NULL) {
if (pInfo->flags & R3964_DEBUG) {
@@ -1249,10 +1250,9 @@ static ssize_t r3964_write(struct tty_st
return -ENOSPC;
}
- pHeader = (struct r3964_block_header *)new_data;
- pHeader->data = new_data + sizeof(struct r3964_block_header);
+ pHeader = (struct tx_block_header *)new_data;
+ pHeader->data = new_data + sizeof(*pHeader);
pHeader->length = count;
- pHeader->locks = 0;
pHeader->owner = NULL;
pClient = findClient(pInfo, task_pid(current));