Re: [PATCH v2 1/2] stdio: Introduce stdio_valid()

2021-02-01 Thread Simon Glass
On Thu, 28 Jan 2021 at 06:12, Nicolas Saenz Julienne
 wrote:
>
> stdio_valid() will confirm that a struct stdio_dev pointer is indeed
> valid.
>
> Signed-off-by: Nicolas Saenz Julienne 
>
> ---
>
> Changes since v1:
>  - Properly document function
>
>  common/stdio.c  | 11 +++
>  include/stdio_dev.h | 11 +++
>  2 files changed, 22 insertions(+)

Reviewed-by: Simon Glass 


[PATCH v2 1/2] stdio: Introduce stdio_valid()

2021-01-28 Thread Nicolas Saenz Julienne
stdio_valid() will confirm that a struct stdio_dev pointer is indeed
valid.

Signed-off-by: Nicolas Saenz Julienne 

---

Changes since v1:
 - Properly document function

 common/stdio.c  | 11 +++
 include/stdio_dev.h | 11 +++
 2 files changed, 22 insertions(+)

diff --git a/common/stdio.c b/common/stdio.c
index abf9b1e915..69b7d2692d 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -157,6 +157,17 @@ static int stdio_probe_device(const char *name, enum 
uclass_id id,
return 0;
 }
 
+bool stdio_valid(struct stdio_dev *dev)
+{
+   struct stdio_dev *sdev;
+
+   list_for_each_entry(sdev, , list)
+   if (sdev == dev)
+   return true;
+
+   return false;
+}
+
 struct stdio_dev *stdio_get_by_name(const char *name)
 {
struct list_head *pos;
diff --git a/include/stdio_dev.h b/include/stdio_dev.h
index 48871a6a22..e9d610a840 100644
--- a/include/stdio_dev.h
+++ b/include/stdio_dev.h
@@ -98,6 +98,17 @@ struct list_head *stdio_get_list(void);
 struct stdio_dev *stdio_get_by_name(const char *name);
 struct stdio_dev *stdio_clone(struct stdio_dev *dev);
 
+/**
+ * stdio_valid() - Validate stdio device exists
+ *
+ * Verifies that dev is contained in the global list of stdio devices.
+ *
+ * @dev: Stdio device pointer
+ *
+ * returns 'true' when valid, 'false' otherwise
+ */
+bool stdio_valid(struct stdio_dev *dev);
+
 int drv_lcd_init(void);
 int drv_video_init(void);
 int drv_keyboard_init(void);
-- 
2.30.0