mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 00:04:15 +08:00
a7e454542b
The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to declare
variable-length types such as these ones is a flexible array member[1][2],
introduced in C99:
struct foo {
int stuff;
struct boo array[];
};
By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last in the structure, which
will help us prevent some kind of undefined behavior bugs from being
inadvertently introduced[3] to the codebase from now on.
Also, notice that, dynamic memory allocations won't be affected by
this change:
"Flexible array members have incomplete type, and so the sizeof operator
may not be applied. As a quirk of the original implementation of
zero-length arrays, sizeof evaluates to zero."[1]
This issue was found with the help of Coccinelle.
[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 7649773293
("cxgb3/l2t: Fix undefined behaviour")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
102 lines
2.3 KiB
C
102 lines
2.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Bluetooth support for Realtek devices
|
|
*
|
|
* Copyright (C) 2015 Endless Mobile, Inc.
|
|
*/
|
|
|
|
#define RTL_FRAG_LEN 252
|
|
|
|
#define rtl_dev_err(dev, fmt, ...) bt_dev_err(dev, "RTL: " fmt, ##__VA_ARGS__)
|
|
#define rtl_dev_warn(dev, fmt, ...) bt_dev_warn(dev, "RTL: " fmt, ##__VA_ARGS__)
|
|
#define rtl_dev_info(dev, fmt, ...) bt_dev_info(dev, "RTL: " fmt, ##__VA_ARGS__)
|
|
#define rtl_dev_dbg(dev, fmt, ...) bt_dev_dbg(dev, "RTL: " fmt, ##__VA_ARGS__)
|
|
|
|
struct btrtl_device_info;
|
|
|
|
struct rtl_download_cmd {
|
|
__u8 index;
|
|
__u8 data[RTL_FRAG_LEN];
|
|
} __packed;
|
|
|
|
struct rtl_download_response {
|
|
__u8 status;
|
|
__u8 index;
|
|
} __packed;
|
|
|
|
struct rtl_rom_version_evt {
|
|
__u8 status;
|
|
__u8 version;
|
|
} __packed;
|
|
|
|
struct rtl_epatch_header {
|
|
__u8 signature[8];
|
|
__le32 fw_version;
|
|
__le16 num_patches;
|
|
} __packed;
|
|
|
|
struct rtl_vendor_config_entry {
|
|
__le16 offset;
|
|
__u8 len;
|
|
__u8 data[];
|
|
} __packed;
|
|
|
|
struct rtl_vendor_config {
|
|
__le32 signature;
|
|
__le16 total_len;
|
|
struct rtl_vendor_config_entry entry[];
|
|
} __packed;
|
|
|
|
#if IS_ENABLED(CONFIG_BT_RTL)
|
|
|
|
struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
|
|
const char *postfix);
|
|
void btrtl_free(struct btrtl_device_info *btrtl_dev);
|
|
int btrtl_download_firmware(struct hci_dev *hdev,
|
|
struct btrtl_device_info *btrtl_dev);
|
|
int btrtl_setup_realtek(struct hci_dev *hdev);
|
|
int btrtl_shutdown_realtek(struct hci_dev *hdev);
|
|
int btrtl_get_uart_settings(struct hci_dev *hdev,
|
|
struct btrtl_device_info *btrtl_dev,
|
|
unsigned int *controller_baudrate,
|
|
u32 *device_baudrate, bool *flow_control);
|
|
|
|
#else
|
|
|
|
static inline struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
|
|
const char *postfix)
|
|
{
|
|
return ERR_PTR(-EOPNOTSUPP);
|
|
}
|
|
|
|
static inline void btrtl_free(struct btrtl_device_info *btrtl_dev)
|
|
{
|
|
}
|
|
|
|
static inline int btrtl_download_firmware(struct hci_dev *hdev,
|
|
struct btrtl_device_info *btrtl_dev)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline int btrtl_setup_realtek(struct hci_dev *hdev)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline int btrtl_shutdown_realtek(struct hci_dev *hdev)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline int btrtl_get_uart_settings(struct hci_dev *hdev,
|
|
struct btrtl_device_info *btrtl_dev,
|
|
unsigned int *controller_baudrate,
|
|
u32 *device_baudrate,
|
|
bool *flow_control)
|
|
{
|
|
return -ENOENT;
|
|
}
|
|
|
|
#endif
|