Re: [PATCH] PCI: Set VPD size conservatively

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

 



On Mon, Jun 30, 2008 at 05:52:08PM +0100, Ben Hutchings wrote:
> +void pci_vpd_set_real_size(struct pci_dev *dev)
> +{
> +	unsigned limit = dev->vpd->size;
> +	unsigned addr = 0;
> +
> +	/* Follow chain of resources until we find the end tag, a
> +	 * resource size that would overflow the limit, or an I/O
> +	 * error.
> +	 */
> +	for (;;) {
> +		u8 tag;
> +		__le16 res_size_le;
> +		unsigned res_size;
> +
> +		if (dev->vpd->ops->read(dev, addr, 1, (char *)&tag) != 1)
> +			break;
> +		if (tag & 0x80) {
> +			if (addr > limit - 3)
> +				break;
> +			if (dev->vpd->ops->read(dev, addr + 1, 1,
> +						(char *)&res_size_le) +
> +			    dev->vpd->ops->read(dev, addr + 2, 1,
> +						(char *)&res_size_le + 1) != 2)
> +				break;
> +			res_size = le16_to_cpu(res_size_le);
> +			addr += 3;

This is perhaps a little convoluted.  How about this?

		if (tag & 0x80) {
			char byte;
			if (addr > limit - 3)
				break;
			if (dev->vpd->ops->read(dev, addr + 1, 1, &byte) != 1)
				break;
			res_size = byte;
			if (dev->vpd->ops->read(dev, addr + 2, 1, &byte) != 1)
				break;
			res_size |= (byte << 8);
			addr += 3;

I'd like it if we had:

typedef int (vpd_read_t)(struct pci_dev *dev, int pos, int size, char *buf);

And then we could do:

	vpd_read_t vpd_read = dev->vpd->ops->read;
...
			if (vpd_read(dev, addr + 1, 1, &byte) != 1)

-- 
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux