mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 3/3] commands: add new devunbind debugging command
Date: Mon, 10 Jan 2022 09:56:34 +0100	[thread overview]
Message-ID: <20220110085634.GD6003@pengutronix.de> (raw)
In-Reply-To: <20220108171426.586330-3-a.fatoum@pengutronix.de>

On Sat, Jan 08, 2022 at 06:14:26PM +0100, Ahmad Fatoum wrote:
> Memory corruption around device removal may go unnoticed, because
> barebox is shutting down anyway and doing no new allocations.
> 
> Add a new devunbind command that should help with debugging such issues
> by allowing selective unbinding and removal of devices.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  commands/Kconfig      | 12 +++++++
>  commands/Makefile     |  1 +
>  commands/devunbind.c  | 74 +++++++++++++++++++++++++++++++++++++++++++
>  drivers/base/driver.c |  7 ++--
>  include/driver.h      |  4 +++
>  5 files changed, 95 insertions(+), 3 deletions(-)
>  create mode 100644 commands/devunbind.c
> 
> diff --git a/commands/Kconfig b/commands/Kconfig
> index e2c36949347e..9abd97271952 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -68,6 +68,18 @@ config CMD_DEVINFO
>  	  If called with a device path being the argument, devinfo shows more
>  	  default information about this device and its parameters.
>  
> +config CMD_DEVUNBIND
> +	tristate
> +	default y
> +	prompt "devunbind"
> +	help
> +	  Debugging aid to unbind device from driver at runtime
> +
> +	  devunbind [-f] DEVICE
> +
> +	  Options:
> +	    -f   unbind driver and force removal of device and children
> +
>  config CMD_DMESG
>  	tristate
>  	prompt "dmesg"
> diff --git a/commands/Makefile b/commands/Makefile
> index 0b7c1563b534..875826743ffe 100644
> --- a/commands/Makefile
> +++ b/commands/Makefile
> @@ -107,6 +107,7 @@ obj-$(CONFIG_CMD_MIITOOL)	+= miitool.o
>  obj-$(CONFIG_CMD_DETECT)	+= detect.o
>  obj-$(CONFIG_CMD_BOOT)		+= boot.o
>  obj-$(CONFIG_CMD_DEVINFO)	+= devinfo.o
> +obj-$(CONFIG_CMD_DEVUNBIND)	+= devunbind.o
>  obj-$(CONFIG_CMD_DRVINFO)	+= drvinfo.o
>  obj-$(CONFIG_CMD_READF)		+= readf.o
>  obj-$(CONFIG_CMD_MENUTREE)	+= menutree.o
> diff --git a/commands/devunbind.c b/commands/devunbind.c
> new file mode 100644
> index 000000000000..4bebb27e8e68
> --- /dev/null
> +++ b/commands/devunbind.c
> @@ -0,0 +1,74 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +// SPDX-FileCopyrightText: © 2021 Ahmad Fatoum <a.fatoum@pengutronix.de>, Pengutronix
> +
> +#include <command.h>
> +#include <common.h>
> +#include <complete.h>
> +#include <driver.h>
> +#include <getopt.h>
> +
> +static int do_devunbind(int argc, char *argv[])
> +{
> +	bool unregister = false;
> +	struct device_d *dev;
> +	int ret = COMMAND_SUCCESS, i, opt;
> +
> +	while ((opt = getopt(argc, argv, "fl")) > 0) {
> +		switch (opt) {
> +		case 'f':
> +			unregister = true;
> +			break;
> +		case 'l':
> +			list_for_each_entry(dev, &active_device_list, active) {
> +				BUG_ON(!dev->driver);
> +				if (dev->bus->remove)
> +					printf("%pS(%s, %s)\n", dev->bus->remove,
> +					       dev->driver->name, dev_name(dev));
> +			}
> +			return 0;
> +		default:
> +			return COMMAND_ERROR_USAGE;
> +		}
> +	}
> +
> +	if (!argv[optind])
> +		return COMMAND_ERROR_USAGE;
> +
> +	for (i = optind; i < argc; i++) {
> +		dev = get_device_by_name(argv[i]);
> +		if (!dev)
> +			return -ENODEV;
> +
> +		if (unregister)
> +			return unregister_device(dev);

Shouldn't you continue the loop here?

Sascha

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2022-01-10  9:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-08 17:14 [PATCH 1/3] tlsf: dump stack on assertion failure Ahmad Fatoum
2022-01-08 17:14 ` [PATCH 2/3] driver: have CONFIG_DEBUG_PROBES report device unbind as well Ahmad Fatoum
2022-01-08 17:14 ` [PATCH 3/3] commands: add new devunbind debugging command Ahmad Fatoum
2022-01-10  8:56   ` Sascha Hauer [this message]
2022-01-13 16:04     ` Ahmad Fatoum

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=20220110085634.GD6003@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH 3/3] commands: add new devunbind debugging command' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox