[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20080905110222.GH7908@solarflare.com>
Date: Fri, 5 Sep 2008 12:02:23 +0100
From: Ben Hutchings <bhutchings@...arflare.com>
To: Stephen Hemminger <shemminger@...tta.com>
Cc: Jesse Barnes <jbarnes@...tuousgeek.org>, linux-pci@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/3] PCI: revise VPD access interface
Stephen Hemminger wrote:
> Change PCI VPD API which was only used by sysfs to something usable
> in drivers.
> * move iteration over multiple words to the low level
> * cleanup types of arguments
> * add exportable wrapper
>
> Signed-off-by: Stephen Hemminger <shemminger@...tta.com>
>
> --- a/drivers/pci/access.c 2008-09-04 10:16:52.000000000 -0700
> +++ b/drivers/pci/access.c 2008-09-04 10:19:47.000000000 -0700
[...]
> -static int pci_vpd_pci22_write(struct pci_dev *dev, int pos, int size,
> - const char *buf)
> +static int pci_vpd_pci22_write(struct pci_dev *dev, loff_t pos, size_t count,
> + const void *buf)
> {
> struct pci_vpd_pci22 *vpd =
> container_of(dev->vpd, struct pci_vpd_pci22, base);
> - u32 val;
> + loff_t end = pos + count;
> int ret;
>
> - if (pos < 0 || pos > vpd->base.len || pos & 3 ||
> - size > vpd->base.len - pos || size < 4)
> + if (pos > vpd->base.len || pos & 3)
> return -EINVAL;
>
> - val = (u8) *buf++;
> - val |= ((u8) *buf++) << 8;
> - val |= ((u8) *buf++) << 16;
> - val |= ((u32)(u8) *buf++) << 24;
> -
> ret = mutex_lock_killable(&vpd->lock);
> if (ret)
> return ret;
> - ret = pci_vpd_pci22_wait(dev);
> - if (ret < 0)
> - goto out;
> - ret = pci_user_write_config_dword(dev, vpd->cap + PCI_VPD_DATA,
> - val);
> - if (ret < 0)
> - goto out;
> - ret = pci_user_write_config_word(dev, vpd->cap + PCI_VPD_ADDR,
> - pos | PCI_VPD_ADDR_F);
> - if (ret < 0)
> - goto out;
> - vpd->busy = true;
> - vpd->flag = 0;
> - ret = pci_vpd_pci22_wait(dev);
> -out:
> - mutex_unlock(&vpd->lock);
> - if (ret < 0)
> - return ret;
>
> - return 4;
> + while (pos < end) {
> + u32 val;
> +
> + ret = pci_vpd_pci22_wait(dev);
> + if (ret < 0)
> + break;
> + memcpy(&val, buf, sizeof(u32));
[...]
I'm not sure this is correct. pci_user_write_config_dword() expects a
value in host byte order, but this memcpy() makes val always little-endian.
Ben.
--
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
--
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