From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 15/42] state: Convert all bufs to void *
Date: Fri, 31 Mar 2017 09:03:19 +0200 [thread overview]
Message-ID: <20170331070346.26878-16-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20170331070346.26878-1-s.hauer@pengutronix.de>
A void * is a much better type for a buffer than a u8 * as it
can be casted to any other type implicitly. Convert all buffers
used by the state framework to void *.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/state/backend_bucket_cached.c | 6 +++---
common/state/backend_bucket_circular.c | 16 ++++++++--------
common/state/backend_bucket_direct.c | 6 +++---
common/state/backend_format_dtb.c | 6 +++---
common/state/backend_format_raw.c | 10 +++++-----
common/state/backend_storage.c | 6 +++---
common/state/state.c | 4 ++--
common/state/state.h | 16 ++++++++--------
8 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/common/state/backend_bucket_cached.c b/common/state/backend_bucket_cached.c
index 5e7f44c8f8..f8a7785387 100644
--- a/common/state/backend_bucket_cached.c
+++ b/common/state/backend_bucket_cached.c
@@ -20,7 +20,7 @@ struct state_backend_storage_bucket_cache {
struct state_backend_storage_bucket *raw;
- u8 *data;
+ void *data;
ssize_t data_len;
bool force_write;
@@ -61,7 +61,7 @@ static int state_backend_bucket_cache_fill(
}
static int state_backend_bucket_cache_read(struct state_backend_storage_bucket *bucket,
- uint8_t ** buf_out,
+ void ** buf_out,
ssize_t * len_hint)
{
struct state_backend_storage_bucket_cache *cache =
@@ -85,7 +85,7 @@ static int state_backend_bucket_cache_read(struct state_backend_storage_bucket *
}
static int state_backend_bucket_cache_write(struct state_backend_storage_bucket *bucket,
- const uint8_t * buf, ssize_t len)
+ const void * buf, ssize_t len)
{
struct state_backend_storage_bucket_cache *cache =
get_bucket_cache(bucket);
diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c
index 0b8286f9cc..53ee0c3f57 100644
--- a/common/state/backend_bucket_circular.c
+++ b/common/state/backend_bucket_circular.c
@@ -65,7 +65,7 @@ static inline struct state_backend_storage_bucket_circular
#ifdef __BAREBOX__
static int state_mtd_peb_read(struct state_backend_storage_bucket_circular *circ,
- char *buf, int offset, int len)
+ void *buf, int offset, int len)
{
int ret;
@@ -102,7 +102,7 @@ static int state_mtd_peb_read(struct state_backend_storage_bucket_circular *circ
}
static int state_mtd_peb_write(struct state_backend_storage_bucket_circular *circ,
- const char *buf, int offset, int len)
+ const void *buf, int offset, int len)
{
int ret;
@@ -133,7 +133,7 @@ static int state_mtd_peb_erase(struct state_backend_storage_bucket_circular *cir
}
#else
static int state_mtd_peb_read(struct state_backend_storage_bucket_circular *circ,
- char *buf, int suboffset, int len)
+ void *buf, int suboffset, int len)
{
int ret;
off_t offset = suboffset;
@@ -185,7 +185,7 @@ static int state_mtd_peb_read(struct state_backend_storage_bucket_circular *circ
}
static int state_mtd_peb_write(struct state_backend_storage_bucket_circular *circ,
- const char *buf, int suboffset, int len)
+ const void *buf, int suboffset, int len)
{
int ret;
off_t offset = suboffset;
@@ -226,14 +226,14 @@ static int state_mtd_peb_erase(struct state_backend_storage_bucket_circular *cir
#endif
static int state_backend_bucket_circular_read(struct state_backend_storage_bucket *bucket,
- uint8_t ** buf_out,
+ void ** buf_out,
ssize_t * len_out)
{
struct state_backend_storage_bucket_circular *circ =
get_bucket_circular(bucket);
ssize_t read_len;
off_t offset;
- uint8_t *buf;
+ void *buf;
int ret;
/* Storage is empty */
@@ -288,7 +288,7 @@ static int state_backend_bucket_circular_read(struct state_backend_storage_bucke
}
static int state_backend_bucket_circular_write(struct state_backend_storage_bucket *bucket,
- const uint8_t * buf,
+ const void * buf,
ssize_t len)
{
struct state_backend_storage_bucket_circular *circ =
@@ -297,7 +297,7 @@ static int state_backend_bucket_circular_write(struct state_backend_storage_buck
struct state_backend_storage_bucket_circular_meta *meta;
uint32_t written_length = ALIGN(len + sizeof(*meta), circ->writesize);
int ret;
- uint8_t *write_buf;
+ void *write_buf;
if (written_length > circ->max_size) {
dev_err(circ->dev, "Error, state data too big to be written, to write: %zd, writesize: %zd, length: %zd, available: %zd\n",
diff --git a/common/state/backend_bucket_direct.c b/common/state/backend_bucket_direct.c
index 06a5433c45..246cb499c4 100644
--- a/common/state/backend_bucket_direct.c
+++ b/common/state/backend_bucket_direct.c
@@ -46,14 +46,14 @@ static inline struct state_backend_storage_bucket_direct
}
static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
- *bucket, uint8_t ** buf_out,
+ *bucket, void ** buf_out,
ssize_t * len_out)
{
struct state_backend_storage_bucket_direct *direct =
get_bucket_direct(bucket);
struct state_backend_storage_bucket_direct_meta meta;
ssize_t read_len;
- uint8_t *buf;
+ void *buf;
int ret;
ret = lseek(direct->fd, direct->offset, SEEK_SET);
@@ -95,7 +95,7 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
}
static int state_backend_bucket_direct_write(struct state_backend_storage_bucket
- *bucket, const uint8_t * buf,
+ *bucket, const void * buf,
ssize_t len)
{
struct state_backend_storage_bucket_direct *direct =
diff --git a/common/state/backend_format_dtb.c b/common/state/backend_format_dtb.c
index abf8921dc4..d7b01729bc 100644
--- a/common/state/backend_format_dtb.c
+++ b/common/state/backend_format_dtb.c
@@ -39,7 +39,7 @@ static inline struct state_backend_format_dtb *get_format_dtb(struct
}
static int state_backend_format_dtb_verify(struct state_backend_format *format,
- uint32_t magic, const uint8_t * buf,
+ uint32_t magic, const void * buf,
ssize_t *lenp)
{
struct state_backend_format_dtb *fdtb = get_format_dtb(format);
@@ -75,7 +75,7 @@ static int state_backend_format_dtb_verify(struct state_backend_format *format,
static int state_backend_format_dtb_unpack(struct state_backend_format *format,
struct state *state,
- const uint8_t * buf, ssize_t len)
+ const void * buf, ssize_t len)
{
struct state_backend_format_dtb *fdtb = get_format_dtb(format);
int ret;
@@ -92,7 +92,7 @@ static int state_backend_format_dtb_unpack(struct state_backend_format *format,
}
static int state_backend_format_dtb_pack(struct state_backend_format *format,
- struct state *state, uint8_t ** buf,
+ struct state *state, void ** buf,
ssize_t * len)
{
struct state_backend_format_dtb *fdtb = get_format_dtb(format);
diff --git a/common/state/backend_format_raw.c b/common/state/backend_format_raw.c
index 3c8956f8ef..a425b636d0 100644
--- a/common/state/backend_format_raw.c
+++ b/common/state/backend_format_raw.c
@@ -54,14 +54,14 @@ static inline struct state_backend_format_raw *get_format_raw(
}
static int backend_format_raw_verify(struct state_backend_format *format,
- uint32_t magic, const uint8_t * buf,
+ uint32_t magic, const void * buf,
ssize_t *lenp)
{
uint32_t crc;
struct backend_raw_header *header;
int d_len = 0;
int ret;
- const uint8_t *data;
+ const void *data;
ssize_t len = *lenp;
struct state_backend_format_raw *backend_raw = get_format_raw(format);
ssize_t complete_len;
@@ -139,12 +139,12 @@ static int backend_format_raw_verify(struct state_backend_format *format,
}
static int backend_format_raw_unpack(struct state_backend_format *format,
- struct state *state, const uint8_t * buf,
+ struct state *state, const void * buf,
ssize_t len)
{
struct state_variable *sv;
const struct backend_raw_header *header;
- const uint8_t *data;
+ const void *data;
struct state_backend_format_raw *backend_raw = get_format_raw(format);
header = (const struct backend_raw_header *)buf;
@@ -163,7 +163,7 @@ static int backend_format_raw_unpack(struct state_backend_format *format,
}
static int backend_format_raw_pack(struct state_backend_format *format,
- struct state *state, uint8_t ** buf_out,
+ struct state *state, void ** buf_out,
ssize_t * len_out)
{
struct state_backend_format_raw *backend_raw = get_format_raw(format);
diff --git a/common/state/backend_storage.c b/common/state/backend_storage.c
index f1b3f5a6b2..6ec58a0c97 100644
--- a/common/state/backend_storage.c
+++ b/common/state/backend_storage.c
@@ -42,7 +42,7 @@ const unsigned int min_copies_written = 1;
* error.
*/
int state_storage_write(struct state_backend_storage *storage,
- const uint8_t * buf, ssize_t len)
+ const void * buf, ssize_t len)
{
struct state_backend_storage_bucket *bucket;
int ret;
@@ -82,7 +82,7 @@ int state_storage_write(struct state_backend_storage *storage,
* low, can read their own copy first and compare it.
*/
int state_storage_restore_consistency(struct state_backend_storage *storage,
- const uint8_t * buf, ssize_t len)
+ const void * buf, ssize_t len)
{
return state_storage_write(storage, buf, len);
}
@@ -105,7 +105,7 @@ int state_storage_restore_consistency(struct state_backend_storage *storage,
*/
int state_storage_read(struct state_backend_storage *storage,
struct state_backend_format *format,
- uint32_t magic, uint8_t ** buf, ssize_t * len)
+ uint32_t magic, void **buf, ssize_t *len)
{
struct state_backend_storage_bucket *bucket;
int ret;
diff --git a/common/state/state.c b/common/state/state.c
index 8d2dca2523..476e3ee08e 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -41,7 +41,7 @@ static LIST_HEAD(state_list);
*/
int state_save(struct state *state)
{
- uint8_t *buf;
+ void *buf;
ssize_t len;
int ret;
@@ -80,7 +80,7 @@ out:
*/
int state_load(struct state *state)
{
- uint8_t *buf;
+ void *buf;
ssize_t len;
int ret;
diff --git a/common/state/state.h b/common/state/state.h
index 0b1a7e5ec2..52d332e27d 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -21,9 +21,9 @@ struct mtd_info_user;
*/
struct state_backend_storage_bucket {
int (*write) (struct state_backend_storage_bucket * bucket,
- const uint8_t * buf, ssize_t len);
+ const void * buf, ssize_t len);
int (*read) (struct state_backend_storage_bucket * bucket,
- uint8_t ** buf, ssize_t * len_hint);
+ void ** buf, ssize_t * len_hint);
void (*free) (struct state_backend_storage_bucket * bucket);
struct list_head bucket_list;
@@ -46,11 +46,11 @@ struct state_backend_storage_bucket {
*/
struct state_backend_format {
int (*verify) (struct state_backend_format * format, uint32_t magic,
- const uint8_t * buf, ssize_t *lenp);
+ const void * buf, ssize_t *lenp);
int (*pack) (struct state_backend_format * format, struct state * state,
- uint8_t ** buf, ssize_t * len);
+ void ** buf, ssize_t * len);
int (*unpack) (struct state_backend_format * format,
- struct state * state, const uint8_t * buf, ssize_t len);
+ struct state * state, const void * buf, ssize_t len);
void (*free) (struct state_backend_format * format);
const char *name;
};
@@ -207,13 +207,13 @@ int state_backend_bucket_direct_create(struct device_d *dev, const char *path,
struct state_backend_storage_bucket **bucket,
off_t offset, ssize_t max_size);
int state_storage_write(struct state_backend_storage *storage,
- const uint8_t * buf, ssize_t len);
+ const void * buf, ssize_t len);
int state_storage_restore_consistency(struct state_backend_storage
- *storage, const uint8_t * buf,
+ *storage, const void * buf,
ssize_t len);
int state_storage_read(struct state_backend_storage *storage,
struct state_backend_format *format,
- uint32_t magic, uint8_t **buf, ssize_t *len);
+ uint32_t magic, void **buf, ssize_t *len);
static inline struct state_uint32 *to_state_uint32(struct state_variable *s)
{
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2017-03-31 7:04 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-31 7:03 State patches Sascha Hauer
2017-03-31 7:03 ` [PATCH 01/42] state: Make pointing to the backend using a phandle the only supported method Sascha Hauer
2017-05-15 9:18 ` Jan Remmet
2017-05-15 10:14 ` Jan Remmet
2017-05-16 5:33 ` Sascha Hauer
2017-05-17 9:13 ` Jan Remmet
2017-03-31 7:03 ` [PATCH 02/42] state: Use positive logic Sascha Hauer
2017-03-31 7:03 ` [PATCH 03/42] state: backend: remove .get_packed_len Sascha Hauer
2017-03-31 7:03 ` [PATCH 04/42] state: backend: remove len_hint argument from state_storage_read Sascha Hauer
2017-03-31 7:03 ` [PATCH 05/42] state: Drop backend as extra struct type Sascha Hauer
2017-03-31 7:03 ` [PATCH 06/42] state: merge backend.c into state.c Sascha Hauer
2017-03-31 7:03 ` [PATCH 07/42] state: open code state_backend_init in caller Sascha Hauer
2017-03-31 7:03 ` [PATCH 08/42] state: remove unnecessary argument from state_format_init Sascha Hauer
2017-03-31 7:03 ` [PATCH 09/42] state: pass struct state * to storage functions Sascha Hauer
2017-03-31 7:03 ` [PATCH 10/42] state: storage: initialize variable once outside loop Sascha Hauer
2017-03-31 7:03 ` [PATCH 11/42] state: backend_circular: Read whole PEB Sascha Hauer
2017-04-15 8:40 ` Sam Ravnborg
2017-03-31 7:03 ` [PATCH 12/42] state: drop lazy_init Sascha Hauer
2017-03-31 7:03 ` [PATCH 13/42] state: simplify direct backend Sascha Hauer
2017-03-31 7:03 ` [PATCH 14/42] state: replace len_hint logic Sascha Hauer
2017-03-31 7:03 ` Sascha Hauer [this message]
2017-03-31 7:03 ` [PATCH 16/42] state: Drop cache bucket Sascha Hauer
2017-04-15 8:53 ` Sam Ravnborg
2017-04-19 8:22 ` Sascha Hauer
2017-03-31 7:03 ` [PATCH 17/42] state: backend-direct: Fix max_size Sascha Hauer
2017-03-31 7:03 ` [PATCH 18/42] state: bucket: Make output more informative Sascha Hauer
2017-03-31 7:03 ` [PATCH 19/42] state: backend_bucket_direct: max_size is always given Sascha Hauer
2017-03-31 7:03 ` [PATCH 20/42] state: backend: Add more fields to struct state_backend_storage Sascha Hauer
2017-03-31 7:03 ` [PATCH 21/42] state: backend_circular: remove unnecessary warning Sascha Hauer
2017-03-31 7:03 ` [PATCH 22/42] state: storage: direct: do not close file that is not opened Sascha Hauer
2017-03-31 7:03 ` [PATCH 23/42] state: backend: Add some documentation Sascha Hauer
2017-03-31 7:03 ` [PATCH 24/42] state: backend_circular: default to circular storage Sascha Hauer
2017-03-31 7:03 ` [PATCH 25/42] state: backend_circular: rewrite function doc Sascha Hauer
2017-03-31 7:03 ` [PATCH 26/42] state: backend_storage: Rename variable nr_copies to n_buckets Sascha Hauer
2017-03-31 7:03 ` [PATCH 27/42] state: backend_storage: Rename variable desired_copies to desired_buckets Sascha Hauer
2017-03-31 7:03 ` [PATCH 28/42] state: backend_storage: rewrite function doc Sascha Hauer
2017-03-31 7:03 ` [PATCH 29/42] state: backend_storage: make locally used variable static Sascha Hauer
2017-03-31 7:03 ` [PATCH 30/42] state: backend_storage: rename more variables Sascha Hauer
2017-03-31 7:03 ` [PATCH 31/42] keystore: implement forgetting secrets Sascha Hauer
2017-03-31 7:03 ` [PATCH 32/42] commands: implement keystore command Sascha Hauer
2017-03-31 7:03 ` [PATCH 33/42] commands: state: allow loading state with -l Sascha Hauer
2017-03-31 7:03 ` [PATCH 34/42] crypto: digest: initialize earlier Sascha Hauer
2017-03-31 7:03 ` [PATCH 35/42] state: backend_raw: alloc digest only when needed Sascha Hauer
2017-03-31 7:03 ` [PATCH 36/42] state: backend_circular: Set minumum writesize to 8 Sascha Hauer
2017-03-31 7:03 ` [PATCH 37/42] state: backend bucket circular: Explain metadata Sascha Hauer
2017-03-31 7:03 ` [PATCH 38/42] state: Allow to load without authentification Sascha Hauer
2017-03-31 7:03 ` [PATCH 39/42] state: Update documentation Sascha Hauer
2017-03-31 7:03 ` [PATCH 40/42] state: Do not load state during state_new_from_node Sascha Hauer
2017-03-31 7:03 ` [PATCH 41/42] state: Remove -EUCLEAN check from userspace tool Sascha Hauer
2017-03-31 7:03 ` [PATCH 42/42] state: find device node from device path, not from device node path Sascha Hauer
2017-04-03 20:15 ` State patches Sam Ravnborg
2017-04-04 6:19 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170331070346.26878-16-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox