All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeremy Sowden <jeremy@azazel.net>
To: Linux Driver Project Developer List
	<driverdev-devel@linuxdriverproject.org>
Cc: Greg KH <gregkh@linuxfoundation.org>
Subject: [PATCH 7/8] staging: kpc2000: simplified kp2000_device retrieval in device attribute call-backs.
Date: Mon, 20 May 2019 20:52:33 +0100	[thread overview]
Message-ID: <20190520195243.917-7-jeremy@azazel.net> (raw)
In-Reply-To: <20190520195243.917-1-jeremy@azazel.net>

All the call-backs used the same formula to retrieve the pcard from dev:

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

  if (!pdev)
    return NULL;

  pcard = pci_get_drvdata(pdev);

Since to_pci_dev is a wrapper for container_of, it will not return NULL,
and since pci_get_drvdata just calls dev_get_drvdata on the dev member
of pdev, this is equivalent to:

  struct kp2000_device *pcard = dev_get_drvdata(&(container_of(dev, struct pci_dev, dev)->dev));

and we can simplify it to:

  struct kp2000_device *pcard = dev_get_drvdata(dev);

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 drivers/staging/kpc2000/kpc2000/core.c | 28 +++++++++-----------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index a8383e8159eb..f6043ef7b55b 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -25,20 +25,10 @@ static DEFINE_IDA(card_num_ida);
  * SysFS Attributes
  ******************************************************/
 
-static struct kp2000_device *get_pcard(struct device *dev)
-{
-	struct pci_dev *pdev = to_pci_dev(dev);
-
-	if (!pdev)
-		return NULL;
-
-	return pci_get_drvdata(pdev);
-}
-
 static ssize_t ssid_show(struct device *dev, struct device_attribute *attr,
 			 char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -50,7 +40,7 @@ static DEVICE_ATTR_RO(ssid);
 static ssize_t ddna_show(struct device *dev, struct device_attribute *attr,
 			 char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -62,7 +52,7 @@ static DEVICE_ATTR_RO(ddna);
 static ssize_t card_id_show(struct device *dev, struct device_attribute *attr,
 			    char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -74,7 +64,7 @@ static DEVICE_ATTR_RO(card_id);
 static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr,
 			   char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -86,7 +76,7 @@ static DEVICE_ATTR_RO(hw_rev);
 static ssize_t build_show(struct device *dev, struct device_attribute *attr,
 			  char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -98,7 +88,7 @@ static DEVICE_ATTR_RO(build);
 static ssize_t build_date_show(struct device *dev,
 			       struct device_attribute *attr, char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -110,7 +100,7 @@ static DEVICE_ATTR_RO(build_date);
 static ssize_t build_time_show(struct device *dev,
 			       struct device_attribute *attr, char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
 	if (!pcard)
 		return -ENXIO;
@@ -122,7 +112,7 @@ static DEVICE_ATTR_RO(build_time);
 static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
 			     char *buf)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	u64 val;
 
 	if (!pcard)
@@ -137,7 +127,7 @@ static ssize_t cpld_reconfigure(struct device *dev,
 				struct device_attribute *attr,
 				const char *buf, size_t count)
 {
-	struct kp2000_device *pcard = get_pcard(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	long wr_val;
 	int rv;
 
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  parent reply	other threads:[~2019-05-20 19:52 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-16 20:04 [PATCH 00/11] staging: kpc2000: another batch of fixes Jeremy Sowden
2019-05-16 20:04 ` [PATCH 01/11] staging: kpc2000: removed trailing white-space Jeremy Sowden
2019-05-16 20:04 ` [PATCH 02/11] staging: kpc2000: add separate show functions for kpc_uio_class device attributes Jeremy Sowden
2019-05-16 20:17   ` Matt Sickler
2019-05-16 20:46     ` Jeremy Sowden
2019-05-16 20:45   ` Greg KH
2019-05-16 21:06     ` Jeremy Sowden
2019-05-16 20:04 ` [PATCH 03/11] staging: kpc2000: define all kpc_uio_class device attributes as read-only Jeremy Sowden
2019-05-16 20:04 ` [PATCH 04/11] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
2019-05-16 20:04 ` [PATCH 05/11] staging: kpc2000: declare all kpc_uio_class device attributes as static Jeremy Sowden
2019-05-16 20:04 ` [PATCH 06/11] staging: kpc2000: use atomic_t to assign card numbers Jeremy Sowden
2019-05-16 20:04 ` [PATCH 07/11] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
2019-05-16 20:04 ` [PATCH 08/11] staging: kpc2000: add separate show functions for readable kp device attributes Jeremy Sowden
2019-05-16 20:04 ` [PATCH 09/11] staging: kpc2000: formatting fixes for " Jeremy Sowden
2019-05-16 20:04 ` [PATCH 10/11] staging: kpc2000: define read-only kp device attributes as read-only Jeremy Sowden
2019-05-16 20:04 ` [PATCH 11/11] staging: kpc2000: declare all kp device attributes as static Jeremy Sowden
2019-05-16 21:38 ` [PATCH v2 0/9] staging: kpc2000: another batch of fixes Jeremy Sowden
2019-05-16 21:38   ` [PATCH v2 1/9] staging: kpc2000: removed trailing white-space Jeremy Sowden
2019-05-17  7:30     ` Greg KH
2019-05-17 11:03       ` [PATCH v3 0/6] staging: kpc2000: another batch of fixes Jeremy Sowden
2019-05-17 11:03         ` [PATCH v3 1/6] staging: kpc2000: add separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
2019-05-17 11:03         ` [PATCH v3 2/6] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
2019-05-17 11:03         ` [PATCH v3 3/6] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
2019-05-17 11:54           ` Greg KH
2019-05-17 12:18             ` Jeremy Sowden
2019-05-21 11:23             ` Dan Carpenter
2019-05-22 12:30               ` Greg KH
2019-05-17 11:03         ` [PATCH v3 4/6] staging: kpc2000: formatting fixes for kp device attributes Jeremy Sowden
2019-05-17 11:03         ` [PATCH v3 5/6] staging: kpc2000: add separate show functions for readable kp device attributes, defined them as read-only, and declared them static Jeremy Sowden
2019-05-17 11:03         ` [PATCH v3 6/6] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
2019-05-17 11:50           ` Greg KH
2019-05-17 12:19             ` Jeremy Sowden
2019-05-20 19:52         ` [PATCH 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
2019-05-20 19:52           ` [PATCH 2/8] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
2019-05-20 19:52           ` [PATCH 3/8] staging: kpc2000: improved formatting of core.c Jeremy Sowden
2019-05-20 19:52           ` [PATCH 4/8] staging: kpc2000: added a helper to get struct kp2000_device from struct device Jeremy Sowden
2019-05-20 19:52           ` [PATCH 5/8] staging: kpc2000: added separate show functions for readable kp device attributes, defined them as read-only, and declared them static Jeremy Sowden
2019-05-20 19:52           ` [PATCH 6/8] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
2019-05-20 19:52           ` Jeremy Sowden [this message]
2019-05-20 19:52           ` [PATCH 8/8] staging: kpc2000: removed superfluous NULL checks from device attribute call-backs Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 0/8] staging: kpc2000: another batch of fixes Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 1/8] staging: kpc2000: added separate show functions for kpc_uio_class device attributes, defined them as read-only and declared them static Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 2/8] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 3/8] staging: kpc2000: improved formatting of core.c Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 4/8] staging: kpc2000: added a helper to get struct kp2000_device from struct device Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 5/8] staging: kpc2000: added separate show functions for readable kp device attributes, defined them as read-only, and declared them static Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 6/8] staging: kpc2000: use IDA to assign card numbers Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 7/8] staging: kpc2000: simplified kp2000_device retrieval in device attribute call-backs Jeremy Sowden
2019-05-20 19:52           ` [PATCH v4 8/8] staging: kpc2000: removed superfluous NULL checks from " Jeremy Sowden
2019-05-20 20:03         ` git-send-email cock-up [Was: Re: [PATCH v3 0/6] staging: kpc2000: another batch of fixes] Jeremy Sowden
2019-05-16 21:38   ` [PATCH v2 2/9] staging: kpc2000: add separate show functions for kpc_uio_class device attributes and defined them as read-only Jeremy Sowden
2019-05-17  7:15     ` Greg KH
2019-05-16 21:38   ` [PATCH v2 3/9] staging: kpc2000: declare all kpc_uio_class device attributes as static Jeremy Sowden
2019-05-17  7:15     ` Greg KH
2019-05-16 21:38   ` [PATCH v2 4/9] staging: kpc2000: removed two kpc_uio_class device attributes Jeremy Sowden
2019-05-17  7:14     ` Greg KH
2019-05-16 21:38   ` [PATCH v2 5/9] staging: kpc2000: use atomic_t to assign card numbers Jeremy Sowden
2019-05-16 22:14     ` Matt Sickler
2019-05-17  7:13       ` Greg KH
2019-05-16 21:38   ` [PATCH v2 6/9] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs Jeremy Sowden
2019-05-16 21:38   ` [PATCH v2 7/9] staging: kpc2000: formatting fixes for kp device attributes Jeremy Sowden
2019-05-16 21:38   ` [PATCH v2 8/9] staging: kpc2000: add separate show functions for readable kp device attributes, and defined them as read-only Jeremy Sowden
2019-05-16 21:38   ` [PATCH v2 9/9] staging: kpc2000: declare all kp device attributes as static Jeremy Sowden

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190520195243.917-7-jeremy@azazel.net \
    --to=jeremy@azazel.net \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.