linux-stable/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h
Gustavo A. R. Silva 232c897eb5 brcmfmac: Replace zero-length array with flexible-array member
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>
Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20200225020804.GA9428@embeddedor
2020-03-23 19:12:12 +02:00

86 lines
2.1 KiB
C

// SPDX-License-Identifier: ISC
/*
* Copyright (c) 2013 Broadcom Corporation
*/
#ifndef BRCMFMAC_FIRMWARE_H
#define BRCMFMAC_FIRMWARE_H
#define BRCMF_FW_REQF_OPTIONAL 0x0001
#define BRCMF_FW_NAME_LEN 320
#define BRCMF_FW_DEFAULT_PATH "brcm/"
/**
* struct brcmf_firmware_mapping - Used to map chipid/revmask to firmware
* filename and nvram filename. Each bus type implementation should create
* a table of firmware mappings (using the macros defined below).
*
* @chipid: ID of chip.
* @revmask: bitmask of revisions, e.g. 0x10 means rev 4 only, 0xf means rev 0-3
* @fw: name of the firmware file.
* @nvram: name of nvram file.
*/
struct brcmf_firmware_mapping {
u32 chipid;
u32 revmask;
const char *fw_base;
};
#define BRCMF_FW_DEF(fw_name, fw_base) \
static const char BRCM_ ## fw_name ## _FIRMWARE_BASENAME[] = \
BRCMF_FW_DEFAULT_PATH fw_base; \
MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH fw_base ".bin")
#define BRCMF_FW_ENTRY(chipid, mask, name) \
{ chipid, mask, BRCM_ ## name ## _FIRMWARE_BASENAME }
void brcmf_fw_nvram_free(void *nvram);
enum brcmf_fw_type {
BRCMF_FW_TYPE_BINARY,
BRCMF_FW_TYPE_NVRAM
};
struct brcmf_fw_item {
const char *path;
enum brcmf_fw_type type;
u16 flags;
union {
const struct firmware *binary;
struct {
void *data;
u32 len;
} nv_data;
};
};
struct brcmf_fw_request {
u16 domain_nr;
u16 bus_nr;
u32 n_items;
const char *board_type;
struct brcmf_fw_item items[];
};
struct brcmf_fw_name {
const char *extension;
char *path;
};
struct brcmf_fw_request *
brcmf_fw_alloc_request(u32 chip, u32 chiprev,
const struct brcmf_firmware_mapping mapping_table[],
u32 table_size, struct brcmf_fw_name *fwnames,
u32 n_fwnames);
/*
* Request firmware(s) asynchronously. When the asynchronous request
* fails it will not use the callback, but call device_release_driver()
* instead which will call the driver .remove() callback.
*/
int brcmf_fw_get_firmwares(struct device *dev, struct brcmf_fw_request *req,
void (*fw_cb)(struct device *dev, int err,
struct brcmf_fw_request *req));
#endif /* BRCMFMAC_FIRMWARE_H */