1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
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);
@@ -904,7 +906,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;
@@ -930,7 +932,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;
@@ -1013,7 +1015,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));
@@ -1097,7 +1099,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");
@@ -1213,7 +1215,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;
@@ -1238,8 +1240,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) {
@@ -1248,10 +1249,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));
|