From c090e8f2367f1c532bf30935104eccdada9d013d Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Thu, 11 Feb 2021 17:09:34 +0200 Subject: stdio: Get rid of dead code, i.e. stdio_deregister() Nobody is using stdio_deregister(), remove for good. Note, even its parameters are not consistent with stdio_register(). So, if anyone want to introduce this again, better with some consistency. Signed-off-by: Andy Shevchenko --- common/stdio.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'common/stdio.c') diff --git a/common/stdio.c b/common/stdio.c index 2b883fddbea..acc65ada1b1 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -261,17 +261,6 @@ int stdio_deregister_dev(struct stdio_dev *dev, int force) return 0; } -int stdio_deregister(const char *devname, int force) -{ - struct stdio_dev *dev; - - dev = stdio_get_by_name(devname); - if (!dev) /* device not found */ - return -ENODEV; - - return stdio_deregister_dev(dev, force); -} - int stdio_init_tables(void) { #if defined(CONFIG_NEEDS_MANUAL_RELOC) -- cgit v1.2.3 From 99cb2b996bd649d98069a95941beaaade0a4447a Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Thu, 11 Feb 2021 17:09:35 +0200 Subject: stdio: Split out nulldev_register() and move it under #if It's possible that NULLDEV can be disabled while it makes leftovers, move entire device under #if. Signed-off-by: Andy Shevchenko --- common/stdio.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'common/stdio.c') diff --git a/common/stdio.c b/common/stdio.c index acc65ada1b1..61fc0873684 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -28,6 +28,7 @@ static struct stdio_dev devs; struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL }; char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; +#if CONFIG_IS_ENABLED(SYS_DEVICE_NULLDEV) static void nulldev_putc(struct stdio_dev *dev, const char c) { /* nulldev is empty! */ @@ -44,6 +45,25 @@ static int nulldev_input(struct stdio_dev *dev) return 0; } +static void nulldev_register(void) +{ + struct stdio_dev dev; + + memset(&dev, '\0', sizeof(dev)); + + strcpy(dev.name, "nulldev"); + dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT; + dev.putc = nulldev_putc; + dev.puts = nulldev_puts; + dev.getc = nulldev_input; + dev.tstc = nulldev_input; + + stdio_register(&dev); +} +#else +static inline void nulldev_register(void) {} +#endif /* SYS_DEVICE_NULLDEV */ + static void stdio_serial_putc(struct stdio_dev *dev, const char c) { serial_putc(c); @@ -83,18 +103,7 @@ static void drv_system_init (void) dev.tstc = stdio_serial_tstc; stdio_register (&dev); - if (CONFIG_IS_ENABLED(SYS_DEVICE_NULLDEV)) { - memset(&dev, '\0', sizeof(dev)); - - strcpy(dev.name, "nulldev"); - dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT; - dev.putc = nulldev_putc; - dev.puts = nulldev_puts; - dev.getc = nulldev_input; - dev.tstc = nulldev_input; - - stdio_register(&dev); - } + nulldev_register(); } /************************************************************************** -- cgit v1.2.3 From d9b0ac90baf499d215462ed7afffbfd22a58340b Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Thu, 11 Feb 2021 17:09:36 +0200 Subject: stdio: Introduce a new helper stdio_file_to_flags() Let's deduplicate existing copies by splitting off to a new helper. Signed-off-by: Andy Shevchenko --- common/stdio.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'common/stdio.c') diff --git a/common/stdio.c b/common/stdio.c index 61fc0873684..d4acc5256c1 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -28,6 +28,19 @@ static struct stdio_dev devs; struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL }; char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; +int stdio_file_to_flags(const int file) +{ + switch (file) { + case stdin: + return DEV_FLAGS_INPUT; + case stdout: + case stderr: + return DEV_FLAGS_OUTPUT; + default: + return -EINVAL; + } +} + #if CONFIG_IS_ENABLED(SYS_DEVICE_NULLDEV) static void nulldev_putc(struct stdio_dev *dev, const char c) { -- cgit v1.2.3