settings: use CONTAINER_OF() to access backend structure

Use CONTAINER_OF() macro to access outer backend-specific structure. This
removes the requirement to keep `struct settings_store` as the first item
in outer structure.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
This commit is contained in:
Marcin Niestroj 2022-11-22 23:27:53 +01:00 committed by Carles Cufí
commit 26ea31fc87
3 changed files with 9 additions and 9 deletions

View file

@ -150,7 +150,7 @@ static int settings_fcb_load_priv(struct settings_store *cs,
void *cb_arg, void *cb_arg,
bool filter_duplicates) bool filter_duplicates)
{ {
struct settings_fcb *cf = (struct settings_fcb *)cs; struct settings_fcb *cf = CONTAINER_OF(cs, struct settings_fcb, cf_store);
struct fcb_entry_ctx entry_ctx = { struct fcb_entry_ctx entry_ctx = {
{.fe_sector = NULL, .fe_elem_off = 0}, {.fe_sector = NULL, .fe_elem_off = 0},
.fap = cf->cf_fcb.fap .fap = cf->cf_fcb.fap
@ -326,7 +326,7 @@ static int write_handler(void *ctx, off_t off, char const *buf, size_t len)
static int settings_fcb_save_priv(struct settings_store *cs, const char *name, static int settings_fcb_save_priv(struct settings_store *cs, const char *name,
const char *value, size_t val_len) const char *value, size_t val_len)
{ {
struct settings_fcb *cf = (struct settings_fcb *)cs; struct settings_fcb *cf = CONTAINER_OF(cs, struct settings_fcb, cf_store);
struct fcb_entry_ctx loc; struct fcb_entry_ctx loc;
int len; int len;
int rc = -EINVAL; int rc = -EINVAL;
@ -457,7 +457,7 @@ int settings_backend_init(void)
static void *settings_fcb_storage_get(struct settings_store *cs) static void *settings_fcb_storage_get(struct settings_store *cs)
{ {
struct settings_fcb *cf = (struct settings_fcb *)cs; struct settings_fcb *cf = CONTAINER_OF(cs, struct settings_fcb, cf_store);
return &cf->cf_fcb; return &cf->cf_fcb;
} }

View file

@ -122,7 +122,7 @@ static int read_entry_len(const struct line_entry_ctx *entry_ctx, off_t off)
static int settings_file_load_priv(struct settings_store *cs, line_load_cb cb, static int settings_file_load_priv(struct settings_store *cs, line_load_cb cb,
void *cb_arg, bool filter_duplicates) void *cb_arg, bool filter_duplicates)
{ {
struct settings_file *cf = (struct settings_file *)cs; struct settings_file *cf = CONTAINER_OF(cs, struct settings_file, cf_store);
struct fs_file_t file; struct fs_file_t file;
int lines; int lines;
int rc; int rc;
@ -375,7 +375,7 @@ end_rolback:
static int settings_file_save_priv(struct settings_store *cs, const char *name, static int settings_file_save_priv(struct settings_store *cs, const char *name,
const char *value, size_t val_len) const char *value, size_t val_len)
{ {
struct settings_file *cf = (struct settings_file *)cs; struct settings_file *cf = CONTAINER_OF(cs, struct settings_file, cf_store);
struct line_entry_ctx entry_ctx; struct line_entry_ctx entry_ctx;
struct fs_file_t file; struct fs_file_t file;
int rc2; int rc2;
@ -550,7 +550,7 @@ int settings_backend_init(void)
static void *settings_file_storage_get(struct settings_store *cs) static void *settings_file_storage_get(struct settings_store *cs)
{ {
struct settings_file *cf = (struct settings_file *)cs; struct settings_file *cf = CONTAINER_OF(cs, struct settings_file, cf_store);
return (void *)cf->cf_name; return (void *)cf->cf_name;
} }

View file

@ -122,7 +122,7 @@ static int settings_nvs_load(struct settings_store *cs,
const struct settings_load_arg *arg) const struct settings_load_arg *arg)
{ {
int ret = 0; int ret = 0;
struct settings_nvs *cf = (struct settings_nvs *)cs; struct settings_nvs *cf = CONTAINER_OF(cs, struct settings_nvs, cf_store);
struct settings_nvs_read_fn_arg read_fn_arg; struct settings_nvs_read_fn_arg read_fn_arg;
char name[SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1]; char name[SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1];
char buf; char buf;
@ -189,7 +189,7 @@ static int settings_nvs_load(struct settings_store *cs,
static int settings_nvs_save(struct settings_store *cs, const char *name, static int settings_nvs_save(struct settings_store *cs, const char *name,
const char *value, size_t val_len) const char *value, size_t val_len)
{ {
struct settings_nvs *cf = (struct settings_nvs *)cs; struct settings_nvs *cf = CONTAINER_OF(cs, struct settings_nvs, cf_store);
char rdname[SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1]; char rdname[SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN + 1];
uint16_t name_id, write_name_id; uint16_t name_id, write_name_id;
bool delete, write_name; bool delete, write_name;
@ -404,7 +404,7 @@ int settings_backend_init(void)
static void *settings_nvs_storage_get(struct settings_store *cs) static void *settings_nvs_storage_get(struct settings_store *cs)
{ {
struct settings_nvs *cf = (struct settings_nvs *)cs; struct settings_nvs *cf = CONTAINER_OF(cs, struct settings_nvs, cf_store);
return &cf->cf_nvs; return &cf->cf_nvs;
} }