diff mbox

[U-Boot,RFC,13/22] stdio: Provide functions to add/remove devices using stdio_dev

Message ID 1400966481-14131-14-git-send-email-sjg@chromium.org
State RFC
Headers show

Commit Message

Simon Glass May 24, 2014, 9:21 p.m. UTC
The current functions for adding and removing devices require a device name.
This is not convenient for driver model, which wants to store a pointer to
the relevant device. Add new functions which provide this feature and adjust
the old ones to call these.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/stdio.c      | 29 ++++++++++++++++++++++-------
 include/stdio_dev.h |  2 ++
 2 files changed, 24 insertions(+), 7 deletions(-)

Comments

Marek Vasut June 1, 2014, 5:37 p.m. UTC | #1
On Saturday, May 24, 2014 at 11:21:12 PM, Simon Glass wrote:
> The current functions for adding and removing devices require a device
> name. This is not convenient for driver model, which wants to store a
> pointer to the relevant device. Add new functions which provide this
> feature and adjust the old ones to call these.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

I think we should use errno.h and not return -1 all around.

Other than that:
Acked-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut
diff mbox

Patch

diff --git a/common/stdio.c b/common/stdio.c
index dd402cc..f490d6b 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -148,7 +148,7 @@  struct stdio_dev* stdio_clone(struct stdio_dev *dev)
 	return _dev;
 }
 
-int stdio_register (struct stdio_dev * dev)
+int stdio_register_dev(struct stdio_dev *dev, struct stdio_dev **devp)
 {
 	struct stdio_dev *_dev;
 
@@ -156,24 +156,27 @@  int stdio_register (struct stdio_dev * dev)
 	if(!_dev)
 		return -1;
 	list_add_tail(&(_dev->list), &(devs.list));
+	if (devp)
+		*devp = _dev;
+
 	return 0;
 }
 
+int stdio_register(struct stdio_dev *dev)
+{
+	return stdio_register_dev(dev, NULL);
+}
+
 /* deregister the device "devname".
  * returns 0 if success, -1 if device is assigned and 1 if devname not found
  */
 #ifdef	CONFIG_SYS_STDIO_DEREGISTER
-int stdio_deregister(const char *devname)
+int stdio_deregister_dev(struct stdio_dev *dev)
 {
 	int l;
 	struct list_head *pos;
-	struct stdio_dev *dev;
 	char temp_names[3][16];
 
-	dev = stdio_get_by_name(devname);
-
-	if(!dev) /* device not found */
-		return -1;
 	/* get stdio devices (ListRemoveItem changes the dev list) */
 	for (l=0 ; l< MAX_FILES; l++) {
 		if (stdio_devices[l] == dev) {
@@ -197,6 +200,18 @@  int stdio_deregister(const char *devname)
 	}
 	return 0;
 }
+
+int stdio_deregister(const char *devname)
+{
+	struct stdio_dev *dev;
+
+	dev = stdio_get_by_name(devname);
+
+	if (!dev) /* device not found */
+		return -1;
+
+	return stdio_deregister_dev(dev);
+}
 #endif	/* CONFIG_SYS_STDIO_DEREGISTER */
 
 int stdio_init (void)
diff --git a/include/stdio_dev.h b/include/stdio_dev.h
index 4587005..a7d0825 100644
--- a/include/stdio_dev.h
+++ b/include/stdio_dev.h
@@ -77,10 +77,12 @@  extern char *stdio_names[MAX_FILES];
  * PROTOTYPES
  */
 int	stdio_register (struct stdio_dev * dev);
+int stdio_register_dev(struct stdio_dev *dev, struct stdio_dev **devp);
 int	stdio_init (void);
 void	stdio_print_current_devices(void);
 #ifdef CONFIG_SYS_STDIO_DEREGISTER
 int	stdio_deregister(const char *devname);
+int stdio_deregister_dev(struct stdio_dev *dev);
 #endif
 struct list_head* stdio_get_list(void);
 struct stdio_dev* stdio_get_by_name(const char* name);