qcacmn: Abstract qdf_mem_validate_list_node()

Currently qdf_mem contains a function, qdf_mem_validate_list_node(), for
validating a list node and ensuring it is currently part of a list.
Instead, abstract this function from qdf_mem, and move the definition to
qdf_list_node_in_any_list() in qdf_list. This is a more reasonable
location for the list-specific logic, and allows its reuse by other
callers.

Change-Id: I56a5d54e3c81470a111f168533faedf7fa525ff3
CRs-Fixed: 2359358
This commit is contained in:
Dustin Brown
2018-11-30 12:38:07 -08:00
zatwierdzone przez nshrivas
rodzic c2cc252d18
commit 40bd452c5b
4 zmienionych plików z 53 dodań i 46 usunięć

Wyświetl plik

@@ -104,6 +104,4 @@ static inline void __qdf_init_list_head(__qdf_list_node_t *list_head)
{
INIT_LIST_HEAD(list_head);
}
bool qdf_list_has_node(__qdf_list_t *list, __qdf_list_node_t *node);
#endif

Wyświetl plik

@@ -115,7 +115,7 @@ QDF_STATUS qdf_list_remove_front(qdf_list_t *list, qdf_list_node_t **node2)
listptr = list->anchor.next;
*node2 = listptr;
list_del(list->anchor.next);
list_del_init(list->anchor.next);
list->count--;
return QDF_STATUS_SUCCESS;
@@ -138,23 +138,13 @@ QDF_STATUS qdf_list_remove_back(qdf_list_t *list, qdf_list_node_t **node2)
listptr = list->anchor.prev;
*node2 = listptr;
list_del(list->anchor.prev);
list_del_init(list->anchor.prev);
list->count--;
return QDF_STATUS_SUCCESS;
}
qdf_export_symbol(qdf_list_remove_back);
/**
* qdf_list_has_node() - check if a node is in a list
* @list: pointer to the list being searched
* @node: pointer to the node to search for
*
* It is expected that the list being checked is locked
* when this function is being called.
*
* Return: true if the node is in the list
*/
bool qdf_list_has_node(qdf_list_t *list, qdf_list_node_t *node)
{
qdf_list_node_t *tmp;
@@ -163,6 +153,7 @@ bool qdf_list_has_node(qdf_list_t *list, qdf_list_node_t *node)
if (tmp == node)
return true;
}
return false;
}
@@ -183,7 +174,7 @@ QDF_STATUS qdf_list_remove_node(qdf_list_t *list,
if (list_empty(&list->anchor))
return QDF_STATUS_E_EMPTY;
list_del(node_to_remove);
list_del_init(node_to_remove);
list->count--;
return QDF_STATUS_SUCCESS;
@@ -206,6 +197,7 @@ QDF_STATUS qdf_list_peek_front(qdf_list_t *list, qdf_list_node_t **node2)
listptr = list->anchor.next;
*node2 = listptr;
return QDF_STATUS_SUCCESS;
}
qdf_export_symbol(qdf_list_peek_front);
@@ -248,3 +240,25 @@ bool qdf_list_empty(qdf_list_t *list)
return list_empty(&list->anchor);
}
qdf_export_symbol(qdf_list_empty);
bool qdf_list_node_in_any_list(const qdf_list_node_t *node)
{
const struct list_head *linux_node = (const struct list_head *)node;
if (!linux_node)
return false;
/* if the node is an empty list, it is not tied to an anchor node */
if (list_empty(linux_node))
return false;
if (!linux_node->prev || !linux_node->next)
return false;
if (linux_node->prev->next != linux_node ||
linux_node->next->prev != linux_node)
return false;
return true;
}

Wyświetl plik

@@ -169,32 +169,6 @@ enum qdf_mem_validation_bitmap {
QDF_MEM_WRONG_DOMAIN = 1 << 7,
};
/**
* qdf_mem_validate_list_node() - validate that the node is in a list
* @qdf_node: node to check for being in a list
*
* Return: true if the node validly linked in an anchored doubly linked list
*/
static bool qdf_mem_validate_list_node(qdf_list_node_t *qdf_node)
{
struct list_head *node = qdf_node;
/*
* if the node is an empty list, it is not tied to an anchor node
* and must have been removed with list_del_init
*/
if (list_empty(node))
return false;
if (!node->prev || !node->next)
return false;
if (node->prev->next != node || node->next->prev != node)
return false;
return true;
}
static enum qdf_mem_validation_bitmap
qdf_mem_trailer_validate(struct qdf_mem_header *header)
{
@@ -222,7 +196,7 @@ qdf_mem_header_validate(struct qdf_mem_header *header,
else if (header->freed)
error_bitmap |= QDF_MEM_BAD_FREED;
if (!qdf_mem_validate_list_node(&header->node))
if (!qdf_list_node_in_any_list(&header->node))
error_bitmap |= QDF_MEM_BAD_NODE;
if (header->domain < QDF_DEBUG_DOMAIN_INIT ||
@@ -1126,8 +1100,8 @@ void qdf_mem_free_debug(void *ptr, const char *file, uint32_t line)
if (!error_bitmap) {
header->freed = true;
list_del_init(&header->node);
qdf_mem_list_get(header->domain)->count--;
qdf_list_remove_node(qdf_mem_list_get(header->domain),
&header->node);
}
qdf_spin_unlock_irqrestore(&qdf_mem_list_lock);
@@ -1760,8 +1734,8 @@ void qdf_mem_free_consistent_debug(qdf_device_t osdev, void *dev,
error_bitmap = qdf_mem_header_validate(header, domain);
if (!error_bitmap) {
header->freed = true;
list_del_init(&header->node);
qdf_mem_dma_list(header->domain)->count--;
qdf_list_remove_node(qdf_mem_dma_list(header->domain),
&header->node);
}
qdf_spin_unlock_irqrestore(&qdf_mem_dma_list_lock);