Re: [PATCH 1/1] Managed Devices devres_debugfs file system

From: Tobias Klauser
Date: Thu Jul 24 2014 - 11:35:42 EST


On 2014-07-24 at 17:18:01 +0200, Rob Jones <rob.jones@xxxxxxxxxxxxxxx> wrote:
> Reviewed-by: Ian Molton <ian.molton@xxxxxxxxxxxxxxx>
> Suggested-by: Ben Dooks <ben.dooks@xxxxxxxxxxxxxxx>
> Signed-off-by: Rob Jones <rob.jones@xxxxxxxxxxxxxxx>
> ---
> 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,
> +};
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/