static struct cmd_db_header *cmd_db_header;
-
-static inline void *rsc_to_entry_header(struct rsc_hdr *hdr)
+static inline const void *rsc_to_entry_header(const struct rsc_hdr *hdr)
{
u16 offset = le16_to_cpu(hdr->header_offset);
}
static inline void *
-rsc_offset(struct rsc_hdr *hdr, struct entry_header *ent)
+rsc_offset(const struct rsc_hdr *hdr, const struct entry_header *ent)
{
u16 offset = le16_to_cpu(hdr->data_offset);
u16 loffset = le16_to_cpu(ent->offset);
}
EXPORT_SYMBOL(cmd_db_ready);
-static int cmd_db_get_header(const char *id, struct entry_header *eh,
- struct rsc_hdr *rh)
+static int cmd_db_get_header(const char *id, const struct entry_header **eh,
+ const struct rsc_hdr **rh)
{
- struct rsc_hdr *rsc_hdr;
- struct entry_header *ent;
+ const struct rsc_hdr *rsc_hdr;
+ const struct entry_header *ent;
int ret, i, j;
u8 query[8];
if (ret)
return ret;
- if (!eh || !rh)
- return -EINVAL;
-
/* Pad out query string to same length as in DB */
strncpy(query, id, sizeof(query));
ent = rsc_to_entry_header(rsc_hdr);
for (j = 0; j < le16_to_cpu(rsc_hdr->cnt); j++, ent++) {
- if (memcmp(ent->id, query, sizeof(ent->id)) == 0)
- break;
- }
-
- if (j < le16_to_cpu(rsc_hdr->cnt)) {
- memcpy(eh, ent, sizeof(*ent));
- memcpy(rh, rsc_hdr, sizeof(*rh));
- return 0;
+ if (memcmp(ent->id, query, sizeof(ent->id)) == 0) {
+ if (eh)
+ *eh = ent;
+ if (rh)
+ *rh = rsc_hdr;
+ return 0;
+ }
}
}
u32 cmd_db_read_addr(const char *id)
{
int ret;
- struct entry_header ent;
- struct rsc_hdr rsc_hdr;
+ const struct entry_header *ent;
- ret = cmd_db_get_header(id, &ent, &rsc_hdr);
+ ret = cmd_db_get_header(id, &ent, NULL);
- return ret < 0 ? 0 : le32_to_cpu(ent.addr);
+ return ret < 0 ? 0 : le32_to_cpu(ent->addr);
}
EXPORT_SYMBOL(cmd_db_read_addr);
int cmd_db_read_aux_data(const char *id, u8 *data, size_t len)
{
int ret;
- struct entry_header ent;
- struct rsc_hdr rsc_hdr;
+ const struct entry_header *ent;
+ const struct rsc_hdr *rsc_hdr;
u16 ent_len;
if (!data)
if (ret)
return ret;
- ent_len = le16_to_cpu(ent.len);
+ ent_len = le16_to_cpu(ent->len);
if (len < ent_len)
return -EINVAL;
len = min_t(u16, ent_len, len);
- memcpy(data, rsc_offset(&rsc_hdr, &ent), len);
+ memcpy(data, rsc_offset(rsc_hdr, ent), len);
return len;
}
size_t cmd_db_read_aux_data_len(const char *id)
{
int ret;
- struct entry_header ent;
- struct rsc_hdr rsc_hdr;
+ const struct entry_header *ent;
- ret = cmd_db_get_header(id, &ent, &rsc_hdr);
+ ret = cmd_db_get_header(id, &ent, NULL);
- return ret < 0 ? 0 : le16_to_cpu(ent.len);
+ return ret < 0 ? 0 : le16_to_cpu(ent->len);
}
EXPORT_SYMBOL(cmd_db_read_aux_data_len);
enum cmd_db_hw_type cmd_db_read_slave_id(const char *id)
{
int ret;
- struct entry_header ent;
- struct rsc_hdr rsc_hdr;
+ const struct entry_header *ent;
u32 addr;
- ret = cmd_db_get_header(id, &ent, &rsc_hdr);
+ ret = cmd_db_get_header(id, &ent, NULL);
if (ret < 0)
return CMD_DB_HW_INVALID;
- addr = le32_to_cpu(ent.addr);
+ addr = le32_to_cpu(ent->addr);
return (addr >> SLAVE_ID_SHIFT) & SLAVE_ID_MASK;
}
EXPORT_SYMBOL(cmd_db_read_slave_id);