Skip to contentSkip to conversation

cciss: return 0 from driver probe function on success, not 1

PATCH In review Stephen M. Cameron 4 participants 9 messages Oct 29, 2013 – Nov 1, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cciss: return 0 from driver probe function on success, not 1

From: Stephen M. Cameron <[email protected]>

A return value of 1 is interpreted as an error

---
 drivers/block/cciss.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/block/cciss.c +1 -1
index edfa251..0c004ac 100644
@@ -5183,7 +5183,7 @@ reinit_after_soft_reset:
 	rebuild_lun_table(h, 1, 0);
 	cciss_engage_scsi(h);
 	h->busy_initializing = 0;
-	return 1;
+	return 0;
 
 clean4:
 	cciss_free_cmd_pool(h);
maintainer
#1 lore raw
Quoted 15 lines · Stephen M. Cameron

From: Stephen M. Cameron <[email protected]>

A return value of 1 is interpreted as an error

---
 drivers/block/cciss.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/block/cciss.c +0 -0
index edfa251..0c004ac 100644

drivers/block/cciss.c reinit_after_soft_reset: · line 5189

Quoted 8 lines
drivers/block/cciss.c +1 -1
@@ -5183,7 +5183,7 @@ reinit_after_soft_reset:
 	rebuild_lun_table(h, 1, 0);
 	cciss_engage_scsi(h);
 	h->busy_initializing = 0;
-	return 1;
+	return 0;
 
 clean4:
 	cciss_free_cmd_pool(h);

How did this ever work?

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 21 lines · On Tue, 29 Oct 2013 12:58:09 -0600 Jens Axboe <[email protected]> wrote:
Quoted 20 lines · Stephen M. Cameron

From: Stephen M. Cameron <[email protected]>

A return value of 1 is interpreted as an error

---
 drivers/block/cciss.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/block/cciss.c +1 -1
index edfa251..0c004ac 100644
@@ -5183,7 +5183,7 @@ reinit_after_soft_reset:
 	rebuild_lun_table(h, 1, 0);
 	cciss_engage_scsi(h);
 	h->busy_initializing = 0;
-	return 1;
+	return 0;
 
Quoted 5 lines

drivers/block/cciss.c reinit_after_soft_reset: · line 5189

Quoted 3 lines
drivers/block/cciss.c +0 -0
 clean4:
 	cciss_free_cmd_pool(h);

How did this ever work?

Beats me. local_pci_probe() does

	rc = pci_drv->probe(pci_dev, ddi->id);
	if (rc) {
		pci_dev->driver = NULL;
		pm_runtime_put_sync(dev);
	}
	return rc;

shrug, maybe this ->probe somehow has a different caller which checks for <0.

While we're there...

From: Andrew Morton <[email protected]>
Subject: drivers/block/cciss.c:cciss_init_one(): use proper errnos

pci_driver.probe should return a meaningful errno, not -1.

Cc Jens Axboe <[email protected]>
Cc Stephen M. Cameron <[email protected]>

---

 drivers/block/cciss.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/cciss.c renamed from drivers/block/cciss.c~drivers-block-ccissc-cciss_init_one-use-proper-errnos +2 -2
diff -puN drivers/block/cciss.c~drivers-block-ccissc-cciss_init_one-use-proper-errnos drivers/block/cciss.c
@@ -5004,7 +5004,7 @@ reinit_after_soft_reset:
 
 	i = alloc_cciss_hba(pdev);
 	if (i < 0)
-		return -1;
+		return -ENOMEM;
 
 	h = hba[i];
 	h->pdev = pdev;
@@ -5205,7 +5205,7 @@ clean_no_release_regions:
 	 */
 	pci_set_drvdata(pdev, NULL);
 	free_hba(h);
-	return -1;
+	return -ENODEV;
 }
 
 static void cciss_shutdown(struct pci_dev *pdev)

_

#3 lore raw
Quoted 38 lines · Andrew Morton
Quoted 21 lines · On Tue, 29 Oct 2013 12:58:09 -0600 Jens Axboe <[email protected]> wrote:
Quoted 20 lines · Stephen M. Cameron

From: Stephen M. Cameron <[email protected]>

A return value of 1 is interpreted as an error

---
 drivers/block/cciss.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/block/cciss.c +1 -1
index edfa251..0c004ac 100644
@@ -5183,7 +5183,7 @@ reinit_after_soft_reset:
 	rebuild_lun_table(h, 1, 0);
 	cciss_engage_scsi(h);
 	h->busy_initializing = 0;
-	return 1;
+	return 0;
 
Quoted 5 lines

drivers/block/cciss.c reinit_after_soft_reset: · line 5189

Quoted 3 lines
drivers/block/cciss.c +0 -0
 clean4:
 	cciss_free_cmd_pool(h);

How did this ever work?

Beats me. local_pci_probe() does

	rc = pci_drv->probe(pci_dev, ddi->id);
	if (rc) {
		pci_dev->driver = NULL;
		pm_runtime_put_sync(dev);
	}
	return rc;
Quoted 2 lines

shrug, maybe this ->probe somehow has a different caller which checks for <0.

Older kernels (eg: http://lxr.linux.no/#linux+v2.6.32.61/drivers/pci/pci-driver.c ) had different code:

330__pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev) 331{
332 const struct pci_device_id *id;
333 int error = 0;
334
335 if (!pci_dev->driver && drv->probe) {
336 error = -ENODEV;
337
338 id = pci_match_device(drv, pci_dev);
339 if (id)
340 error = pci_call_probe(drv, pci_dev, id);
341 if (error >= 0) {
342 pci_dev->driver = drv;
343 error = 0;
344 }
345 }
346 return error;
347}

Quoted 38 lines

While we're there...

From: Andrew Morton <[email protected]>
Subject: drivers/block/cciss.c:cciss_init_one(): use proper errnos

pci_driver.probe should return a meaningful errno, not -1.

Cc Jens Axboe <[email protected]>
Cc Stephen M. Cameron <[email protected]>

---

 drivers/block/cciss.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -puN drivers/block/cciss.c~drivers-block-ccissc-cciss_init_one-use-proper-errnos drivers/block/cciss.c

drivers/block/cciss.c renamed from drivers/block/cciss.c~drivers-block-ccissc-cciss_init_one-use-proper-errnos +2 -2
@@ -5004,7 +5004,7 @@ reinit_after_soft_reset:
 
 	i = alloc_cciss_hba(pdev);
 	if (i < 0)
-		return -1;
+		return -ENOMEM;
 
 	h = hba[i];
 	h->pdev = pdev;
@@ -5205,7 +5205,7 @@ clean_no_release_regions:
 	 */
 	pci_set_drvdata(pdev, NULL);
 	free_hba(h);
-	return -1;
+	return -ENODEV;
 }
 
 static void cciss_shutdown(struct pci_dev *pdev)
Quoted 1 line

_

Thanks.

-- steve

#4 lore raw
Quoted 27 lines · On Thu, 31 Oct 2013 16:54:44 -0500 [email protected] wrote:
Quoted 11 lines
Quoted 1 line

How did this ever work?

Beats me. local_pci_probe() does

	rc = pci_drv->probe(pci_dev, ddi->id);
	if (rc) {
		pci_dev->driver = NULL;
		pm_runtime_put_sync(dev);
	}
	return rc;
Quoted 2 lines

shrug, maybe this ->probe somehow has a different caller which checks for <0.

Older kernels (eg: http://lxr.linux.no/#linux+v2.6.32.61/drivers/pci/pci-driver.c ) had different code:

330__pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev) 331{
332 const struct pci_device_id *id;
333 int error = 0;
334
335 if (!pci_dev->driver && drv->probe) {
336 error = -ENODEV;
337
338 id = pci_match_device(drv, pci_dev);
339 if (id)

Quoted 8 lines

340 error = pci_call_probe(drv, pci_dev, id);
341 if (error >= 0) {
342 pci_dev->driver = drv;
343 error = 0;
344 }
345 }
346 return error;
347}

So cciss is presently kompletely kaput? If so, the kapputting code is present in 3.9 and probably earlier, so this patch is needed in 3.12 and -stable. Or if not, what?

(Playing question and answer like this is a bad way of writing a changelog btw - all this stuff should have been right there in the v1 changelog).

#5 lore raw
Quoted 35 lines · Andrew Morton
Quoted 25 lines · On Thu, 31 Oct 2013 16:54:44 -0500 [email protected] wrote:
Quoted 10 lines
Quoted 1 line

How did this ever work?

Beats me. local_pci_probe() does

	rc = pci_drv->probe(pci_dev, ddi->id);
	if (rc) {
		pci_dev->driver = NULL;
		pm_runtime_put_sync(dev);
	}
	return rc;
Quoted 2 lines

shrug, maybe this ->probe somehow has a different caller which checks for <0.

Older kernels (eg: http://lxr.linux.no/#linux+v2.6.32.61/drivers/pci/pci-driver.c ) had different code:

330__pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev) 331{
332 const struct pci_device_id *id;
333 int error = 0;
334
335 if (!pci_dev->driver && drv->probe) {
336 error = -ENODEV;
337
338 id = pci_match_device(drv, pci_dev);
339 if (id)

Quoted 8 lines

340 error = pci_call_probe(drv, pci_dev, id);
341 if (error >= 0) {
342 pci_dev->driver = drv;
343 error = 0;
344 }
345 }
346 return error;
347}

Quoted 3 lines

So cciss is presently kompletely kaput? If so, the kapputting code is present in 3.9 and probably earlier, so this patch is needed in 3.12 and -stable. Or if not, what?

Steve posted similar patch for hpsa too and I'm sure someone would notice when the hpsa driver was kaput. If I understand it correctly the driver works with some limitation - rmmod doesn't work for example.

The problem in kernel is that the error handling in local_pci_probe and in __pci_device_probe is different for ret values > 0,
so we should fix it somewhere so it is in sync.
The documentation states that the probe function should return zero on success so what about this -

This would bring the handling to sync

drivers/pci/pci-driver.c +0 -2
index 98f7b9b..200a071 100644
@@ -317,8 +317,6 @@ __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev)
 		id = pci_match_device(drv, pci_dev);
 		if (id)
 			error = pci_call_probe(drv, pci_dev, id);
-		if (error >= 0)
-			error = 0;
 	}
 	return error;
 }
Quoted 10 lines

(Playing question and answer like this is a bad way of writing a changelog btw - all this stuff should have been right there in the v1 changelog).

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#6 lore raw
Quoted 12 lines · On Fri, 01 Nov 2013 14:06:45 +0100 Tomas Henzl <[email protected]> wrote:

The problem in kernel is that the error handling in local_pci_probe and in __pci_device_probe is different for ret values > 0,
so we should fix it somewhere so it is in sync.
The documentation states that the probe function should return zero on success so what about this -

This would bring the handling to sync

drivers/pci/pci-driver.c +0 -0
index 98f7b9b..200a071 100644

drivers/pci/pci-driver.c __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev) · line 322

Quoted 8 lines
drivers/pci/pci-driver.c +0 -2
@@ -317,8 +317,6 @@ __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev)
 		id = pci_match_device(drv, pci_dev);
 		if (id)
 			error = pci_call_probe(drv, pci_dev, id);
-		if (error >= 0)
-			error = 0;
 	}
 	return error;
 }

ah, there it is.

This change would turn semi-kaput drivers into kaput-kaput drivers. It would be better to add a runtime warning here so those drivers get fixed. Such a warning would need to reliably identify the offending probe function so a simple WARN_ON() wouldn't be sufficient.

#7 lore raw
Quoted 25 lines · Andrew Morton
Quoted 12 lines · On Fri, 01 Nov 2013 14:06:45 +0100 Tomas Henzl <[email protected]> wrote:

The problem in kernel is that the error handling in local_pci_probe and in __pci_device_probe is different for ret values > 0,
so we should fix it somewhere so it is in sync.
The documentation states that the probe function should return zero on success so what about this -

This would bring the handling to sync

drivers/pci/pci-driver.c +0 -0
index 98f7b9b..200a071 100644

drivers/pci/pci-driver.c __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev) · line 322

Quoted 8 lines
drivers/pci/pci-driver.c +0 -2
@@ -317,8 +317,6 @@ __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev)
 		id = pci_match_device(drv, pci_dev);
 		if (id)
 			error = pci_call_probe(drv, pci_dev, id);
-		if (error >= 0)
-			error = 0;
 	}
 	return error;
 }

ah, there it is.

Quoted 5 lines

This change would turn semi-kaput drivers into kaput-kaput drivers. It would be better to add a runtime warning here so those drivers get fixed. Such a warning would need to reliably identify the offending probe function so a simple WARN_ON() wouldn't be sufficient.

FWIW, I just booted up with the following change:

drivers/pci/pci-driver.c +8 -1
index 98f7b9b..ef71bb5 100644
@@ -264,9 +264,16 @@ static long local_pci_probe(void *_ddi)
 	pm_runtime_get_sync(dev);
 	pci_dev->driver = pci_drv;
 	rc = pci_drv->probe(pci_dev, ddi->id);
-	if (rc) {
+	if (rc < 0) {
 		pci_dev->driver = NULL;
 		pm_runtime_put_sync(dev);
+	} else {
+		if (rc > 0) {
+			dev_warn(dev,
+				"Driver probe function returned %d, greater than 0\n", rc);
+			rc = 0;
+			
+		}
 	}
 	return rc;
 }

And,

[scameron@localhost linux-3.12-rc6]$ dmesg | grep 'Driver probe' [scameron@localhost linux-3.12-rc6]$

Not that it means all that much since I don't have hardware for the majority of drivers, obviously.

I think the above should make drivers with probe functions returning > 0 "work" again, but with a warning.

The question would be, are there drivers which return > 0 and by this value intend to convey that the probe function has failed?

-- steve

#8 lore raw
Quoted 61 lines · On 11/01/2013 03:08 PM, [email protected] wrote:
Quoted 24 lines · Andrew Morton
Quoted 12 lines · On Fri, 01 Nov 2013 14:06:45 +0100 Tomas Henzl <[email protected]> wrote:

The problem in kernel is that the error handling in local_pci_probe and in __pci_device_probe is different for ret values > 0,
so we should fix it somewhere so it is in sync.
The documentation states that the probe function should return zero on success so what about this -

This would bring the handling to sync

drivers/pci/pci-driver.c +0 -0
index 98f7b9b..200a071 100644

drivers/pci/pci-driver.c __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev) · line 322

Quoted 8 lines
drivers/pci/pci-driver.c +0 -2
@@ -317,8 +317,6 @@ __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev)
 		id = pci_match_device(drv, pci_dev);
 		if (id)
 			error = pci_call_probe(drv, pci_dev, id);
-		if (error >= 0)
-			error = 0;
 	}
 	return error;
 }

ah, there it is.

Quoted 5 lines

This change would turn semi-kaput drivers into kaput-kaput drivers. It would be better to add a runtime warning here so those drivers get fixed. Such a warning would need to reliably identify the offending probe function so a simple WARN_ON() wouldn't be sufficient.

FWIW, I just booted up with the following change:

drivers/pci/pci-driver.c +8 -1
index 98f7b9b..ef71bb5 100644
@@ -264,9 +264,16 @@ static long local_pci_probe(void *_ddi)
 	pm_runtime_get_sync(dev);
 	pci_dev->driver = pci_drv;
 	rc = pci_drv->probe(pci_dev, ddi->id);
-	if (rc) {
+	if (rc < 0) {
 		pci_dev->driver = NULL;
 		pm_runtime_put_sync(dev);
+	} else {
+		if (rc > 0) {
+			dev_warn(dev,
+				"Driver probe function returned %d, greater than 0\n", rc);
+			rc = 0;
+			
+		}
 	}
 	return rc;
 }

And,

[scameron@localhost linux-3.12-rc6]$ dmesg | grep 'Driver probe' [scameron@localhost linux-3.12-rc6]$

Quoted 8 lines

Not that it means all that much since I don't have hardware for the majority of drivers, obviously.

I think the above should make drivers with probe functions returning > 0 "work" again, but with a warning.

The question would be, are there drivers which return > 0 and by this value intend to convey that the probe function has failed?

I think that this is unlikely and the patch is fine, but I can't speak for the drivers..

Please repost your patch so it gets more attention than in this thread.

Quoted 8 lines

-- steve

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/