From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 04/10] console: Use dev_add_param_string
Date: Mon, 10 Apr 2017 09:14:14 +0200 [thread overview]
Message-ID: <20170410071420.26884-5-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20170410071420.26884-1-s.hauer@pengutronix.de>
dev_add_param_string allows to pass a priv * so that the device_d *
argument is not needed and can be removed later.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/console.c | 50 ++++++++++++++++++++++++--------------------------
include/console.h | 2 +-
2 files changed, 25 insertions(+), 27 deletions(-)
diff --git a/common/console.c b/common/console.c
index 74fb684b2c..1bcb13fa0b 100644
--- a/common/console.c
+++ b/common/console.c
@@ -94,7 +94,7 @@ int console_close(struct console_device *cdev)
int console_set_active(struct console_device *cdev, unsigned flag)
{
- int ret, i;
+ int ret;
if (!cdev->getc)
flag &= ~CONSOLE_STDIN;
@@ -119,18 +119,6 @@ int console_set_active(struct console_device *cdev, unsigned flag)
cdev->f_active = flag;
- if (IS_ENABLED(CONFIG_PARAMETER)) {
- i = 0;
-
- if (flag & CONSOLE_STDIN)
- cdev->active[i++] = 'i';
- if (flag & CONSOLE_STDOUT)
- cdev->active[i++] = 'o';
- if (flag & CONSOLE_STDERR)
- cdev->active[i++] = 'e';
- cdev->active[i] = 0;
- }
-
if (initialized < CONSOLE_INIT_FULL) {
char ch;
initialized = CONSOLE_INIT_FULL;
@@ -150,30 +138,39 @@ unsigned console_get_active(struct console_device *cdev)
return cdev->f_active;
}
-static int console_active_set(struct device_d *dev, struct param_d *param,
- const char *val)
+static int console_active_set(struct param_d *param, void *priv)
{
- struct console_device *cdev = to_console_dev(dev);
+ struct console_device *cdev = priv;
unsigned int flag = 0;
+ int ret;
- if (val) {
- if (strchr(val, 'i'))
+ if (cdev->active_string) {
+ if (strchr(cdev->active_string, 'i'))
flag |= CONSOLE_STDIN;
- if (strchr(val, 'o'))
+ if (strchr(cdev->active_string, 'o'))
flag |= CONSOLE_STDOUT;
- if (strchr(val, 'e'))
+ if (strchr(cdev->active_string, 'e'))
flag |= CONSOLE_STDERR;
}
- return console_set_active(cdev, flag);
+ ret = console_set_active(cdev, flag);
+ if (ret)
+ return ret;
+
+ return 0;
}
-static const char *console_active_get(struct device_d *dev,
- struct param_d *param)
+static int console_active_get(struct param_d *param, void *priv)
{
- struct console_device *cdev = to_console_dev(dev);
+ struct console_device *cdev = priv;
+ unsigned int flag = cdev->f_active;
- return cdev->active;
+ free(cdev->active_string);
+ cdev->active_string = basprintf("%s%s%s",
+ flag & CONSOLE_STDIN ? "i" : "",
+ flag & CONSOLE_STDOUT ? "o" : "",
+ flag & CONSOLE_STDERR ? "e" : "");
+ return 0;
}
int console_set_baudrate(struct console_device *cdev, unsigned baudrate)
@@ -340,7 +337,8 @@ int console_register(struct console_device *newcdev)
newcdev->open_count = 0;
- dev_add_param(dev, "active", console_active_set, console_active_get, 0);
+ dev_add_param_string(dev, "active", console_active_set, console_active_get,
+ &newcdev->active_string, newcdev);
if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_FIRST)) {
if (list_empty(&console_list))
diff --git a/include/console.h b/include/console.h
index 126c2e8aa3..724168e07c 100644
--- a/include/console.h
+++ b/include/console.h
@@ -53,7 +53,7 @@ struct console_device {
struct list_head list;
unsigned char f_active;
- char active[4];
+ char *active_string;
unsigned int open_count;
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2017-04-10 7:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-10 7:14 improve device parameter types Sascha Hauer
2017-04-10 7:14 ` [PATCH 01/10] ARM: socfpga: change param_type struct name Sascha Hauer
2017-04-10 7:14 ` [PATCH 02/10] parameter: Give device parameters types Sascha Hauer
2017-04-10 7:14 ` [PATCH 03/10] lib: implement simple_strtoll Sascha Hauer
2017-04-10 12:44 ` Sam Ravnborg
2017-04-11 6:42 ` Sascha Hauer
2017-04-10 7:14 ` Sascha Hauer [this message]
2017-04-10 7:14 ` [PATCH 05/10] mtd: nand: use dev_add_param_enum Sascha Hauer
2017-04-10 7:14 ` [PATCH 06/10] mtd: use dev_add_param_string Sascha Hauer
2017-04-10 7:14 ` [PATCH 07/10] net: " Sascha Hauer
2017-04-10 7:14 ` [PATCH 08/10] param: make parameter functions more consistent Sascha Hauer
2017-04-10 7:14 ` [PATCH 09/10] globalvar: make globalvar " Sascha Hauer
2017-04-10 7:14 ` [PATCH 10/10] param: remove unnecessary device_d * argument 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=20170410071420.26884-5-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