From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 5/6] commands: drvinfo: support filtering by driver
Date: Thu, 27 Oct 2022 09:29:16 +0200 [thread overview]
Message-ID: <20221027072916.GB9130@pengutronix.de> (raw)
In-Reply-To: <20221026064205.2360041-5-a.fatoum@pengutronix.de>
On Wed, Oct 26, 2022 at 08:42:04AM +0200, Ahmad Fatoum wrote:
> drvinfo can be very long especially for the in-tree defconfigs,
> add optional filtering support:
>
> barebox@board:/ drvinfo imx7d
> Driver Device(s)
> --------------------
> imx7d-src
> 30390000.reset-controller@30390000.of
> imx7d_adc
> 30610000.adc@30610000.of
> 30620000.adc@30620000.of
>
> Use 'devinfo DEVICE' for more information
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> commands/drvinfo.c | 13 +++++++++++++
> common/complete.c | 21 +++++++++++++++++++++
> include/complete.h | 1 +
> 3 files changed, 35 insertions(+)
>
> diff --git a/commands/drvinfo.c b/commands/drvinfo.c
> index 9f8f971ee9dd..27ff55f01d90 100644
> --- a/commands/drvinfo.c
> +++ b/commands/drvinfo.c
> @@ -5,15 +5,23 @@
> #include <common.h>
> #include <command.h>
> #include <driver.h>
> +#include <complete.h>
>
> static int do_drvinfo(int argc, char *argv[])
> {
> + char *filter = NULL;
> struct driver_d *drv;
> struct device_d *dev;
>
> + if (IS_ENABLED(CONFIG_AUTO_COMPLETE) && argc > 1)
> + filter = strjoin(" ", &argv[1], argc - 1);
Why does this depend on CONFIG_AUTO_COMPLETE?
> +
> printf("Driver\tDevice(s)\n");
> printf("--------------------\n");
> for_each_driver(drv) {
> + if (filter && !str_has_prefix(drv->name, filter))
> + continue;
I don't see how this is expected to work. When you pass multiple drivers
as argument 'filter' will be a concatenation of multiple driver names
which then matches nothing.
How about using fnmatch? We could then pass things like "*usb*"
Sascha
> +
> printf("%s\n",drv->name);
> for_each_device(dev) {
> if (dev->driver == drv)
> @@ -24,6 +32,7 @@ static int do_drvinfo(int argc, char *argv[])
> if (IS_ENABLED(CONFIG_CMD_DEVINFO))
> printf("\nUse 'devinfo DEVICE' for more information\n");
>
> + free(filter);
> return 0;
> }
>
> @@ -31,5 +40,9 @@ static int do_drvinfo(int argc, char *argv[])
> BAREBOX_CMD_START(drvinfo)
> .cmd = do_drvinfo,
> BAREBOX_CMD_DESC("list compiled-in device drivers")
> +#ifdef CONFIG_AUTO_COMPLETE
> + BAREBOX_CMD_OPTS("[DRIVER]")
> +#endif
> BAREBOX_CMD_GROUP(CMD_GRP_INFO)
> + BAREBOX_CMD_COMPLETE(driver_complete)
> BAREBOX_CMD_END
> diff --git a/common/complete.c b/common/complete.c
> index ab3c98549314..916d13d776ce 100644
> --- a/common/complete.c
> +++ b/common/complete.c
> @@ -174,6 +174,27 @@ static int device_param_complete(struct device_d *dev, struct string_list *sl,
> return 0;
> }
>
> +int driver_complete(struct string_list *sl, char *instr)
> +{
> + struct driver_d *drv;
> + int len;
> +
> + if (!instr)
> + instr = "";
> +
> + len = strlen(instr);
> +
> + for_each_driver(drv) {
> + if (strncmp(instr, drv->name, len))
> + continue;
> +
> + string_list_add_asprintf(sl, "%s ", drv->name);
> + }
> +
> + return COMPLETE_CONTINUE;
> +}
> +EXPORT_SYMBOL(driver_complete);
> +
> int empty_complete(struct string_list *sl, char *instr)
> {
> return COMPLETE_END;
> diff --git a/include/complete.h b/include/complete.h
> index b0e675b5599f..2068760ac235 100644
> --- a/include/complete.h
> +++ b/include/complete.h
> @@ -14,6 +14,7 @@ void complete_reset(void);
>
> int command_complete(struct string_list *sl, char *instr);
> int device_complete(struct string_list *sl, char *instr);
> +int driver_complete(struct string_list *sl, char *instr);
> int empty_complete(struct string_list *sl, char *instr);
> int eth_complete(struct string_list *sl, char *instr);
> int command_var_complete(struct string_list *sl, char *instr);
> --
> 2.30.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2022-10-27 7:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-26 6:42 [PATCH 1/6] commands: add new uptime command Ahmad Fatoum
2022-10-26 6:42 ` [PATCH 2/6] commands: time: refactor into new strjoin Ahmad Fatoum
2022-10-26 6:42 ` [PATCH 3/6] string: reduce strjoin runtime, drop trailing separator Ahmad Fatoum
2022-10-27 6:56 ` Sascha Hauer
2022-10-27 7:24 ` Ahmad Fatoum
2022-10-27 7:33 ` Sascha Hauer
2022-10-27 7:53 ` Ahmad Fatoum
2022-10-26 6:42 ` [PATCH 4/6] test: self: add strjoin tests Ahmad Fatoum
2022-10-26 6:42 ` [PATCH 5/6] commands: drvinfo: support filtering by driver Ahmad Fatoum
2022-10-27 7:29 ` Sascha Hauer [this message]
2022-10-27 7:51 ` Ahmad Fatoum
2022-10-27 8:49 ` Sascha Hauer
2022-10-26 6:42 ` [PATCH 6/6] test: self: only include ramfs selftest when CONFIG_SELFTEST_FS_RAMFS=y Ahmad Fatoum
2022-10-27 7:11 ` [PATCH 1/6] commands: add new uptime command 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=20221027072916.GB9130@pengutronix.de \
--to=sha@pengutronix.de \
--cc=a.fatoum@pengutronix.de \
--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