Commit a986d796 authored by Jeremy Sowden's avatar Jeremy Sowden Committed by Greg Kroah-Hartman

staging: kpc2000: added a helper to get struct kp2000_device from struct device.

The attribute call-backs all use the same formula to get the pcard from
dev:

  struct pci_dev *pdev = to_pci_dev(dev);
  struct kp2000_device *pcard;

  if (!pdev)
    return -ENXIO;
  pcard = pci_get_drvdata(pdev);
  if (!pcard)
    return -ENXIO;

Added a function to reduce the duplicated code.
Signed-off-by: default avatarJeremy Sowden <jeremy@azazel.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d8ac3593
...@@ -29,15 +29,21 @@ ...@@ -29,15 +29,21 @@
* SysFS Attributes * SysFS Attributes
******************************************************/ ******************************************************/
static ssize_t show_attr(struct device *dev, struct device_attribute *attr, static struct kp2000_device *get_pcard(struct device *dev)
char *buf)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
struct kp2000_device *pcard;
if (!pdev) if (!pdev)
return -ENXIO; return NULL;
pcard = pci_get_drvdata(pdev);
return pci_get_drvdata(pdev);
}
static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct kp2000_device *pcard = get_pcard(dev);
if (!pcard) if (!pcard)
return -ENXIO; return -ENXIO;
...@@ -72,14 +78,9 @@ static ssize_t show_attr(struct device *dev, struct device_attribute *attr, ...@@ -72,14 +78,9 @@ static ssize_t show_attr(struct device *dev, struct device_attribute *attr,
static ssize_t show_cpld_config_reg(struct device *dev, static ssize_t show_cpld_config_reg(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct kp2000_device *pcard = get_pcard(dev);
struct kp2000_device *pcard;
u64 val; u64 val;
if (!pdev)
return -ENXIO;
pcard = pci_get_drvdata(pdev);
if (!pcard) if (!pcard)
return -ENXIO; return -ENXIO;
...@@ -91,14 +92,10 @@ static ssize_t cpld_reconfigure(struct device *dev, ...@@ -91,14 +92,10 @@ static ssize_t cpld_reconfigure(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct kp2000_device *pcard = get_pcard(dev);
long wr_val; long wr_val;
struct kp2000_device *pcard;
int rv; int rv;
if (!pdev)
return -ENXIO;
pcard = pci_get_drvdata(pdev);
if (!pcard) if (!pcard)
return -ENXIO; return -ENXIO;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment