soc: qcom: cmd-db: Stop memcpy()ing in cmd_db_read_aux_data()
Let's change the function signature to return the pointer to memory or an error pointer on failure, and take an argument that lets us return the size of the aux data read. This way we can remove the cmd_db_read_aux_data_len() API entirely and also get rid of the memcpy operation from cmd_db to the caller. Updating the only user of this code shows that making this change allows us to remove a function and put the lookup where the user is. Cc: Mahesh Sivasubramanian <msivasub@codeaurora.org> Cc: Lina Iyer <ilina@codeaurora.org> Cc: Bjorn Andersson <bjorn.andersson@linaro.org> Cc: Evan Green <evgreen@chromium.org> Cc: Jordan Crouse <jcrouse@codeaurora.org> Cc: Rob Clark <robdclark@gmail.com> Signed-off-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Andy Gross <andy.gross@linaro.org>
This commit is contained in:
@@ -192,55 +192,28 @@ EXPORT_SYMBOL(cmd_db_read_addr);
|
||||
/**
|
||||
* cmd_db_read_aux_data() - Query command db for aux data.
|
||||
*
|
||||
* @id: Resource to retrieve AUX Data on.
|
||||
* @data: Data buffer to copy returned aux data to. Returns size on NULL
|
||||
* @len: Caller provides size of data buffer passed in.
|
||||
* @id: Resource to retrieve AUX Data on
|
||||
* @len: size of data buffer returned
|
||||
*
|
||||
* Return: size of data on success, errno otherwise
|
||||
* Return: pointer to data on success, error pointer otherwise
|
||||
*/
|
||||
int cmd_db_read_aux_data(const char *id, u8 *data, size_t len)
|
||||
const void *cmd_db_read_aux_data(const char *id, size_t *len)
|
||||
{
|
||||
int ret;
|
||||
const struct entry_header *ent;
|
||||
const struct rsc_hdr *rsc_hdr;
|
||||
u16 ent_len;
|
||||
|
||||
if (!data)
|
||||
return -EINVAL;
|
||||
|
||||
ret = cmd_db_get_header(id, &ent, &rsc_hdr);
|
||||
if (ret)
|
||||
return ret;
|
||||
return ERR_PTR(ret);
|
||||
|
||||
ent_len = le16_to_cpu(ent->len);
|
||||
if (len < ent_len)
|
||||
return -EINVAL;
|
||||
if (len)
|
||||
*len = le16_to_cpu(ent->len);
|
||||
|
||||
len = min_t(u16, ent_len, len);
|
||||
memcpy(data, rsc_offset(rsc_hdr, ent), len);
|
||||
|
||||
return len;
|
||||
return rsc_offset(rsc_hdr, ent);
|
||||
}
|
||||
EXPORT_SYMBOL(cmd_db_read_aux_data);
|
||||
|
||||
/**
|
||||
* cmd_db_read_aux_data_len - Get the length of the auxiliary data stored in DB.
|
||||
*
|
||||
* @id: Resource to retrieve AUX Data.
|
||||
*
|
||||
* Return: size on success, 0 on error
|
||||
*/
|
||||
size_t cmd_db_read_aux_data_len(const char *id)
|
||||
{
|
||||
int ret;
|
||||
const struct entry_header *ent;
|
||||
|
||||
ret = cmd_db_get_header(id, &ent, NULL);
|
||||
|
||||
return ret < 0 ? 0 : le16_to_cpu(ent->len);
|
||||
}
|
||||
EXPORT_SYMBOL(cmd_db_read_aux_data_len);
|
||||
|
||||
/**
|
||||
* cmd_db_read_slave_id - Get the slave ID for a given resource address
|
||||
*
|
||||
|
Reference in New Issue
Block a user