lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140724153533.GB3384@distanz.ch>
Date:	Thu, 24 Jul 2014 17:35:33 +0200
From:	Tobias Klauser <tklauser@...tanz.ch>
To:	Rob Jones <rob.jones@...ethink.co.uk>
Cc:	gregkh@...uxfoundation.org, rdunlap@...radead.org,
	linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
	linux-kernel@...ts.codethink.co.uk, ian.molton@...ethink.co.uk,
	ben.dooks@...ethink.co.uk
Subject: Re: [PATCH 1/1] Managed Devices devres_debugfs file system

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ