From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH v2 4/4] bbu: Simplify bbu_find_handler_by_device()
Date: Sun, 7 Oct 2018 23:35:18 -0700 [thread overview]
Message-ID: <20181008063518.18164-5-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20181008063518.18164-1-andrew.smirnov@gmail.com>
Simplify bbu_find_handler_by_device() by making use of
devpath_to_name() as well as some basic recursion to avoid coding the
same loop twice.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
common/bbu.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/common/bbu.c b/common/bbu.c
index 75c3221d5..5cb09e4eb 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -120,22 +120,18 @@ struct bbu_handler *bbu_find_handler_by_name(const char *name)
struct bbu_handler *bbu_find_handler_by_device(const char *devicepath)
{
struct bbu_handler *handler;
+ const char *devname = devpath_to_name(devicepath);
if (!devicepath)
return NULL;
- list_for_each_entry(handler, &bbu_image_handlers, list)
+ list_for_each_entry(handler, &bbu_image_handlers, list) {
if (!strcmp(handler->devicefile, devicepath))
return handler;
+ }
- if (strncmp(devicepath, "/dev/", 5))
- return NULL;
-
- devicepath += 5;
-
- list_for_each_entry(handler, &bbu_image_handlers, list)
- if (!strcmp(handler->devicefile, devicepath))
- return handler;
+ if (devname != devicepath)
+ return bbu_find_handler_by_device(devname);
return NULL;
}
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-10-08 6:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-08 6:35 [PATCH v2 0/4] Additional error checking for barebox_update Andrey Smirnov
2018-10-08 6:35 ` [PATCH v2 1/4] bbu: Expose bbu_find_handler_by_*() functions Andrey Smirnov
2018-10-08 6:35 ` [PATCH v2 2/4] bbu: Add "handler" parameter to barebox_update() Andrey Smirnov
2018-10-08 6:35 ` [PATCH v2 3/4] bbu: command: Make sure specified update handler exists Andrey Smirnov
2018-10-08 6:35 ` Andrey Smirnov [this message]
2018-10-08 8:08 ` [PATCH v2 0/4] Additional error checking for barebox_update Sascha Hauer
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=20181008063518.18164-5-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--cc=barebox@lists.infradead.org \
/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