mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [RFC PATCH] pci: Improve handling of constant id_table pointer
@ 2015-04-14 19:56 Uwe Kleine-König
  2015-04-15  5:27 ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Uwe Kleine-König @ 2015-04-14 19:56 UTC (permalink / raw)
  To: barebox; +Cc: Uwe Kleine-König

From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

This makes it more obvious why the cast is needed. Still looks ugly though.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/pci/bus.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 866ab08..fca4f5c 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -27,11 +27,11 @@ static int pci_match(struct device_d *dev, struct driver_d *drv)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
 	struct pci_driver *pdrv = to_pci_driver(drv);
-	struct pci_device_id *id;
+	const struct pci_device_id *id;
 
-	for (id = (struct pci_device_id *)pdrv->id_table; id->vendor; id++)
+	for (id = pdrv->id_table; id->vendor; id++)
 		if (pci_match_one_device(id, pdev)) {
-			dev->priv = id;
+			dev->priv = (/* non-const */ void *)id;
 			return 0;
 		}
 
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] pci: Improve handling of constant id_table pointer
  2015-04-14 19:56 [RFC PATCH] pci: Improve handling of constant id_table pointer Uwe Kleine-König
@ 2015-04-15  5:27 ` Sascha Hauer
  2015-04-15  7:09   ` Uwe Kleine-König
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2015-04-15  5:27 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: barebox, Uwe Kleine-König

On Tue, Apr 14, 2015 at 09:56:23PM +0200, Uwe Kleine-König wrote:
> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> 
> This makes it more obvious why the cast is needed. Still looks ugly though.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/pci/bus.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
> index 866ab08..fca4f5c 100644
> --- a/drivers/pci/bus.c
> +++ b/drivers/pci/bus.c
> @@ -27,11 +27,11 @@ static int pci_match(struct device_d *dev, struct driver_d *drv)
>  {
>  	struct pci_dev *pdev = to_pci_dev(dev);
>  	struct pci_driver *pdrv = to_pci_driver(drv);
> -	struct pci_device_id *id;
> +	const struct pci_device_id *id;
>  
> -	for (id = (struct pci_device_id *)pdrv->id_table; id->vendor; id++)
> +	for (id = pdrv->id_table; id->vendor; id++)
>  		if (pci_match_one_device(id, pdev)) {
> -			dev->priv = id;
> +			dev->priv = (/* non-const */ void *)id;

dev->priv shouldn't be used here, it's for private use of the device
driver. The following should fix it (untested).

Sascha

---------------------8<----------------------------

From 7977a32035787b500aa52e4a4241101e5aae7ad7 Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer@pengutronix.de>
Date: Wed, 15 Apr 2015 07:25:41 +0200
Subject: [PATCH] pci: Do not abuse dev->priv for storing data

dev->priv is for private use of the device driver, so do not
use it in the pci core. Instead, introduce a id field in struct
pci_device.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/pci/bus.c   | 6 +++---
 include/linux/pci.h | 1 +
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index d6c5496..9fec4d7 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -27,11 +27,11 @@ static int pci_match(struct device_d *dev, struct driver_d *drv)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
 	struct pci_driver *pdrv = to_pci_driver(drv);
-	struct pci_device_id *id;
+	const struct pci_device_id *id;
 
 	for (id = (struct pci_device_id *)pdrv->id_table; id->vendor; id++)
 		if (pci_match_one_device(id, pdev)) {
-			dev->priv = id;
+			pdev->id = id;
 			return 0;
 		}
 
@@ -43,7 +43,7 @@ static int pci_probe(struct device_d *dev)
 	struct pci_dev *pdev = to_pci_dev(dev);
 	struct pci_driver *pdrv = to_pci_driver(dev->driver);
 
-	return pdrv->probe(pdev, dev->priv);
+	return pdrv->probe(pdev, pdev->id);
 }
 
 static void pci_remove(struct device_d *dev)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index e422055..152ba10 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -92,6 +92,7 @@ struct pci_dev {
 	struct pci_bus	*bus;		/* bus this device is on */
 	struct pci_bus	*subordinate;	/* bus this device bridges to */
 	struct pci_slot	*slot;		/* Physical slot this device is in */
+	const struct pci_device_id *id;	/* the id this device matches */
 
 	struct device_d dev;
 
-- 
2.1.4

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] pci: Improve handling of constant id_table pointer
  2015-04-15  5:27 ` Sascha Hauer
@ 2015-04-15  7:09   ` Uwe Kleine-König
  0 siblings, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2015-04-15  7:09 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox, Uwe Kleine-König

On Wed, Apr 15, 2015 at 07:27:46AM +0200, Sascha Hauer wrote:
> diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
> index d6c5496..9fec4d7 100644
> --- a/drivers/pci/bus.c
> +++ b/drivers/pci/bus.c
> @@ -27,11 +27,11 @@ static int pci_match(struct device_d *dev, struct driver_d *drv)
>  {
>  	struct pci_dev *pdev = to_pci_dev(dev);
>  	struct pci_driver *pdrv = to_pci_driver(drv);
> -	struct pci_device_id *id;
> +	const struct pci_device_id *id;
>  
>  	for (id = (struct pci_device_id *)pdrv->id_table; id->vendor; id++)
This cast can then be dropped, too.

Otherwise,
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks
Uwe


-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-04-15  7:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-14 19:56 [RFC PATCH] pci: Improve handling of constant id_table pointer Uwe Kleine-König
2015-04-15  5:27 ` Sascha Hauer
2015-04-15  7:09   ` Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox