btdev code view problem modification, debug rectification

1. bt_io_file_write function call copy_from_user branch failure need to release skb.
2. The branch that bt_io_file_read fails to call copy_to_user needs to release skb, because skb has been unchained from ring buf.
3. The bt_cmd_peek_packet function only obtains the skb data length. After put_user fails, the skb does not need to be released.
4. The bt_cmd_create_virnet function bt_get_unused_id may return an invalid id, and add the if judgment that the id is less than 0.
5. The branch of bt_cmd_create_virnet function copy_to_user that fails needs to release bt_table_remove_device.
6. bt_table_add_device and bt_table_remove_device functions to tbl->num variable ++ and -- operation to increase the validity judgment, avoid flipping.
7. __bt_ring_create function if (unlikely(size < 0)) branch has memory leaks, modified to determine the validity of the input parameter, and then apply for memory.
8. Both bt_ring_is_empty and bt_ring_is_full return true for invalid branches.
9. bt_virnet_produce_data adds a memory barrier before and after calling bt_ring_produce, and bt_ring_produce already has a memory barrier. Delete the redundant memory barrier.
10. The vnet->tx_queue variable is a redundant operation and has no practical effect. Delete all codes corresponding to the variable to improve the efficiency of receiving and sending packets on the btdev virtual device.
   bt_virnet_create deletes init_waitqueue_head(&vnet->tx_queue);
   bt_io_file_poll deletes poll_wait(filp, &vnet->tx_queue, wait);
11. Change the global variable name to g_xxx
12. atomic operation process xx_open_limit variable value changes add annotation
13. debug rectification, the normal path is closed by default (shell can be opened), and the abnormal path is opened by default. At the same time, key information such as btdev interface name printing and data length are added to the interface open, delete, and packet sending functions.

Signed-off-by: yangyanjun <yangyanjun@huawei.com>
This commit is contained in:
yangyanjun
2023-06-16 14:40:27 +08:00
parent 5f0e2198b1
commit c786a42652
2 changed files with 265 additions and 208 deletions
File diff suppressed because it is too large Load Diff
+7 -8
View File
@@ -39,11 +39,14 @@
#include <linux/seq_file.h>
#include <linux/ktime.h>
#include <linux/rtnetlink.h>
#include <linux/libfdt_env.h>
/* must include btdev_user.h first before any macro definition */
#include "btdev_user.h"
#define OK 0
#define TRUE 1
#define FALSE 0
#define DELAY_100_MS 100
#define MACADDR_LEN (2 * ETH_ALEN)
@@ -56,10 +59,6 @@
#define NEWIP_TYPE_SIZE 2 /* newip type eadd */
#define BT_MAX_MTU 65535
#define UNKNOWN_NAME "unknown"
/**
* for debug
*/
#define DEBUG
/**
* ring buffer
@@ -122,7 +121,7 @@ struct bt_virnet {
struct list_head virnet_entry;
enum bt_virnet_state state;
struct semaphore sem;
wait_queue_head_t rx_queue, tx_queue;
wait_queue_head_t rx_queue;
};
/**
@@ -140,7 +139,7 @@ struct bt_drv {
/**
* state to string
*/
static const char *bt_virnet_state_rep[BT_VIRNET_STAET_NUM] = {
static const char *g_bt_virnet_state_rep[BT_VIRNET_STAET_NUM] = {
"CREATED",
"CONNECTED",
"DISCONNECTED",
@@ -222,7 +221,7 @@ static inline const char *bt_virnet_get_ndev_name(const struct bt_virnet *vn)
static inline const char *bt_virnet_get_state_rep(const struct bt_virnet *vn)
{
return bt_virnet_state_rep[vn->state];
return g_bt_virnet_state_rep[vn->state];
}
static inline int bt_get_total_device(const struct bt_drv *drv)
@@ -239,7 +238,7 @@ static inline int bt_virnet_get_ring_packets(const struct bt_virnet *vn)
if (unlikely(!vn->tx_ring) || unlikely(!vn->tx_ring->head) ||
unlikely(!vn->tx_ring->tail))
return -EINVAL;
return 0;
packets = vn->tx_ring->head - vn->tx_ring->tail;
if (unlikely(packets < 0))