All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: u-boot@lists.denx.de
Subject: [PATCH 1/2] stdio: Introduce stdio_valid()
Date: Wed, 20 Jan 2021 15:04:53 +0100	[thread overview]
Message-ID: <20210120140454.4286-2-nsaenzjulienne@suse.de> (raw)
In-Reply-To: <20210120140454.4286-1-nsaenzjulienne@suse.de>

stdio_valid() will confirm that a struct stdio_dev pointer is indeed
valid.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 common/stdio.c      | 11 +++++++++++
 include/stdio_dev.h |  1 +
 2 files changed, 12 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, &devs.list, 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..f341439b03 100644
--- a/include/stdio_dev.h
+++ b/include/stdio_dev.h
@@ -97,6 +97,7 @@ int stdio_deregister_dev(struct stdio_dev *dev, int force);
 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);
+bool stdio_valid(struct stdio_dev *dev);
 
 int drv_lcd_init(void);
 int drv_video_init(void);
-- 
2.30.0

  reply	other threads:[~2021-01-20 14:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 14:04 [PATCH 0/2] Console/stdio use after free Nicolas Saenz Julienne
2021-01-20 14:04 ` Nicolas Saenz Julienne [this message]
2021-01-24  2:03   ` [PATCH 1/2] stdio: Introduce stdio_valid() Simon Glass
2021-01-25 16:34     ` Nicolas Saenz Julienne
2021-01-27 20:13       ` Tom Rini
2021-01-20 14:04 ` [PATCH 2/2] console: Don't start/stop console if stdio device invalid Nicolas Saenz Julienne
2021-01-24  2:03   ` Simon Glass
2021-01-20 14:18 ` [PATCH 0/2] Console/stdio use after free Simon Glass
2021-01-20 14:44   ` Nicolas Saenz Julienne
2021-01-20 14:59     ` Simon Glass
2021-01-20 18:59   ` Pratyush Yadav
2021-01-20 19:54     ` Simon Glass
2021-01-20 15:57 ` Andy Shevchenko
2021-01-25 16:31   ` Nicolas Saenz Julienne

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=20210120140454.4286-2-nsaenzjulienne@suse.de \
    --to=nsaenzjulienne@suse.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.