linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Li Chen <lchen@ambarella.com>
Cc: Jonathan Corbet <corbet@lwn.net>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Li Chen <me@linux.beauty>, Randy Dunlap <rdunlap@infradead.org>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 01/15] debugfs: allow to use regmap for print regs
Date: Mon, 23 Jan 2023 12:52:45 +0100	[thread overview]
Message-ID: <Y851DWfj+hZIiR38@kroah.com> (raw)
In-Reply-To: <20230123073305.149940-2-lchen@ambarella.com>

On Mon, Jan 23, 2023 at 03:32:16PM +0800, Li Chen wrote:
> Currently, debugfs_regset32 only contains void __iomem *base,
> and it is not friendly to regmap user.
> 
> Let's add regmap to debugfs_regset32, and add regmap
> support to debugfs_print_reg32.
> 
> Signed-off-by: Li Chen <me@linux.beauty>
> Change-Id: I8ef015ed0906a4ad85b7592f771dcf64c23f7832

No change-id please.

> ---
>  Documentation/filesystems/debugfs.rst |  2 ++
>  fs/debugfs/file.c                     | 43 ++++++++++++++++++++++++++-
>  include/linux/debugfs.h               | 11 +++++++
>  3 files changed, 55 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/filesystems/debugfs.rst b/Documentation/filesystems/debugfs.rst
> index dc35da8b8792..b2c76ac3a333 100644
> --- a/Documentation/filesystems/debugfs.rst
> +++ b/Documentation/filesystems/debugfs.rst
> @@ -178,6 +178,8 @@ file::
>  
>      void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
>  			 int nregs, void __iomem *base, char *prefix);
> +    void debugfs_print_regmap_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
> +			 int nregs, struct regmap *regmap*, char *prefix);

One too many "*" characters on that last line, right?

>  
>  The "base" argument may be 0, but you may want to build the reg32 array
>  using __stringify, and a number of register names (macros) are actually
> diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
> index b54f470e0d03..2fb792843b30 100644
> --- a/fs/debugfs/file.c
> +++ b/fs/debugfs/file.c
> @@ -1137,14 +1137,55 @@ void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
>  }
>  EXPORT_SYMBOL_GPL(debugfs_print_regs32);
>  
> +/**
> + * debugfs_print_regmap_regs32 - use seq_print to describe a set of registers
> + * @s: the seq_file structure being used to generate output
> + * @regs: an array if struct debugfs_reg32 structures
> + * @nregs: the length of the above array
> + * @regmap: regmap to be used in reading the registers
> + * @prefix: a string to be prefixed to every output line
> + *
> + * This function outputs a text block describing the current values of
> + * some 32-bit hardware registers. It is meant to be used within debugfs
> + * files based on seq_file that need to show registers, intermixed with other
> + * information. The prefix argument may be used to specify a leading string,
> + * because some peripherals have several blocks of identical registers,
> + * for example configuration of dma channels
> + */
> +void debugfs_print_regmap_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
> +			  int nregs, struct regmap *regmap, char *prefix)
> +{
> +	int i;
> +	u32 val;
> +
> +	for (i = 0; i < nregs; i++, regs++) {
> +		if (prefix)
> +			seq_printf(s, "%s", prefix);
> +		regmap_read(regmap, regs->offset, &val);
> +		seq_printf(s, "%s = 0x%08x\n", regs->name, val);
> +		if (seq_has_overflowed(s))
> +			break;
> +	}
> +}
> +EXPORT_SYMBOL_GPL(debugfs_print_regmap_regs32);
> +
>  static int debugfs_regset32_show(struct seq_file *s, void *data)
>  {
>  	struct debugfs_regset32 *regset = s->private;
>  
> +	void __iomem *base = regset->base;
> +	struct regmap *regmap = regset->regmap;

Why the extra blank line?  Did you run checkpatch?

And it's generally not considered a good idea to dereference a pointer
_before_ it is checked.  It will not crash, but static checkers will
have a field day with it.


> +
> +	if ((regmap && base) || (!regmap && !base))
> +		return -EINVAL;
> +
>  	if (regset->dev)
>  		pm_runtime_get_sync(regset->dev);
>  
> -	debugfs_print_regs32(s, regset->regs, regset->nregs, regset->base, "");
> +	if (base)
> +		debugfs_print_regs32(s, regset->regs, regset->nregs, base, "");
> +	else
> +		debugfs_print_regmap_regs32(s, regset->regs, regset->nregs, regmap, "");
>  
>  	if (regset->dev)
>  		pm_runtime_put(regset->dev);
> diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
> index ea2d919fd9c7..87dfea6a25a0 100644
> --- a/include/linux/debugfs.h
> +++ b/include/linux/debugfs.h
> @@ -17,6 +17,7 @@
>  
>  #include <linux/types.h>
>  #include <linux/compiler.h>
> +#include <linux/regmap.h>

No need to include this here, just provide a prototype for "struct
regmap" and all will be fine.

thanks,

greg k-h

  parent reply	other threads:[~2023-01-23 11:52 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-23  7:32 [PATCH 00/15] Ambarella S6LM SoC bring-up Li Chen
2023-01-23  7:32 ` [PATCH 02/15] dt-bindings: vendor-prefixes: add Ambarella prefix Li Chen
2023-01-23  8:02   ` Krzysztof Kozlowski
2023-01-23  7:32 ` [PATCH 05/15] arm64: Kconfig: Introduce CONFIG_ARCH_AMBARELLA Li Chen
2023-01-23  8:32   ` Arnd Bergmann
     [not found] ` <20230123073305.149940-4-lchen@ambarella.com>
2023-01-23  8:03   ` [PATCH 03/15] dt-bindings: arm: ambarella: Add binding for Ambarella ARM platforms Krzysztof Kozlowski
2023-01-23 13:58     ` Li Chen
     [not found] ` <20230123073305.149940-5-lchen@ambarella.com>
2023-01-23  8:07   ` [PATCH 04/15] dt-bindings: arm: add support for Ambarella SoC Krzysztof Kozlowski
2023-01-23 15:09     ` Li Chen
2023-01-23 15:52       ` Krzysztof Kozlowski
     [not found] ` <20230123073305.149940-8-lchen@ambarella.com>
2023-01-23  8:11   ` [PATCH 07/15] dt-bindings: clock: Add Ambarella clock bindings Krzysztof Kozlowski
2023-01-25  9:28     ` Li Chen
2023-01-25  9:55       ` Krzysztof Kozlowski
2023-01-25 12:06         ` Li Chen
2023-01-25 12:14           ` Krzysztof Kozlowski
2023-01-25 13:40             ` Li Chen
2023-01-26 11:29               ` Krzysztof Kozlowski
2023-01-27 14:48                 ` Li Chen
2023-01-27 15:08                   ` Krzysztof Kozlowski
2023-01-28  9:42                     ` Li Chen
2023-01-28 10:08                       ` Krzysztof Kozlowski
2023-01-28 10:11                         ` Li Chen
2023-02-06 11:28                     ` Li Chen
2023-02-06 13:41                       ` Krzysztof Kozlowski
2023-02-06 14:57                         ` Li Chen
2023-02-08 10:27                           ` Krzysztof Kozlowski
2023-01-27 15:11                   ` Krzysztof Kozlowski
2023-01-28  9:45                     ` Li Chen
     [not found] ` <20230123073305.149940-10-lchen@ambarella.com>
2023-01-23  8:11   ` [PATCH 09/15] dt-bindings: serial: add support for Ambarella Krzysztof Kozlowski
2023-01-25  9:54     ` Li Chen
2023-01-25  9:56       ` Krzysztof Kozlowski
2023-01-28  9:22         ` Li Chen
     [not found] ` <20230123073305.149940-12-lchen@ambarella.com>
2023-01-23  8:13   ` [PATCH 11/15] dt-bindings: mtd: Add binding " Krzysztof Kozlowski
     [not found] ` <20230123073305.149940-14-lchen@ambarella.com>
2023-01-23  8:13   ` [PATCH 13/15] dt-bindings: pinctrl: add support " Krzysztof Kozlowski
2023-01-23 12:32   ` Linus Walleij
2023-01-28 10:05     ` Li Chen
     [not found] ` <20230123073305.149940-16-lchen@ambarella.com>
2023-01-23  8:20   ` [PATCH 15/15] arm64: dts: ambarella: introduce Ambarella s6lm SoC Krzysztof Kozlowski
     [not found] ` <20230123073305.149940-7-lchen@ambarella.com>
2023-01-23  8:29   ` [PATCH 06/15] soc: add Ambarella driver Arnd Bergmann
2023-01-24  7:58     ` Li Chen
2023-01-24 15:46       ` Arnd Bergmann
2023-01-29  7:21         ` Li Chen
2023-01-23 11:48   ` Conor.Dooley
2023-01-24  8:27     ` Li Chen
2023-01-24  8:46       ` Conor.Dooley
2023-01-24 14:24         ` Li Chen
     [not found] ` <20230123073305.149940-13-lchen@ambarella.com>
2023-01-23  8:32   ` [PATCH 12/15] mtd: nand: add Ambarella nand support Miquel Raynal
2023-01-23  8:39 ` [PATCH 00/15] Ambarella S6LM SoC bring-up Arnd Bergmann
2023-01-24  2:08   ` Bagas Sanjaya
     [not found] ` <20230123073305.149940-11-lchen@ambarella.com>
2023-01-23  9:50   ` [PATCH 10/15] serial: ambarella: add support for Ambarella uart_port Greg Kroah-Hartman
2023-01-23  9:51   ` Greg Kroah-Hartman
2023-01-25 10:01     ` Li Chen
     [not found] ` <20230123073305.149940-2-lchen@ambarella.com>
2023-01-23 11:52   ` Greg Kroah-Hartman [this message]
2023-01-23 13:47     ` [PATCH 01/15] debugfs: allow to use regmap for print regs Li Chen

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=Y851DWfj+hZIiR38@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=corbet@lwn.net \
    --cc=lchen@ambarella.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@linux.beauty \
    --cc=rafael@kernel.org \
    --cc=rdunlap@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;
as well as URLs for NNTP newsgroup(s).