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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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-doc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux