From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] globalvar: allow running actions on set with globalvar_add_bool()
Date: Wed, 16 Sep 2020 15:54:09 +0200 [thread overview]
Message-ID: <20200916135409.24896-1-a.fatoum@pengutronix.de> (raw)
globalvar_add_simple_bool() and the other family of globalvars don't allow
running a callback when the variable is set. This is a useful thing
to have however for things like global.usbgadget.autostart=1.
Provide a globalvar_add_bool() that accommodates this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/globalvar.c | 8 +++++---
include/globalvar.h | 14 +++++++++++---
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/common/globalvar.c b/common/globalvar.c
index 83f61366a201..5bde86aad08a 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -569,7 +569,9 @@ int globalvar_add_simple_int(const char *name, int *value,
return 0;
}
-int globalvar_add_simple_bool(const char *name, int *value)
+int globalvar_add_bool(const char *name,
+ int (*set)(struct param_d *, void *),
+ int *value, void *priv)
{
struct param_d *p;
int ret;
@@ -578,8 +580,8 @@ int globalvar_add_simple_bool(const char *name, int *value)
if (ret)
return ret;
- p = dev_add_param_bool(&global_device, name, NULL, NULL,
- value, NULL);
+ p = dev_add_param_bool(&global_device, name, set, NULL,
+ value, priv);
if (IS_ERR(p))
return PTR_ERR(p);
diff --git a/include/globalvar.h b/include/globalvar.h
index d798fa815c5a..84bee9102cf3 100644
--- a/include/globalvar.h
+++ b/include/globalvar.h
@@ -20,7 +20,9 @@ void globalvar_set(const char *name, const char *val);
int globalvar_add_simple_string(const char *name, char **value);
int globalvar_add_simple_int(const char *name, int *value,
const char *format);
-int globalvar_add_simple_bool(const char *name, int *value);
+int globalvar_add_bool(const char *name,
+ int (*set)(struct param_d *, void *),
+ int *value, void *priv);
int globalvar_add_simple_enum(const char *name, int *value,
const char * const *names, int max);
int globalvar_add_simple_bitmask(const char *name, unsigned long *value,
@@ -53,8 +55,9 @@ static inline int globalvar_add_simple_int(const char *name,
return 0;
}
-static inline int globalvar_add_simple_bool(const char *name,
- int *value)
+static inline int globalvar_add_bool(const char *name,
+ int (*set)(struct param_d *, void *),
+ int *value, void *priv)
{
return 0;
}
@@ -127,4 +130,9 @@ int nvvar_save(void);
int nv_complete(struct string_list *sl, char *instr);
int global_complete(struct string_list *sl, char *instr);
+static inline int globalvar_add_simple_bool(const char *name, int *value)
+{
+ return globalvar_add_bool(name, NULL, value, NULL);
+}
+
#endif /* __GLOBALVAR_H */
--
2.28.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2020-09-16 13:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-16 13:54 Ahmad Fatoum [this message]
2020-09-18 9:44 ` 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=20200916135409.24896-1-a.fatoum@pengutronix.de \
--to=a.fatoum@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