All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mISDN: Fix return values of the probe function
@ 2021-10-18 14:20 Zheyu Ma
  2021-10-18 17:06 ` Denis Kirjanov
  0 siblings, 1 reply; 3+ messages in thread
From: Zheyu Ma @ 2021-10-18 14:20 UTC (permalink / raw)
  To: isdn, davem; +Cc: netdev, linux-kernel, Zheyu Ma

During the process of driver probing, the probe function should return < 0
for failure, otherwise, the kernel will treat value > 0 as success.

Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
---
 drivers/isdn/hardware/mISDN/hfcpci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
index e501cb03f211..bd087cca1c1d 100644
--- a/drivers/isdn/hardware/mISDN/hfcpci.c
+++ b/drivers/isdn/hardware/mISDN/hfcpci.c
@@ -1994,14 +1994,14 @@ setup_hw(struct hfc_pci *hc)
 	pci_set_master(hc->pdev);
 	if (!hc->irq) {
 		printk(KERN_WARNING "HFC-PCI: No IRQ for PCI card found\n");
-		return 1;
+		return -EINVAL;
 	}
 	hc->hw.pci_io =
 		(char __iomem *)(unsigned long)hc->pdev->resource[1].start;
 
 	if (!hc->hw.pci_io) {
 		printk(KERN_WARNING "HFC-PCI: No IO-Mem for PCI card found\n");
-		return 1;
+		return -ENOMEM;
 	}
 	/* Allocate memory for FIFOS */
 	/* the memory needs to be on a 32k boundary within the first 4G */
@@ -2012,7 +2012,7 @@ setup_hw(struct hfc_pci *hc)
 	if (!buffer) {
 		printk(KERN_WARNING
 		       "HFC-PCI: Error allocating memory for FIFO!\n");
-		return 1;
+		return -ENOMEM;
 	}
 	hc->hw.fifos = buffer;
 	pci_write_config_dword(hc->pdev, 0x80, hc->hw.dmahandle);
@@ -2022,7 +2022,7 @@ setup_hw(struct hfc_pci *hc)
 		       "HFC-PCI: Error in ioremap for PCI!\n");
 		dma_free_coherent(&hc->pdev->dev, 0x8000, hc->hw.fifos,
 				  hc->hw.dmahandle);
-		return 1;
+		return -ENOMEM;
 	}
 
 	printk(KERN_INFO
-- 
2.17.6


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

* Re: [PATCH] mISDN: Fix return values of the probe function
  2021-10-18 14:20 [PATCH] mISDN: Fix return values of the probe function Zheyu Ma
@ 2021-10-18 17:06 ` Denis Kirjanov
  2021-10-18 23:15   ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Denis Kirjanov @ 2021-10-18 17:06 UTC (permalink / raw)
  To: Zheyu Ma, isdn, davem; +Cc: netdev, linux-kernel



10/18/21 5:20 PM, Zheyu Ma пишет:
> During the process of driver probing, the probe function should return < 0
> for failure, otherwise, the kernel will treat value > 0 as success.

setup_card() checks for the return value.
Thus it makes sense to submit the patch with net-next tag

> 
> Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
> ---
>   drivers/isdn/hardware/mISDN/hfcpci.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
> index e501cb03f211..bd087cca1c1d 100644
> --- a/drivers/isdn/hardware/mISDN/hfcpci.c
> +++ b/drivers/isdn/hardware/mISDN/hfcpci.c
> @@ -1994,14 +1994,14 @@ setup_hw(struct hfc_pci *hc)
>   	pci_set_master(hc->pdev);
>   	if (!hc->irq) {
>   		printk(KERN_WARNING "HFC-PCI: No IRQ for PCI card found\n");
> -		return 1;
> +		return -EINVAL;
>   	}
>   	hc->hw.pci_io =
>   		(char __iomem *)(unsigned long)hc->pdev->resource[1].start;
>   
>   	if (!hc->hw.pci_io) {
>   		printk(KERN_WARNING "HFC-PCI: No IO-Mem for PCI card found\n");
> -		return 1;
> +		return -ENOMEM;
>   	}
>   	/* Allocate memory for FIFOS */
>   	/* the memory needs to be on a 32k boundary within the first 4G */
> @@ -2012,7 +2012,7 @@ setup_hw(struct hfc_pci *hc)
>   	if (!buffer) {
>   		printk(KERN_WARNING
>   		       "HFC-PCI: Error allocating memory for FIFO!\n");
> -		return 1;
> +		return -ENOMEM;
>   	}
>   	hc->hw.fifos = buffer;
>   	pci_write_config_dword(hc->pdev, 0x80, hc->hw.dmahandle);
> @@ -2022,7 +2022,7 @@ setup_hw(struct hfc_pci *hc)
>   		       "HFC-PCI: Error in ioremap for PCI!\n");
>   		dma_free_coherent(&hc->pdev->dev, 0x8000, hc->hw.fifos,
>   				  hc->hw.dmahandle);
> -		return 1;
> +		return -ENOMEM;
>   	}
>   
>   	printk(KERN_INFO
> 

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

* Re: [PATCH] mISDN: Fix return values of the probe function
  2021-10-18 17:06 ` Denis Kirjanov
@ 2021-10-18 23:15   ` Jakub Kicinski
  0 siblings, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2021-10-18 23:15 UTC (permalink / raw)
  To: Denis Kirjanov; +Cc: Zheyu Ma, isdn, davem, netdev, linux-kernel

On Mon, 18 Oct 2021 20:06:51 +0300 Denis Kirjanov wrote:
> 10/18/21 5:20 PM, Zheyu Ma пишет:
> > During the process of driver probing, the probe function should return < 0
> > for failure, otherwise, the kernel will treat value > 0 as success.  
> 
> setup_card() checks for the return value.
> Thus it makes sense to submit the patch with net-next tag

setup_card() propagates the value returned by setup_hw() which in turn
gets propagated by hfc_probe() and hits local_pci_probe():

	/*
	 * Probe function should return < 0 for failure, 0 for success
	 * Treat values > 0 as success, but warn.
	 */
	pci_warn(pci_dev, "Driver probe function unexpectedly returned %d\n",
		 rc);
	return 0;

But you're right, this is a minor bug, hfc_remove_pci() checks if
driver data is already NULL so there will be no crash. Just a driver
bound to a device even though probe failed. Still net material tho.

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

end of thread, other threads:[~2021-10-18 23:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-18 14:20 [PATCH] mISDN: Fix return values of the probe function Zheyu Ma
2021-10-18 17:06 ` Denis Kirjanov
2021-10-18 23:15   ` Jakub Kicinski

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.