From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id D14D01BF299 for ; Tue, 21 May 2019 10:35:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id C944685E6F for ; Tue, 21 May 2019 10:35:30 +0000 (UTC) Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zWi-U8dyjWCe for ; Tue, 21 May 2019 10:35:29 +0000 (UTC) Received: from kadath.azazel.net (kadath.azazel.net [81.187.231.250]) by fraxinus.osuosl.org (Postfix) with ESMTPS id C31C985E69 for ; Tue, 21 May 2019 10:35:28 +0000 (UTC) From: Jeremy Sowden Subject: [PATCH v6 2/6] staging: kpc2000: added a helper to get struct kp2000_device from struct device. Date: Tue, 21 May 2019 11:35:20 +0100 Message-Id: <20190521103524.2176-3-jeremy@azazel.net> In-Reply-To: <20190521103524.2176-1-jeremy@azazel.net> References: <20190521103524.2176-1-jeremy@azazel.net> MIME-Version: 1.0 List-Id: Linux Driver Project Developer List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: driverdev-devel-bounces@linuxdriverproject.org Sender: "devel" To: Linux Driver Project Developer List Cc: Greg KH 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: Jeremy Sowden --- drivers/staging/kpc2000/kpc2000/core.c | 29 ++++++++++++-------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c index f1735237cfb6..e58bddec87ee 100644 --- a/drivers/staging/kpc2000/kpc2000/core.c +++ b/drivers/staging/kpc2000/kpc2000/core.c @@ -29,15 +29,21 @@ * SysFS Attributes ******************************************************/ -static ssize_t show_attr(struct device *dev, struct device_attribute *attr, - char *buf) +static struct kp2000_device *get_pcard(struct device *dev) { struct pci_dev *pdev = to_pci_dev(dev); - struct kp2000_device *pcard; if (!pdev) - return -ENXIO; - pcard = pci_get_drvdata(pdev); + return NULL; + + 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) return -ENXIO; @@ -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, struct device_attribute *attr, char *buf) { - struct pci_dev *pdev = to_pci_dev(dev); - struct kp2000_device *pcard; + struct kp2000_device *pcard = get_pcard(dev); u64 val; - if (!pdev) - return -ENXIO; - - pcard = pci_get_drvdata(pdev); if (!pcard) return -ENXIO; @@ -91,14 +92,10 @@ static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct pci_dev *pdev = to_pci_dev(dev); + struct kp2000_device *pcard = get_pcard(dev); long wr_val; - struct kp2000_device *pcard; int rv; - if (!pdev) - return -ENXIO; - pcard = pci_get_drvdata(pdev); if (!pcard) return -ENXIO; -- 2.20.1 _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel