summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-01-29 20:37:04 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2018-01-30 08:33:54 +0100
commitb5526c403c41ffa70a917df3841cd5e77b23d1f3 (patch)
tree608cba584e6b0fa4292fbb0bb98c91145581d2f2 /common
parent83ff71fcee4daabfd74ff31e5612f74c4996ec5c (diff)
downloadbarebox-b5526c403c41ffa70a917df3841cd5e77b23d1f3.tar.gz
barebox-b5526c403c41ffa70a917df3841cd5e77b23d1f3.tar.xz
imd: Make all pointers into image const
The IMD code should be readonly and never modify any pointers. Make all pointers const so that const pointers can be passed in to IMD. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/bbu.c4
-rw-r--r--common/imd.c27
2 files changed, 16 insertions, 15 deletions
diff --git a/common/bbu.c b/common/bbu.c
index 3b372263b1..11e44f4a7d 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -159,7 +159,7 @@ static int bbu_check_of_compat(struct bbu_data *data)
struct device_node *root_node;
const char *machine, *str;
int ret;
- struct imd_header *of_compat;
+ const struct imd_header *of_compat;
if (!IS_ENABLED(CONFIG_OFDEVICE) || !IS_ENABLED(CONFIG_IMD))
return 0;
@@ -191,7 +191,7 @@ static int bbu_check_of_compat(struct bbu_data *data)
static int bbu_check_metadata(struct bbu_data *data)
{
- struct imd_header *imd;
+ const struct imd_header *imd;
int ret;
char *str;
diff --git a/common/imd.c b/common/imd.c
index a8a10fc9bb..05e118e773 100644
--- a/common/imd.c
+++ b/common/imd.c
@@ -35,7 +35,7 @@ int imd_command_setenv(const char *variable_name, const char *value)
* imd_next - return a pointer to the next metadata field.
* @imd The current metadata field
*/
-struct imd_header *imd_next(struct imd_header *imd)
+const struct imd_header *imd_next(const struct imd_header *imd)
{
int length;
@@ -43,10 +43,11 @@ struct imd_header *imd_next(struct imd_header *imd)
length = ALIGN(length, 4);
length += 8;
- return (void *)imd + length;
+ return (const void *)imd + length;
}
-struct imd_header *imd_find_type(struct imd_header *imd, uint32_t type)
+const struct imd_header *imd_find_type(const struct imd_header *imd,
+ uint32_t type)
{
imd_for_each(imd, imd)
if (imd_read_type(imd) == type)
@@ -55,10 +56,10 @@ struct imd_header *imd_find_type(struct imd_header *imd, uint32_t type)
return NULL;
}
-static int imd_next_validate(void *buf, int bufsize, int start_ofs)
+static int imd_next_validate(const void *buf, int bufsize, int start_ofs)
{
int length, size;
- struct imd_header *imd = buf + start_ofs;
+ const struct imd_header *imd = buf + start_ofs;
size = bufsize - start_ofs;
@@ -82,10 +83,10 @@ static int imd_next_validate(void *buf, int bufsize, int start_ofs)
return length;
}
-static int imd_validate_tags(void *buf, int bufsize, int start_ofs)
+static int imd_validate_tags(const void *buf, int bufsize, int start_ofs)
{
int ret;
- struct imd_header *imd = buf + start_ofs;
+ const struct imd_header *imd = buf + start_ofs;
while (1) {
uint32_t type;
@@ -122,7 +123,7 @@ static int imd_validate_tags(void *buf, int bufsize, int start_ofs)
*
* Return: a pointer to the image metadata or a ERR_PTR
*/
-struct imd_header *imd_get(void *buf, int size)
+const struct imd_header *imd_get(const void *buf, int size)
{
int start_ofs = 0;
int i, ret;
@@ -206,7 +207,7 @@ static uint32_t imd_name_to_type(const char *name)
*
* Return: A pointer to the string or NULL if the string is not found
*/
-const char *imd_string_data(struct imd_header *imd, int index)
+const char *imd_string_data(const struct imd_header *imd, int index)
{
int i, total = 0, l = 0;
int len = imd_read_length(imd);
@@ -233,7 +234,7 @@ const char *imd_string_data(struct imd_header *imd, int index)
*
* Return: A pointer to the string or NULL if the string is not found
*/
-char *imd_concat_strings(struct imd_header *imd)
+char *imd_concat_strings(const struct imd_header *imd)
{
int i, len = imd_read_length(imd);
char *str;
@@ -266,9 +267,9 @@ char *imd_concat_strings(struct imd_header *imd)
*
* Return: A pointer to the value or NULL if the string is not found
*/
-const char *imd_get_param(struct imd_header *imd, const char *name)
+const char *imd_get_param(const struct imd_header *imd, const char *name)
{
- struct imd_header *cur;
+ const struct imd_header *cur;
int namelen = strlen(name);
imd_for_each(imd, cur) {
@@ -294,7 +295,7 @@ int imd_command(int argc, char *argv[])
void *buf;
size_t size;
uint32_t type = IMD_TYPE_INVALID;
- struct imd_header *imd_start, *imd;
+ const struct imd_header *imd_start, *imd;
const char *filename;
const char *variable_name = NULL;
char *str;