Skip to content

Commit e4439fa

Browse files
wingmankwokdavem330
authored andcommitted
net: ethernet: ti: cpts: clean up event list if event pool is empty
When a CPTS user does not exit gracefully by disabling cpts timestamping and leaving a joined multicast group, the system continues to receive and timestamps the ptp packets which eventually occupy all the event list entries. When this happns, the added code tries to remove some list entries which are expired. Signed-off-by: WingMan Kwok <[email protected]> Signed-off-by: Grygorii Strashko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8fcd689 commit e4439fa

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

drivers/net/ethernet/ti/cpts.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ static int cpts_fifo_pop(struct cpts *cpts, u32 *high, u32 *low)
5757
return -1;
5858
}
5959

60+
static int cpts_purge_events(struct cpts *cpts)
61+
{
62+
struct list_head *this, *next;
63+
struct cpts_event *event;
64+
int removed = 0;
65+
66+
list_for_each_safe(this, next, &cpts->events) {
67+
event = list_entry(this, struct cpts_event, list);
68+
if (event_expired(event)) {
69+
list_del_init(&event->list);
70+
list_add(&event->list, &cpts->pool);
71+
++removed;
72+
}
73+
}
74+
75+
if (removed)
76+
pr_debug("cpts: event pool cleaned up %d\n", removed);
77+
return removed ? 0 : -1;
78+
}
79+
6080
/*
6181
* Returns zero if matching event type was found.
6282
*/
@@ -69,10 +89,12 @@ static int cpts_fifo_read(struct cpts *cpts, int match)
6989
for (i = 0; i < CPTS_FIFO_DEPTH; i++) {
7090
if (cpts_fifo_pop(cpts, &hi, &lo))
7191
break;
72-
if (list_empty(&cpts->pool)) {
73-
pr_err("cpts: event pool is empty\n");
92+
93+
if (list_empty(&cpts->pool) && cpts_purge_events(cpts)) {
94+
pr_err("cpts: event pool empty\n");
7495
return -1;
7596
}
97+
7698
event = list_first_entry(&cpts->pool, struct cpts_event, list);
7799
event->tmo = jiffies + 2;
78100
event->high = hi;

0 commit comments

Comments
 (0)