public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Andreas Bießmann" <andreas.devel@googlemail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/6] stdio: dm: Make stdio_devices[] local
Date: Sun, 02 Sep 2012 01:11:43 +0200	[thread overview]
Message-ID: <5042962F.4060706@googlemail.com> (raw)
In-Reply-To: <1346453055-30888-4-git-send-email-marex@denx.de>

Dear Marek Vasut,

On 01.09.12 00:44, Marek Vasut wrote:
> Use stdio_get_fd() and stdio_set_fd() instead of direct access
> to the array. This allows making stdio_devices[] local to stdio.c
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Wolfgang Denk <wd@denx.de>
> ---
>  common/cmd_console.c  |    8 +++----
>  common/cmd_terminal.c |    9 ++++++--
>  common/console.c      |   60 ++++++++++++++++++++++++++++++++-----------------
>  common/fdt_support.c  |    8 ++++++-
>  common/stdio.c        |    2 +-
>  include/stdio_dev.h   |    1 -
>  6 files changed, 58 insertions(+), 30 deletions(-)
> 
> diff --git a/common/cmd_console.c b/common/cmd_console.c
> index d8cad6b..343bc28 100644
> --- a/common/cmd_console.c
> +++ b/common/cmd_console.c
> @@ -34,7 +34,7 @@ int do_coninfo (cmd_tbl_t * cmd, int flag, int argc, char * const argv[])
>  	int l;
>  	struct list_head *list = stdio_get_list();
>  	struct list_head *pos;
> -	struct stdio_dev *dev;
> +	struct stdio_dev *dev, *sio;
>  
>  	/* Scan for valid output and input devices */
>  
> @@ -51,9 +51,9 @@ int do_coninfo (cmd_tbl_t * cmd, int flag, int argc, char * const argv[])
>  			(dev->flags & DEV_FLAGS_OUTPUT) ? 'O' : '.');
>  
>  		for (l = 0; l < MAX_FILES; l++) {
> -			if (stdio_devices[l] == dev) {
> -				printf ("%s ", stdio_names[l]);
> -			}
> +			sio = stdio_get_fd(l);
> +			if (sio == dev)
> +				printf("%s ", stdio_names[l]);
>  		}
>  		putc ('\n');
>  	}
> diff --git a/common/cmd_terminal.c b/common/cmd_terminal.c
> index 7cc1a6c..ba34033 100644
> --- a/common/cmd_terminal.c
> +++ b/common/cmd_terminal.c
> @@ -33,6 +33,7 @@ int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char * const argv[])
>  {
>  	int last_tilde = 0;
>  	struct stdio_dev *dev = NULL;
> +	struct stdio_dev *sio;
>  
>  	if (argc < 1)
>  		return -1;
> @@ -46,12 +47,16 @@ int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char * const argv[])
>  	printf("Entering terminal mode for port %s\n", dev->name);
>  	puts("Use '~.' to leave the terminal and get back to u-boot\n");
>  
> +	sio = stdio_get_dev(stdin);
> +	if (!sio)
> +		return -1;
> +
>  	while (1) {
>  		int c;
>  
>  		/* read from console and display on serial port */
> -		if (stdio_devices[0]->tstc()) {
> -			c = stdio_devices[0]->getc();
> +		if (sio->tstc()) {
> +			c = sio->getc();
>  			if (last_tilde == 1) {
>  				if (c == '.') {
>  					putc(c);
> diff --git a/common/console.c b/common/console.c
> index df03cef..4a1938a 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -64,7 +64,7 @@ static int console_setfile(int file, struct stdio_dev * dev)
>  		}
>  
>  		/* Assign the new device (leaving the existing one started) */
> -		stdio_devices[file] = dev;
> +		stdio_set_fd(file, dev);
>  
>  		/*
>  		 * Update monitor functions
> @@ -170,27 +170,39 @@ static inline void console_doenv(int file, struct stdio_dev *dev)
>  #else
>  static inline int console_getc(int file)
>  {
> -	return stdio_devices[file]->getc();
> +	struct stdio_dev *dev = stdio_get_fd(file);
> +	if (dev)
> +		return dev->getc();
> +	return 0;
>  }
>  
>  static inline int console_tstc(int file)
>  {
> -	return stdio_devices[file]->tstc();
> +	struct stdio_dev *dev = stdio_get_fd(file);
> +	if (dev)
> +		return dev->tstc();
> +	return 0;
>  }
>  
>  static inline void console_putc(int file, const char c)
>  {
> -	stdio_devices[file]->putc(c);
> +	struct stdio_dev *dev = stdio_get_fd(file);
> +	if (dev)
> +		return dev->putc(c);

return is not required here ..

>  }
>  
>  static inline void console_puts(int file, const char *s)
>  {
> -	stdio_devices[file]->puts(s);
> +	struct stdio_dev *dev = stdio_get_fd(file);
> +	if (dev)
> +		return dev->puts(s);

.. and here

>  }
>  
>  static inline void console_printdevs(int file)
>  {
> -	printf("%s\n", stdio_devices[file]->name);
> +	struct stdio_dev *dev = stdio_get_fd(file);
> +	if (dev)
> +		printf("%s\n", dev->name);
>  }
>  
>  static inline void console_doenv(int file, struct stdio_dev *dev)
> @@ -592,27 +604,28 @@ int console_init_f(void)
>  void stdio_print_current_devices(void)
>  {
>  #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
> +	struct stdio_dev *sio;
>  	/* Print information */
>  	puts("In:    ");
> -	if (stdio_devices[stdin] == NULL) {
> +	sio = stdio_get_fd(stdin);
> +	if (sio == NULL)
>  		puts("No input devices available!\n");
> -	} else {
> -		printf ("%s\n", stdio_devices[stdin]->name);
> -	}
> +	else
> +		printf("%s\n", sio->name);
>  
>  	puts("Out:   ");
> -	if (stdio_devices[stdout] == NULL) {
> +	sio = stdio_get_fd(stdout);

Isn't sio still set properly here ...

> +	if (sio == NULL)
>  		puts("No output devices available!\n");
> -	} else {
> -		printf ("%s\n", stdio_devices[stdout]->name);
> -	}
> +	else
> +		printf("%s\n", sio->name);
>  
>  	puts("Err:   ");
> -	if (stdio_devices[stderr] == NULL) {
> +	sio = stdio_get_fd(stderr);

.. and here?

> +	if (sio == NULL)

Side note: in your newly introduced checks you use just

 if (sio) {
 ...

Why check explicitly for NULL here? I personally favor 'if (!sio)'.

>  		puts("No error devices available!\n");
> -	} else {
> -		printf ("%s\n", stdio_devices[stderr]->name);
> -	}
> +	else
> +		printf("%s\n", sio->name);
>  #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
>  }
>  
> @@ -622,6 +635,7 @@ int console_init_r(void)
>  {
>  	char *stdinname, *stdoutname, *stderrname;
>  	struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
> +	struct stdio_dev *sio;
>  #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
>  	int i;
>  #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
> @@ -690,7 +704,9 @@ done:
>  #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
>  	/* set the environment variables (will overwrite previous env settings) */
>  	for (i = 0; i < 3; i++) {
> -		setenv(stdio_names[i], stdio_devices[i]->name);
> +		sio = stdio_get_fd(i);
> +		if (sio)
> +			setenv(stdio_names[i], sio->name);
>  	}
>  #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
>  
> @@ -706,7 +722,7 @@ int console_init_r(void)
>  	int i;
>  	struct list_head *list = stdio_get_list();
>  	struct list_head *pos;
> -	struct stdio_dev *dev;
> +	struct stdio_dev *dev, *sio;
>  
>  #ifdef CONFIG_SPLASH_SCREEN
>  	/*
> @@ -759,7 +775,9 @@ int console_init_r(void)
>  
>  	/* Setting environment variables */
>  	for (i = 0; i < 3; i++) {
> -		setenv(stdio_names[i], stdio_devices[i]->name);
> +		sio = stdio_get_fd(i);
> +		if (sio)
> +			setenv(stdio_names[i], sio->name);
>  	}
>  
>  	return 0;
> diff --git a/common/fdt_support.c b/common/fdt_support.c
> index 593f16c..7727359 100644
> --- a/common/fdt_support.c
> +++ b/common/fdt_support.c
> @@ -97,7 +97,13 @@ int fdt_find_and_setprop(void *fdt, const char *node, const char *prop,
>  #ifdef CONFIG_SERIAL_MULTI
>  static void fdt_fill_multisername(char *sername, size_t maxlen)
>  {
> -	const char *outname = stdio_devices[stdout]->name;
> +	struct stdio_dev *sio = stdio_get_fd(stdout);
> +	const char *outname;
> +
> +	if (!sio)
> +		return;
> +
> +	outname = sio->name;
>  
>  	if (strcmp(outname, "serial") > 0)
>  		strncpy(sername, outname, maxlen);
> diff --git a/common/stdio.c b/common/stdio.c
> index 6c8ac73..ba5e2fc 100644
> --- a/common/stdio.c
> +++ b/common/stdio.c
> @@ -38,7 +38,7 @@
>  DECLARE_GLOBAL_DATA_PTR;
>  
>  static struct stdio_dev devs;
> -struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL };
> +static struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL };
>  char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
>  
>  #if defined(CONFIG_SPLASH_SCREEN) && !defined(CONFIG_SYS_DEVICE_NULLDEV)
> diff --git a/include/stdio_dev.h b/include/stdio_dev.h
> index 86b2a4f..554708a 100644
> --- a/include/stdio_dev.h
> +++ b/include/stdio_dev.h
> @@ -83,7 +83,6 @@ typedef struct {
>  /*
>   * VARIABLES
>   */
> -extern struct stdio_dev *stdio_devices[];
>  extern char *stdio_names[MAX_FILES];
>  
>  /*
> 

Best regards

Andreas Bie?mann

  parent reply	other threads:[~2012-09-01 23:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-31 22:44 [U-Boot] [PATCH 0/6] stdio: Clean up Marek Vasut
2012-08-31 22:44 ` [U-Boot] [PATCH 1/6] stdio: dm: Remove dead code in console.c Marek Vasut
2012-08-31 22:44 ` [U-Boot] [PATCH 2/6] stdio: dm: Add accessors to stdio_devices[] Marek Vasut
2012-08-31 22:44 ` [U-Boot] [PATCH 3/6] stdio: dm: Make stdio_devices[] local Marek Vasut
2012-09-01 20:14   ` Marek Vasut
2012-09-01 23:11   ` Andreas Bießmann [this message]
2012-09-02  0:02     ` Marek Vasut
2012-09-02  8:12       ` Wolfgang Denk
2012-08-31 22:44 ` [U-Boot] [PATCH 4/6] stdio: dm: Add stdio_fd_to_name() call Marek Vasut
2012-08-31 22:44 ` [U-Boot] [PATCH 5/6] stdio: dm: Use stdio_fd_to_name() call to localize stdio_names Marek Vasut
2012-08-31 22:44 ` [U-Boot] [PATCH 6/6] stdio: dm: Optimize stdio_print_current_devices() Marek Vasut
2012-09-01 12:17 ` [U-Boot] [PATCH 0/6] stdio: Clean up Wolfgang Denk
2012-09-01 14:19   ` Marek Vasut
2012-09-01 16:33     ` Wolfgang Denk
2012-09-01 16:57       ` Marek Vasut
2012-09-01 20:00         ` Wolfgang Denk
2012-09-01 20:12           ` Marek Vasut

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=5042962F.4060706@googlemail.com \
    --to=andreas.devel@googlemail.com \
    --cc=u-boot@lists.denx.de \
    /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