mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tobias Klauser <tklauser@distanz.ch>
To: Rob Jones <rob.jones@codethink.co.uk>
Cc: gregkh@linuxfoundation.org, rdunlap@infradead.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kernel@lists.codethink.co.uk, ian.molton@codethink.co.uk,
	ben.dooks@codethink.co.uk
Subject: Re: [PATCH 1/1] Managed Devices devres_debugfs file system
Date: Thu, 24 Jul 2014 17:35:33 +0200	[thread overview]
Message-ID: <20140724153533.GB3384@distanz.ch> (raw)
In-Reply-To: <1406215081-15113-2-git-send-email-rob.jones@codethink.co.uk>

On 2014-07-24 at 17:18:01 +0200, Rob Jones <rob.jones@codethink.co.uk> wrote:
> Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
> Suggested-by: Ben Dooks <ben.dooks@codethink.co.uk>
> Signed-off-by: Rob Jones <rob.jones@codethink.co.uk>
> ---
>  Documentation/driver-model/devres-debugfs.txt |  140 +++++++++
>  drivers/base/Kconfig                          |   18 ++
>  drivers/base/devres.c                         |  387 +++++++++++++++++++++++++
>  3 files changed, 545 insertions(+)
>  create mode 100644 Documentation/driver-model/devres-debugfs.txt

[...]

> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
> index 5c88a27..41b6465 100644
> --- a/drivers/base/devres.c
> +++ b/drivers/base/devres.c
> @@ -7,9 +7,13 @@

[...]

> +/**
> + * devres_dbgfs_seq_show - seq file output routine for a devres debugfs file
> + * @s: pointer to seq file structure
> + * @v: pointer to private data set up by devres_dbgfs_seq_next().
> + *
> + * Static debug function called when the user reads from a device managed
> + * resources debugfs file. It outputs to the user buffer using seq_file
> + * function seq_printf();
> + *
> + * This function locks devres_lock in the device structure.
> + */
> +static int devres_dbgfs_seq_show(struct seq_file *s, void *v)
> +{
> +	struct devres_dbgfs_private *priv = v;
> +	struct device *dev = priv->dev;
> +	int size, i, pos = priv->pos;
> +	struct devres *dr;
> +	struct list_head *head;
> +	struct list_head *item;
> +	unsigned long flags;
> +	char data[16];
> +	char *dataptr;
> +
> +	if (pos == 0) {
> +		seq_printf(s, "dev: %p %s\n", dev, dev_name(dev));
> +		return 0;
> +	}
> +
> +	spin_lock_irqsave(&dev->devres_lock, flags);
> +
> +	head = &dev->devres_head;
> +	if (!head || list_empty(head))
> +		goto out_eof;
> +	item = head;
> +
> +	/* Walk the device resource list to item number *position */
> +	while (pos--) {
> +		item = item->next;
> +		/* Check for end of list before required item */
> +		if (item == head)
> +			goto out_eof;
> +	}
> +
> +	/* Node found, grab the details */
> +	dr = container_of(item, struct devres, node.entry);
> +	size = dr->node.size;
> +	dataptr = (char *)dr->data;
> +
> +	/* Take a copy of the data before unlock */
> +	memcpy(data, dataptr, (size < 16 ? size : 16));

How about using min_t(size_t, size, 16) and making size of type size_t
for that matter, since dr->node.size is size_t anyway?

> +
> +	spin_unlock_irqrestore(&dev->devres_lock, flags);
> +
> +	/* Print the node details */
> +	seq_printf(s, "res: %p %9d ", dataptr, size);
> +
> +	for (i = 0; i < 16; i++) {

Use ARRAY_SIZE(data) here, instead of the 'magic' number 16?

> +		if (size-- > 0)
> +			seq_printf(s, "%02x", data[i]);
> +		else
> +			seq_puts(s, "  ");
> +	}
> +
> +	if (dr->node.name)
> +		seq_printf(s, " %s", dr->node.name);
> +
> +	seq_putc(s, '\n');
> +
> +	return 0;
> +
> +out_eof:
> +	spin_unlock_irqrestore(&dev->devres_lock, flags);
> +	priv->eof = true;
> +	return 0; /* Seek past EOF */
> +}
> +
> +static const struct seq_operations devres_dbgfs_seq_ops = {
> +	.start = devres_dbgfs_seq_start,
> +	.show  = devres_dbgfs_seq_show,
> +	.next  = devres_dbgfs_seq_next,
> +	.stop  = devres_dbgfs_seq_stop,
> +};

  reply	other threads:[~2014-07-24 15:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-24 15:18 [PATCH 0/1] A debugfs file system for managed resources (devres) Rob Jones
2014-07-24 15:18 ` [PATCH 1/1] Managed Devices devres_debugfs file system Rob Jones
2014-07-24 15:35   ` Tobias Klauser [this message]
2014-07-24 15:59   ` Greg KH
2014-07-25 11:11     ` Rob Jones
2014-07-27  3:31       ` Greg KH

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=20140724153533.GB3384@distanz.ch \
    --to=tklauser@distanz.ch \
    --cc=ben.dooks@codethink.co.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=ian.molton@codethink.co.uk \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@lists.codethink.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=rob.jones@codethink.co.uk \
    /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

all inboxes | Powered by JetHome®