linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/6] include: linux: pci.h: introduce pci_get_device_by_id()
@ 2019-11-28 12:54 Enrico Weigelt, metux IT consult
  2019-11-28 12:54 ` [PATCH 2/6] mtd: maps: esb2rom: use pci_get_device_by_id() Enrico Weigelt, metux IT consult
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-11-28 12:54 UTC (permalink / raw)
  To: linux-kernel
  Cc: tim, james.morse, rrichter, jdelvare, linux, miquel.raynal,
	richard, vigneshr, linux-crypto, linux-edac, linux-hwmon,
	linux-mtd, linux-pci

From: Enrico Weigelt <info@metux.net>

Introduce a little helper for getting pci device via struct pci_device_id,
helpful for reducing a little bit of boilerplate.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
---
 include/linux/pci.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/pci.h b/include/linux/pci.h
index eb9f371aa77c..f6650b13724a 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1050,6 +1050,21 @@ struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
 
 struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
 			       struct pci_dev *from);
+
+/**
+ * pci_get_device_by_id() - get pci dev by struct pci_device_id
+ * @id: pci_device_id struct
+ *
+ * Retrieve PCI device by struct pci_device_id struct
+ *
+ * @return: pointer to struct pci_dev if sucessful, NULL otherwise
+ */
+static inline struct pci_dev *pci_get_device_by_id(
+	const struct pci_device_id *id)
+{
+	return pci_get_device(id->vendor, id->device, NULL);
+}
+
 struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device,
 			       unsigned int ss_vendor, unsigned int ss_device,
 			       struct pci_dev *from);
-- 
2.11.0


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

* [PATCH 2/6] mtd: maps: esb2rom: use pci_get_device_by_id()
  2019-11-28 12:54 [PATCH 1/6] include: linux: pci.h: introduce pci_get_device_by_id() Enrico Weigelt, metux IT consult
@ 2019-11-28 12:54 ` Enrico Weigelt, metux IT consult
  2019-11-28 12:54 ` [PATCH 3/6] mtd: maps: amd76xrom: " Enrico Weigelt, metux IT consult
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-11-28 12:54 UTC (permalink / raw)
  To: linux-kernel
  Cc: tim, james.morse, rrichter, jdelvare, linux, miquel.raynal,
	richard, vigneshr, linux-crypto, linux-edac, linux-hwmon,
	linux-mtd, linux-pci

From: Enrico Weigelt <info@metux.net>

Use the new pci_get_device_by_id() helper in order to reduce
a bit of boilerplate.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
---
 drivers/mtd/maps/esb2rom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/maps/esb2rom.c b/drivers/mtd/maps/esb2rom.c
index 5c27c6994896..0c638ac6ad82 100644
--- a/drivers/mtd/maps/esb2rom.c
+++ b/drivers/mtd/maps/esb2rom.c
@@ -421,7 +421,7 @@ static int __init init_esb2rom(void)
 	pdev = NULL;
 	for (id = esb2rom_pci_tbl; id->vendor; id++) {
 		printk(KERN_DEBUG "device id = %x\n", id->device);
-		pdev = pci_get_device(id->vendor, id->device, NULL);
+		pdev = pci_get_device_by_id(id);
 		if (pdev) {
 			printk(KERN_DEBUG "matched device = %x\n", id->device);
 			break;
-- 
2.11.0


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

* [PATCH 3/6] mtd: maps: amd76xrom: use pci_get_device_by_id()
  2019-11-28 12:54 [PATCH 1/6] include: linux: pci.h: introduce pci_get_device_by_id() Enrico Weigelt, metux IT consult
  2019-11-28 12:54 ` [PATCH 2/6] mtd: maps: esb2rom: use pci_get_device_by_id() Enrico Weigelt, metux IT consult
@ 2019-11-28 12:54 ` Enrico Weigelt, metux IT consult
  2019-11-28 12:54 ` [PATCH 4/6] edac: i82443bxgx_edac: " Enrico Weigelt, metux IT consult
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-11-28 12:54 UTC (permalink / raw)
  To: linux-kernel
  Cc: tim, james.morse, rrichter, jdelvare, linux, miquel.raynal,
	richard, vigneshr, linux-crypto, linux-edac, linux-hwmon,
	linux-mtd, linux-pci

Use the new pci_get_device_by_id() helper in order to reduce
a bit of boilerplate.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
---
 drivers/mtd/maps/amd76xrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/maps/amd76xrom.c b/drivers/mtd/maps/amd76xrom.c
index 462fadb56bdb..07a402dbdf44 100644
--- a/drivers/mtd/maps/amd76xrom.c
+++ b/drivers/mtd/maps/amd76xrom.c
@@ -323,7 +323,7 @@ static int __init init_amd76xrom(void)
 	const struct pci_device_id *id;
 	pdev = NULL;
 	for(id = amd76xrom_pci_tbl; id->vendor; id++) {
-		pdev = pci_get_device(id->vendor, id->device, NULL);
+		pdev = pci_get_device_by_id(id);
 		if (pdev) {
 			break;
 		}
-- 
2.11.0


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

* [PATCH 4/6] edac: i82443bxgx_edac: use pci_get_device_by_id()
  2019-11-28 12:54 [PATCH 1/6] include: linux: pci.h: introduce pci_get_device_by_id() Enrico Weigelt, metux IT consult
  2019-11-28 12:54 ` [PATCH 2/6] mtd: maps: esb2rom: use pci_get_device_by_id() Enrico Weigelt, metux IT consult
  2019-11-28 12:54 ` [PATCH 3/6] mtd: maps: amd76xrom: " Enrico Weigelt, metux IT consult
@ 2019-11-28 12:54 ` Enrico Weigelt, metux IT consult
  2019-11-28 13:28   ` Robert Richter
  2019-11-28 12:54 ` [PATCH 5/6] char: hw_random: intel-rng: " Enrico Weigelt, metux IT consult
  2019-11-28 12:54 ` [PATCH 6/6] (v3) drivers: hwmon: i5k_amb: simplify probing / device identification Enrico Weigelt, metux IT consult
  4 siblings, 1 reply; 10+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-11-28 12:54 UTC (permalink / raw)
  To: linux-kernel
  Cc: tim, james.morse, rrichter, jdelvare, linux, miquel.raynal,
	richard, vigneshr, linux-crypto, linux-edac, linux-hwmon,
	linux-mtd, linux-pci

Use the new pci_get_device_by_id() helper in order to reduce
a bit of boilerplate.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
---
 drivers/edac/i82443bxgx_edac.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
index a2ca929e2168..c01f51a4848c 100644
--- a/drivers/edac/i82443bxgx_edac.c
+++ b/drivers/edac/i82443bxgx_edac.c
@@ -407,15 +407,13 @@ static int __init i82443bxgx_edacmc_init(void)
 		goto fail0;
 
 	if (mci_pdev == NULL) {
-		const struct pci_device_id *id = &i82443bxgx_pci_tbl[0];
 		int i = 0;
 		i82443bxgx_registered = 0;
 
-		while (mci_pdev == NULL && id->vendor != 0) {
-			mci_pdev = pci_get_device(id->vendor,
-					id->device, NULL);
+		while (mci_pdev == NULL && i82443bxgx_pci_tbl[i].vendor) {
+			mci_pdev = pci_get_device_by_id(
+				&i82443bxgx_pci_tbl[i]);
 			i++;
-			id = &i82443bxgx_pci_tbl[i];
 		}
 		if (!mci_pdev) {
 			edac_dbg(0, "i82443bxgx pci_get_device fail\n");
-- 
2.11.0


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

* [PATCH 5/6] char: hw_random: intel-rng: use pci_get_device_by_id()
  2019-11-28 12:54 [PATCH 1/6] include: linux: pci.h: introduce pci_get_device_by_id() Enrico Weigelt, metux IT consult
                   ` (2 preceding siblings ...)
  2019-11-28 12:54 ` [PATCH 4/6] edac: i82443bxgx_edac: " Enrico Weigelt, metux IT consult
@ 2019-11-28 12:54 ` Enrico Weigelt, metux IT consult
  2019-11-28 12:54 ` [PATCH 6/6] (v3) drivers: hwmon: i5k_amb: simplify probing / device identification Enrico Weigelt, metux IT consult
  4 siblings, 0 replies; 10+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-11-28 12:54 UTC (permalink / raw)
  To: linux-kernel
  Cc: tim, james.morse, rrichter, jdelvare, linux, miquel.raynal,
	richard, vigneshr, linux-crypto, linux-edac, linux-hwmon,
	linux-mtd, linux-pci

Use the new pci_get_device_by_id() helper in order to reduce
a bit of boilerplate.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
---
 drivers/char/hw_random/intel-rng.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
index 290c880266bf..6b8d37a81166 100644
--- a/drivers/char/hw_random/intel-rng.c
+++ b/drivers/char/hw_random/intel-rng.c
@@ -335,8 +335,7 @@ static int __init mod_init(void)
 	struct intel_rng_hw *intel_rng_hw;
 
 	for (i = 0; !dev && pci_tbl[i].vendor; ++i)
-		dev = pci_get_device(pci_tbl[i].vendor, pci_tbl[i].device,
-				     NULL);
+		dev = pci_get_device_by_id(&pci_tbl[i]);
 
 	if (!dev)
 		goto out; /* Device not found. */
-- 
2.11.0


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

* [PATCH 6/6] (v3) drivers: hwmon: i5k_amb: simplify probing / device identification
  2019-11-28 12:54 [PATCH 1/6] include: linux: pci.h: introduce pci_get_device_by_id() Enrico Weigelt, metux IT consult
                   ` (3 preceding siblings ...)
  2019-11-28 12:54 ` [PATCH 5/6] char: hw_random: intel-rng: " Enrico Weigelt, metux IT consult
@ 2019-11-28 12:54 ` Enrico Weigelt, metux IT consult
  2019-11-28 14:21   ` Guenter Roeck
  4 siblings, 1 reply; 10+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-11-28 12:54 UTC (permalink / raw)
  To: linux-kernel
  Cc: tim, james.morse, rrichter, jdelvare, linux, miquel.raynal,
	richard, vigneshr, linux-crypto, linux-edac, linux-hwmon,
	linux-mtd, linux-pci

Simpilify the probing by putting all chip-specific data directly
into the pci match table, removing the redundant chipset_ids table.

Changes v3:
    * use pci_get_device_by_id() introduces by a previous patch
      of this queue

Changes v2:
    * use PCI_DEVICE_DATA() macro in the pci match table
    * directly pass the pci device id to i5k_channel_probe(),
      instead of computing it internally by extra offset parameter

Submitted: 2019-06-06
Signed-off-by: Enrico Weigelt <info@metux.net>
---
 drivers/hwmon/i5k_amb.c | 38 +++++++++++++++-----------------------
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/drivers/hwmon/i5k_amb.c b/drivers/hwmon/i5k_amb.c
index b09c39abd3a8..cb85607d104f 100644
--- a/drivers/hwmon/i5k_amb.c
+++ b/drivers/hwmon/i5k_amb.c
@@ -414,16 +414,14 @@ static int i5k_amb_add(void)
 }
 
 static int i5k_find_amb_registers(struct i5k_amb_data *data,
-					    unsigned long devid)
+				  const struct pci_device_id *devid)
 {
 	struct pci_dev *pcidev;
 	u32 val32;
 	int res = -ENODEV;
 
 	/* Find AMB register memory space */
-	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
-				devid,
-				NULL);
+	pcidev = pci_get_device_by_id(devid);
 	if (!pcidev)
 		return -ENODEV;
 
@@ -447,14 +445,15 @@ static int i5k_find_amb_registers(struct i5k_amb_data *data,
 	return res;
 }
 
-static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
+static int i5k_channel_probe(u16 *amb_present, unsigned int vendor,
+			     unsigned int device)
 {
 	struct pci_dev *pcidev;
 	u16 val16;
 	int res = -ENODEV;
 
 	/* Copy the DIMM presence map for these two channels */
-	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, NULL);
+	pcidev = pci_get_device(vendor, device, NULL);
 	if (!pcidev)
 		return -ENODEV;
 
@@ -473,23 +472,12 @@ static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
 	return res;
 }
 
-static struct {
-	unsigned long err;
-	unsigned long fbd0;
-} chipset_ids[]  = {
-	{ PCI_DEVICE_ID_INTEL_5000_ERR, PCI_DEVICE_ID_INTEL_5000_FBD0 },
-	{ PCI_DEVICE_ID_INTEL_5400_ERR, PCI_DEVICE_ID_INTEL_5400_FBD0 },
-	{ 0, 0 }
-};
-
-#ifdef MODULE
 static const struct pci_device_id i5k_amb_ids[] = {
-	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5000_ERR) },
-	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR) },
+	{ PCI_DEVICE_DATA(INTEL, 5000_ERR, PCI_DEVICE_ID_INTEL_5000_FBD0) },
+	{ PCI_DEVICE_DATA(INTEL, 5400_ERR, PCI_DEVICE_ID_INTEL_5400_FBD0) },
 	{ 0, }
 };
 MODULE_DEVICE_TABLE(pci, i5k_amb_ids);
-#endif
 
 static int i5k_amb_probe(struct platform_device *pdev)
 {
@@ -504,22 +492,26 @@ static int i5k_amb_probe(struct platform_device *pdev)
 	/* Figure out where the AMB registers live */
 	i = 0;
 	do {
-		res = i5k_find_amb_registers(data, chipset_ids[i].err);
+		res = i5k_find_amb_registers(data, &i5k_amb_ids[i]);
 		if (res == 0)
 			break;
 		i++;
-	} while (chipset_ids[i].err);
+	} while (i5k_amb_ids[i].device);
 
 	if (res)
 		goto err;
 
 	/* Copy the DIMM presence map for the first two channels */
-	res = i5k_channel_probe(&data->amb_present[0], chipset_ids[i].fbd0);
+	res = i5k_channel_probe(&data->amb_present[0],
+				i5k_amb_ids[i].vendor,
+				i5k_amb_ids[i].driver_data);
 	if (res)
 		goto err;
 
 	/* Copy the DIMM presence map for the optional second two channels */
-	i5k_channel_probe(&data->amb_present[2], chipset_ids[i].fbd0 + 1);
+	i5k_channel_probe(&data->amb_present[2],
+			  i5k_amb_ids[i].vendor,
+			  i5k_amb_ids[i].driver_data+1);
 
 	/* Set up resource regions */
 	reso = request_mem_region(data->amb_base, data->amb_len, DRVNAME);
-- 
2.11.0


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

* Re: [PATCH 4/6] edac: i82443bxgx_edac: use pci_get_device_by_id()
  2019-11-28 12:54 ` [PATCH 4/6] edac: i82443bxgx_edac: " Enrico Weigelt, metux IT consult
@ 2019-11-28 13:28   ` Robert Richter
  0 siblings, 0 replies; 10+ messages in thread
From: Robert Richter @ 2019-11-28 13:28 UTC (permalink / raw)
  To: Enrico Weigelt, metux IT consult
  Cc: linux-kernel, tim, james.morse, jdelvare, linux, miquel.raynal,
	richard, vigneshr, linux-crypto, linux-edac, linux-hwmon,
	linux-mtd, linux-pci

On 28.11.19 13:54:04, Enrico Weigelt, metux IT consult wrote:
> Use the new pci_get_device_by_id() helper in order to reduce
> a bit of boilerplate.

> -		while (mci_pdev == NULL && id->vendor != 0) {
> -			mci_pdev = pci_get_device(id->vendor,
> -					id->device, NULL);
> +		while (mci_pdev == NULL && i82443bxgx_pci_tbl[i].vendor) {
> +			mci_pdev = pci_get_device_by_id(
> +				&i82443bxgx_pci_tbl[i]);

I don't see how this is less boilerplate. Since this differs from the
typical pattern for this it is less readable now.

-Robert

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

* Re: [PATCH 6/6] (v3) drivers: hwmon: i5k_amb: simplify probing / device identification
  2019-11-28 12:54 ` [PATCH 6/6] (v3) drivers: hwmon: i5k_amb: simplify probing / device identification Enrico Weigelt, metux IT consult
@ 2019-11-28 14:21   ` Guenter Roeck
  2019-12-10 23:25     ` Bjorn Helgaas
  0 siblings, 1 reply; 10+ messages in thread
From: Guenter Roeck @ 2019-11-28 14:21 UTC (permalink / raw)
  To: Enrico Weigelt, metux IT consult, linux-kernel
  Cc: tim, james.morse, rrichter, jdelvare, miquel.raynal, richard,
	vigneshr, linux-crypto, linux-edac, linux-hwmon, linux-mtd,
	linux-pci

On 11/28/19 4:54 AM, Enrico Weigelt, metux IT consult wrote:
> Simpilify the probing by putting all chip-specific data directly
> into the pci match table, removing the redundant chipset_ids table.
> 
> Changes v3:
>      * use pci_get_device_by_id() introduces by a previous patch
>        of this queue
> 
> Changes v2:
>      * use PCI_DEVICE_DATA() macro in the pci match table
>      * directly pass the pci device id to i5k_channel_probe(),
>        instead of computing it internally by extra offset parameter
> 
> Submitted: 2019-06-06
> Signed-off-by: Enrico Weigelt <info@metux.net>

I don't immediately see how this is better. I am not even sure if it is correct.

Guenter

> ---
>   drivers/hwmon/i5k_amb.c | 38 +++++++++++++++-----------------------
>   1 file changed, 15 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/hwmon/i5k_amb.c b/drivers/hwmon/i5k_amb.c
> index b09c39abd3a8..cb85607d104f 100644
> --- a/drivers/hwmon/i5k_amb.c
> +++ b/drivers/hwmon/i5k_amb.c
> @@ -414,16 +414,14 @@ static int i5k_amb_add(void)
>   }
>   
>   static int i5k_find_amb_registers(struct i5k_amb_data *data,
> -					    unsigned long devid)
> +				  const struct pci_device_id *devid)
>   {
>   	struct pci_dev *pcidev;
>   	u32 val32;
>   	int res = -ENODEV;
>   
>   	/* Find AMB register memory space */
> -	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
> -				devid,
> -				NULL);
> +	pcidev = pci_get_device_by_id(devid);
>   	if (!pcidev)
>   		return -ENODEV;
>   
> @@ -447,14 +445,15 @@ static int i5k_find_amb_registers(struct i5k_amb_data *data,
>   	return res;
>   }
>   
> -static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
> +static int i5k_channel_probe(u16 *amb_present, unsigned int vendor,
> +			     unsigned int device)
>   {
>   	struct pci_dev *pcidev;
>   	u16 val16;
>   	int res = -ENODEV;
>   
>   	/* Copy the DIMM presence map for these two channels */
> -	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, NULL);
> +	pcidev = pci_get_device(vendor, device, NULL);
>   	if (!pcidev)
>   		return -ENODEV;
>   
> @@ -473,23 +472,12 @@ static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
>   	return res;
>   }
>   
> -static struct {
> -	unsigned long err;
> -	unsigned long fbd0;
> -} chipset_ids[]  = {
> -	{ PCI_DEVICE_ID_INTEL_5000_ERR, PCI_DEVICE_ID_INTEL_5000_FBD0 },
> -	{ PCI_DEVICE_ID_INTEL_5400_ERR, PCI_DEVICE_ID_INTEL_5400_FBD0 },
> -	{ 0, 0 }
> -};
> -
> -#ifdef MODULE
>   static const struct pci_device_id i5k_amb_ids[] = {
> -	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5000_ERR) },
> -	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR) },
> +	{ PCI_DEVICE_DATA(INTEL, 5000_ERR, PCI_DEVICE_ID_INTEL_5000_FBD0) },
> +	{ PCI_DEVICE_DATA(INTEL, 5400_ERR, PCI_DEVICE_ID_INTEL_5400_FBD0) },
>   	{ 0, }
>   };
>   MODULE_DEVICE_TABLE(pci, i5k_amb_ids);
> -#endif
>   
>   static int i5k_amb_probe(struct platform_device *pdev)
>   {
> @@ -504,22 +492,26 @@ static int i5k_amb_probe(struct platform_device *pdev)
>   	/* Figure out where the AMB registers live */
>   	i = 0;
>   	do {
> -		res = i5k_find_amb_registers(data, chipset_ids[i].err);
> +		res = i5k_find_amb_registers(data, &i5k_amb_ids[i]);
>   		if (res == 0)
>   			break;
>   		i++;
> -	} while (chipset_ids[i].err);
> +	} while (i5k_amb_ids[i].device);
>   
>   	if (res)
>   		goto err;
>   
>   	/* Copy the DIMM presence map for the first two channels */
> -	res = i5k_channel_probe(&data->amb_present[0], chipset_ids[i].fbd0);
> +	res = i5k_channel_probe(&data->amb_present[0],
> +				i5k_amb_ids[i].vendor,
> +				i5k_amb_ids[i].driver_data);
>   	if (res)
>   		goto err;
>   
>   	/* Copy the DIMM presence map for the optional second two channels */
> -	i5k_channel_probe(&data->amb_present[2], chipset_ids[i].fbd0 + 1);
> +	i5k_channel_probe(&data->amb_present[2],
> +			  i5k_amb_ids[i].vendor,
> +			  i5k_amb_ids[i].driver_data+1);
>   
>   	/* Set up resource regions */
>   	reso = request_mem_region(data->amb_base, data->amb_len, DRVNAME);
> 


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

* Re: [PATCH 6/6] (v3) drivers: hwmon: i5k_amb: simplify probing / device identification
  2019-11-28 14:21   ` Guenter Roeck
@ 2019-12-10 23:25     ` Bjorn Helgaas
  2020-01-08 10:16       ` Enrico Weigelt, metux IT consult
  0 siblings, 1 reply; 10+ messages in thread
From: Bjorn Helgaas @ 2019-12-10 23:25 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Enrico Weigelt, metux IT consult, linux-kernel, tim, james.morse,
	rrichter, jdelvare, miquel.raynal, richard, vigneshr,
	linux-crypto, linux-edac, linux-hwmon, linux-mtd, linux-pci

On Thu, Nov 28, 2019 at 06:21:31AM -0800, Guenter Roeck wrote:
> On 11/28/19 4:54 AM, Enrico Weigelt, metux IT consult wrote:
> > Simpilify the probing by putting all chip-specific data directly
> > into the pci match table, removing the redundant chipset_ids table.
> > 
> > Changes v3:
> >      * use pci_get_device_by_id() introduces by a previous patch
> >        of this queue
> > 
> > Changes v2:
> >      * use PCI_DEVICE_DATA() macro in the pci match table
> >      * directly pass the pci device id to i5k_channel_probe(),
> >        instead of computing it internally by extra offset parameter
> > 
> > Submitted: 2019-06-06
> > Signed-off-by: Enrico Weigelt <info@metux.net>
> 
> I don't immediately see how this is better. I am not even sure if it
> is correct.

I don't mind this, but:

  1) I don't maintain this file, so my opinion doesn't count much.

  2) I despise the pci_get_device() interfaces because they're
  inefficient, not hotplug-safe, they circumvent the device model
  claim mechanism, and it's hard to do the reference counting
  correctly.

  3) There are several things going on in this patch and it would be
  easier to read if you could split them into separate patches:

    - Removing the redundancy between chipset_ids[] and i5k_amb_ids[].
      This seems like a nice change.

    - The "chipset_ids[i].fbd0 + 1" thing was weird and the new
      ".driver_data + 1" is still weird.  Those are PCI device IDs,
      and addition is not a valid operation on those IDs.  IMHO both
      PCI_DEVICE_ID_INTEL_5000_FBD0 and PCI_DEVICE_ID_INTEL_5000_FBD1
      should be listed explicitly in the driver instead of trying to
      compute PCI_DEVICE_ID_INTEL_5000_FBD1.

    - Replacing the hard-coding of PCI_VENDOR_ID_INTEL with the vendor
      ID from i5k_amb_ids[] seems worthwhile and should be its own
      separate patch (if possible).

    - Changing to use pci_get_device_by_id().  This should be trivial
      to verify, like the other patches.

> > ---
> >   drivers/hwmon/i5k_amb.c | 38 +++++++++++++++-----------------------
> >   1 file changed, 15 insertions(+), 23 deletions(-)
> > 
> > diff --git a/drivers/hwmon/i5k_amb.c b/drivers/hwmon/i5k_amb.c
> > index b09c39abd3a8..cb85607d104f 100644
> > --- a/drivers/hwmon/i5k_amb.c
> > +++ b/drivers/hwmon/i5k_amb.c
> > @@ -414,16 +414,14 @@ static int i5k_amb_add(void)
> >   }
> >   static int i5k_find_amb_registers(struct i5k_amb_data *data,
> > -					    unsigned long devid)
> > +				  const struct pci_device_id *devid)
> >   {
> >   	struct pci_dev *pcidev;
> >   	u32 val32;
> >   	int res = -ENODEV;
> >   	/* Find AMB register memory space */
> > -	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
> > -				devid,
> > -				NULL);
> > +	pcidev = pci_get_device_by_id(devid);
> >   	if (!pcidev)
> >   		return -ENODEV;
> > @@ -447,14 +445,15 @@ static int i5k_find_amb_registers(struct i5k_amb_data *data,
> >   	return res;
> >   }
> > -static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
> > +static int i5k_channel_probe(u16 *amb_present, unsigned int vendor,
> > +			     unsigned int device)
> >   {
> >   	struct pci_dev *pcidev;
> >   	u16 val16;
> >   	int res = -ENODEV;
> >   	/* Copy the DIMM presence map for these two channels */
> > -	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, NULL);
> > +	pcidev = pci_get_device(vendor, device, NULL);
> >   	if (!pcidev)
> >   		return -ENODEV;
> > @@ -473,23 +472,12 @@ static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
> >   	return res;
> >   }
> > -static struct {
> > -	unsigned long err;
> > -	unsigned long fbd0;
> > -} chipset_ids[]  = {
> > -	{ PCI_DEVICE_ID_INTEL_5000_ERR, PCI_DEVICE_ID_INTEL_5000_FBD0 },
> > -	{ PCI_DEVICE_ID_INTEL_5400_ERR, PCI_DEVICE_ID_INTEL_5400_FBD0 },
> > -	{ 0, 0 }
> > -};
> > -
> > -#ifdef MODULE
> >   static const struct pci_device_id i5k_amb_ids[] = {
> > -	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5000_ERR) },
> > -	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR) },
> > +	{ PCI_DEVICE_DATA(INTEL, 5000_ERR, PCI_DEVICE_ID_INTEL_5000_FBD0) },
> > +	{ PCI_DEVICE_DATA(INTEL, 5400_ERR, PCI_DEVICE_ID_INTEL_5400_FBD0) },
> >   	{ 0, }
> >   };
> >   MODULE_DEVICE_TABLE(pci, i5k_amb_ids);
> > -#endif
> >   static int i5k_amb_probe(struct platform_device *pdev)
> >   {
> > @@ -504,22 +492,26 @@ static int i5k_amb_probe(struct platform_device *pdev)
> >   	/* Figure out where the AMB registers live */
> >   	i = 0;
> >   	do {
> > -		res = i5k_find_amb_registers(data, chipset_ids[i].err);
> > +		res = i5k_find_amb_registers(data, &i5k_amb_ids[i]);
> >   		if (res == 0)
> >   			break;
> >   		i++;
> > -	} while (chipset_ids[i].err);
> > +	} while (i5k_amb_ids[i].device);
> >   	if (res)
> >   		goto err;
> >   	/* Copy the DIMM presence map for the first two channels */
> > -	res = i5k_channel_probe(&data->amb_present[0], chipset_ids[i].fbd0);
> > +	res = i5k_channel_probe(&data->amb_present[0],
> > +				i5k_amb_ids[i].vendor,
> > +				i5k_amb_ids[i].driver_data);
> >   	if (res)
> >   		goto err;
> >   	/* Copy the DIMM presence map for the optional second two channels */
> > -	i5k_channel_probe(&data->amb_present[2], chipset_ids[i].fbd0 + 1);
> > +	i5k_channel_probe(&data->amb_present[2],
> > +			  i5k_amb_ids[i].vendor,
> > +			  i5k_amb_ids[i].driver_data+1);
> >   	/* Set up resource regions */
> >   	reso = request_mem_region(data->amb_base, data->amb_len, DRVNAME);
> > 
> 

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

* Re: [PATCH 6/6] (v3) drivers: hwmon: i5k_amb: simplify probing / device identification
  2019-12-10 23:25     ` Bjorn Helgaas
@ 2020-01-08 10:16       ` Enrico Weigelt, metux IT consult
  0 siblings, 0 replies; 10+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2020-01-08 10:16 UTC (permalink / raw)
  To: Bjorn Helgaas, Guenter Roeck
  Cc: Enrico Weigelt, metux IT consult, linux-kernel, tim, james.morse,
	rrichter, jdelvare, miquel.raynal, richard, vigneshr,
	linux-crypto, linux-edac, linux-hwmon, linux-mtd, linux-pci

On 11.12.19 00:25, Bjorn Helgaas wrote:

Hi,

>   2) I despise the pci_get_device() interfaces because they're
>   inefficient, not hotplug-safe, they circumvent the device model
>   claim mechanism, and it's hard to do the reference counting
>   correctly.

Agreed, but for that we'd have to edac and hwmo driver together into
one (or maybe a MFD). That would be a major rewrite, and I don't have
the necessary HW to test it.

>   3) There are several things going on in this patch and it would be
>   easier to read if you could split them into separate patches:
> 
>     - Removing the redundancy between chipset_ids[] and i5k_amb_ids[].
>       This seems like a nice change.
> 
>     - The "chipset_ids[i].fbd0 + 1" thing was weird and the new
>       ".driver_data + 1" is still weird.  Those are PCI device IDs,
>       and addition is not a valid operation on those IDs.  IMHO both
>       PCI_DEVICE_ID_INTEL_5000_FBD0 and PCI_DEVICE_ID_INTEL_5000_FBD1
>       should be listed explicitly in the driver instead of trying to
>       compute PCI_DEVICE_ID_INTEL_5000_FBD1.

Ok, good point.

>     - Replacing the hard-coding of PCI_VENDOR_ID_INTEL with the vendor
>       ID from i5k_amb_ids[] seems worthwhile and should be its own
>       separate patch (if possible).
> 
>     - Changing to use pci_get_device_by_id().  This should be trivial
>       to verify, like the other patches.

Ok, I'll try to split it up more clearly, once I've got some more spare
time.


--mtx

---
Enrico Weigelt, metux IT consult
Free software and Linux embedded engineering
info@metux.net -- +49-151-27565287

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

end of thread, other threads:[~2020-01-08 10:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-28 12:54 [PATCH 1/6] include: linux: pci.h: introduce pci_get_device_by_id() Enrico Weigelt, metux IT consult
2019-11-28 12:54 ` [PATCH 2/6] mtd: maps: esb2rom: use pci_get_device_by_id() Enrico Weigelt, metux IT consult
2019-11-28 12:54 ` [PATCH 3/6] mtd: maps: amd76xrom: " Enrico Weigelt, metux IT consult
2019-11-28 12:54 ` [PATCH 4/6] edac: i82443bxgx_edac: " Enrico Weigelt, metux IT consult
2019-11-28 13:28   ` Robert Richter
2019-11-28 12:54 ` [PATCH 5/6] char: hw_random: intel-rng: " Enrico Weigelt, metux IT consult
2019-11-28 12:54 ` [PATCH 6/6] (v3) drivers: hwmon: i5k_amb: simplify probing / device identification Enrico Weigelt, metux IT consult
2019-11-28 14:21   ` Guenter Roeck
2019-12-10 23:25     ` Bjorn Helgaas
2020-01-08 10:16       ` Enrico Weigelt, metux IT consult

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).