Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d19f359

Browse files
committed
platform/x86: dell_rbu: don't open code list_for_each_entry*()
The loop declaration in packet_read_list() and packet_empty_list() can be simplified by reusing the common list_for_each_entry*() helper macros. Signed-off-by: Andy Shevchenko <[email protected]>
1 parent 94ed313 commit d19f359

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

drivers/platform/x86/dell_rbu.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,13 @@ static int packetize_data(const u8 *data, size_t length)
255255
return rc;
256256
}
257257

258-
static int do_packet_read(char *data, struct list_head *ptemp_list,
258+
static int do_packet_read(char *data, struct packet_data *newpacket,
259259
int length, int bytes_read, int *list_read_count)
260260
{
261261
void *ptemp_buf;
262-
struct packet_data *newpacket = NULL;
263262
int bytes_copied = 0;
264263
int j = 0;
265264

266-
newpacket = list_entry(ptemp_list, struct packet_data, list);
267265
*list_read_count += newpacket->length;
268266

269267
if (*list_read_count > bytes_read) {
@@ -291,7 +289,7 @@ static int do_packet_read(char *data, struct list_head *ptemp_list,
291289

292290
static int packet_read_list(char *data, size_t * pread_length)
293291
{
294-
struct list_head *ptemp_list;
292+
struct packet_data *newpacket;
295293
int temp_count = 0;
296294
int bytes_copied = 0;
297295
int bytes_read = 0;
@@ -305,9 +303,8 @@ static int packet_read_list(char *data, size_t * pread_length)
305303
remaining_bytes = *pread_length;
306304
bytes_read = rbu_data.packet_read_count;
307305

308-
ptemp_list = (&packet_data_head.list)->next;
309-
while (!list_empty(ptemp_list)) {
310-
bytes_copied = do_packet_read(pdest, ptemp_list,
306+
list_for_each_entry(newpacket, (&packet_data_head.list)->next, list) {
307+
bytes_copied = do_packet_read(pdest, newpacket,
311308
remaining_bytes, bytes_read, &temp_count);
312309
remaining_bytes -= bytes_copied;
313310
bytes_read += bytes_copied;
@@ -318,8 +315,6 @@ static int packet_read_list(char *data, size_t * pread_length)
318315
*/
319316
if (remaining_bytes == 0)
320317
break;
321-
322-
ptemp_list = ptemp_list->next;
323318
}
324319
/*finally set the bytes read */
325320
*pread_length = bytes_read - rbu_data.packet_read_count;
@@ -329,17 +324,11 @@ static int packet_read_list(char *data, size_t * pread_length)
329324

330325
static void packet_empty_list(void)
331326
{
332-
struct list_head *ptemp_list;
333-
struct list_head *pnext_list;
334-
struct packet_data *newpacket;
327+
struct packet_data *newpacket, *tmp;
328+
329+
list_for_each_entry_safe(newpacket, tmp, (&packet_data_head.list)->next, list) {
330+
list_del(&newpacket->list);
335331

336-
ptemp_list = (&packet_data_head.list)->next;
337-
while (!list_empty(ptemp_list)) {
338-
newpacket =
339-
list_entry(ptemp_list, struct packet_data, list);
340-
pnext_list = ptemp_list->next;
341-
list_del(ptemp_list);
342-
ptemp_list = pnext_list;
343332
/*
344333
* zero out the RBU packet memory before freeing
345334
* to make sure there are no stale RBU packets left in memory

0 commit comments

Comments
 (0)