public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] mfd: intel-lpss: refactor PCI probe and common IRQ check
@ 2023-11-06 18:40 Andy Shevchenko
  2023-11-06 18:40 ` [PATCH v3 1/2] mfd: intel-lpss: Use PCI APIs instead of derefereincing Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Andy Shevchenko @ 2023-11-06 18:40 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Chen Ni, linux-kernel; +Cc: Lee Jones

The PCI code can be refactored to use respective PCI APIs instead of
direct dereference of struct pci_dev members.

With that, we may unshadow the error code that is promoted in the irq
field of info structure. PCI core shouldn't propagate 0 as a value
there, and in case it happens it reveals a bug somewhere else.

Changelog:

v2 -> v3:
1. Refactored PCI glue driver a bit (a new patch)
2. Updated commit message in the original patch

v1 -> v2:
1. Update commit message
2. Fix IRQ check in intel_lpcc_probe()

Andy Shevchenko (1):
  mfd: intel-lpss: Use PCI APIs instead of derefereincing

Chen Ni (1):
  mfd: intel-lpss: Amend IRQ check

 drivers/mfd/intel-lpss-pci.c | 8 ++++++--
 drivers/mfd/intel-lpss.c     | 5 ++++-
 2 files changed, 10 insertions(+), 3 deletions(-)

-- 
2.40.0.1.gaa8946217a0b


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

* [PATCH v3 1/2] mfd: intel-lpss: Use PCI APIs instead of derefereincing
  2023-11-06 18:40 [PATCH v3 0/2] mfd: intel-lpss: refactor PCI probe and common IRQ check Andy Shevchenko
@ 2023-11-06 18:40 ` Andy Shevchenko
  2023-11-23 11:17   ` Lee Jones
  2023-11-06 18:40 ` [PATCH v3 2/2] mfd: intel-lpss: Amend IRQ check Andy Shevchenko
  2023-11-23 11:17 ` [PATCH v3 0/2] mfd: intel-lpss: refactor PCI probe and common " Lee Jones
  2 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2023-11-06 18:40 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Chen Ni, linux-kernel; +Cc: Lee Jones

We have a few PCI APIs that may be used instead of direct dereferencibg,
Using them will also provide better error codes.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/mfd/intel-lpss-pci.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/intel-lpss-pci.c b/drivers/mfd/intel-lpss-pci.c
index ae5759200622..cf56cd3a40ee 100644
--- a/drivers/mfd/intel-lpss-pci.c
+++ b/drivers/mfd/intel-lpss-pci.c
@@ -37,13 +37,17 @@ static int intel_lpss_pci_probe(struct pci_dev *pdev,
 	if (ret)
 		return ret;
 
+	ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_LEGACY);
+	if (ret)
+		return ret;
+
 	info = devm_kmemdup(&pdev->dev, (void *)id->driver_data, sizeof(*info),
 			    GFP_KERNEL);
 	if (!info)
 		return -ENOMEM;
 
-	info->mem = &pdev->resource[0];
-	info->irq = pdev->irq;
+	info->mem = pci_resource_n(pdev, 0);
+	info->irq = pci_irq_vector(pdev, 0);
 
 	if (pci_match_id(ignore_resource_conflicts_ids, pdev))
 		info->ignore_resource_conflicts = true;
-- 
2.40.0.1.gaa8946217a0b


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

* [PATCH v3 2/2] mfd: intel-lpss: Amend IRQ check
  2023-11-06 18:40 [PATCH v3 0/2] mfd: intel-lpss: refactor PCI probe and common IRQ check Andy Shevchenko
  2023-11-06 18:40 ` [PATCH v3 1/2] mfd: intel-lpss: Use PCI APIs instead of derefereincing Andy Shevchenko
@ 2023-11-06 18:40 ` Andy Shevchenko
  2023-11-23 11:18   ` Lee Jones
  2023-11-23 11:17 ` [PATCH v3 0/2] mfd: intel-lpss: refactor PCI probe and common " Lee Jones
  2 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2023-11-06 18:40 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Chen Ni, linux-kernel; +Cc: Lee Jones

From: Chen Ni <nichen@iscas.ac.cn>

platform_get_irq() returns a negative error code to indicating an
error. All the same does pci_alloc_irq_vectors() and pci_irq_vector().
So in intel_lpss_probe() the erroneous IRQ should be better returned
as is.

The pci_alloc_irq_vectors() call and platform_get_irq() guarantee
that IRQ won't be 0, hence drop that check.

Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
[andy: updated commit message]
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/mfd/intel-lpss.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/intel-lpss.c b/drivers/mfd/intel-lpss.c
index 9591b354072a..4c9d0222751a 100644
--- a/drivers/mfd/intel-lpss.c
+++ b/drivers/mfd/intel-lpss.c
@@ -378,9 +378,12 @@ int intel_lpss_probe(struct device *dev,
 	struct intel_lpss *lpss;
 	int ret;
 
-	if (!info || !info->mem || info->irq <= 0)
+	if (!info || !info->mem)
 		return -EINVAL;
 
+	if (info->irq < 0)
+		return info->irq;
+
 	lpss = devm_kzalloc(dev, sizeof(*lpss), GFP_KERNEL);
 	if (!lpss)
 		return -ENOMEM;
-- 
2.40.0.1.gaa8946217a0b


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

* Re: [PATCH v3 0/2] mfd: intel-lpss: refactor PCI probe and common IRQ check
  2023-11-06 18:40 [PATCH v3 0/2] mfd: intel-lpss: refactor PCI probe and common IRQ check Andy Shevchenko
  2023-11-06 18:40 ` [PATCH v3 1/2] mfd: intel-lpss: Use PCI APIs instead of derefereincing Andy Shevchenko
  2023-11-06 18:40 ` [PATCH v3 2/2] mfd: intel-lpss: Amend IRQ check Andy Shevchenko
@ 2023-11-23 11:17 ` Lee Jones
  2 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2023-11-23 11:17 UTC (permalink / raw)
  To: Jarkko Nikula, Chen Ni, linux-kernel, Andy Shevchenko

On Mon, 06 Nov 2023 20:40:50 +0200, Andy Shevchenko wrote:
> The PCI code can be refactored to use respective PCI APIs instead of
> direct dereference of struct pci_dev members.
> 
> With that, we may unshadow the error code that is promoted in the irq
> field of info structure. PCI core shouldn't propagate 0 as a value
> there, and in case it happens it reveals a bug somewhere else.
> 
> [...]

Applied, thanks!

[1/2] mfd: intel-lpss: Use PCI APIs instead of derefereincing
      commit: e6951fb7878751aba4c147f1f206a2cbc05d1b9f
[2/2] mfd: intel-lpss: Amend IRQ check
      commit: ec791121b8ace33d2251b6c7a4d11a231ee51c05

--
Lee Jones [李琼斯]


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

* Re: [PATCH v3 1/2] mfd: intel-lpss: Use PCI APIs instead of derefereincing
  2023-11-06 18:40 ` [PATCH v3 1/2] mfd: intel-lpss: Use PCI APIs instead of derefereincing Andy Shevchenko
@ 2023-11-23 11:17   ` Lee Jones
  0 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2023-11-23 11:17 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Jarkko Nikula, Chen Ni, linux-kernel

On Mon, 06 Nov 2023, Andy Shevchenko wrote:

> We have a few PCI APIs that may be used instead of direct dereferencibg,
> Using them will also provide better error codes.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/mfd/intel-lpss-pci.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

Please use spell-check on your commit messages.

Let's not get complacent.

> diff --git a/drivers/mfd/intel-lpss-pci.c b/drivers/mfd/intel-lpss-pci.c
> index ae5759200622..cf56cd3a40ee 100644
> --- a/drivers/mfd/intel-lpss-pci.c
> +++ b/drivers/mfd/intel-lpss-pci.c
> @@ -37,13 +37,17 @@ static int intel_lpss_pci_probe(struct pci_dev *pdev,
>  	if (ret)
>  		return ret;
>  
> +	ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_LEGACY);
> +	if (ret)
> +		return ret;
> +
>  	info = devm_kmemdup(&pdev->dev, (void *)id->driver_data, sizeof(*info),
>  			    GFP_KERNEL);
>  	if (!info)
>  		return -ENOMEM;
>  
> -	info->mem = &pdev->resource[0];
> -	info->irq = pdev->irq;
> +	info->mem = pci_resource_n(pdev, 0);
> +	info->irq = pci_irq_vector(pdev, 0);
>  
>  	if (pci_match_id(ignore_resource_conflicts_ids, pdev))
>  		info->ignore_resource_conflicts = true;
> -- 
> 2.40.0.1.gaa8946217a0b
> 

-- 
Lee Jones [李琼斯]

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

* Re: [PATCH v3 2/2] mfd: intel-lpss: Amend IRQ check
  2023-11-06 18:40 ` [PATCH v3 2/2] mfd: intel-lpss: Amend IRQ check Andy Shevchenko
@ 2023-11-23 11:18   ` Lee Jones
  0 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2023-11-23 11:18 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Jarkko Nikula, Chen Ni, linux-kernel

On Mon, 06 Nov 2023, Andy Shevchenko wrote:

> From: Chen Ni <nichen@iscas.ac.cn>
> 
> platform_get_irq() returns a negative error code to indicating an
> error. All the same does pci_alloc_irq_vectors() and pci_irq_vector().
> So in intel_lpss_probe() the erroneous IRQ should be better returned
> as is.
> 
> The pci_alloc_irq_vectors() call and platform_get_irq() guarantee
> that IRQ won't be 0, hence drop that check.
> 
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
> [andy: updated commit message]

I reworded it further.

> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/mfd/intel-lpss.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mfd/intel-lpss.c b/drivers/mfd/intel-lpss.c
> index 9591b354072a..4c9d0222751a 100644
> --- a/drivers/mfd/intel-lpss.c
> +++ b/drivers/mfd/intel-lpss.c
> @@ -378,9 +378,12 @@ int intel_lpss_probe(struct device *dev,
>  	struct intel_lpss *lpss;
>  	int ret;
>  
> -	if (!info || !info->mem || info->irq <= 0)
> +	if (!info || !info->mem)
>  		return -EINVAL;
>  
> +	if (info->irq < 0)
> +		return info->irq;
> +
>  	lpss = devm_kzalloc(dev, sizeof(*lpss), GFP_KERNEL);
>  	if (!lpss)
>  		return -ENOMEM;
> -- 
> 2.40.0.1.gaa8946217a0b
> 

-- 
Lee Jones [李琼斯]

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

end of thread, other threads:[~2023-11-23 11:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-06 18:40 [PATCH v3 0/2] mfd: intel-lpss: refactor PCI probe and common IRQ check Andy Shevchenko
2023-11-06 18:40 ` [PATCH v3 1/2] mfd: intel-lpss: Use PCI APIs instead of derefereincing Andy Shevchenko
2023-11-23 11:17   ` Lee Jones
2023-11-06 18:40 ` [PATCH v3 2/2] mfd: intel-lpss: Amend IRQ check Andy Shevchenko
2023-11-23 11:18   ` Lee Jones
2023-11-23 11:17 ` [PATCH v3 0/2] mfd: intel-lpss: refactor PCI probe and common " Lee Jones

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