Skip to contentSkip to conversation

firewire: handle sysfs errors

PATCH In review Jeff Garzik 2 participants 6 messages Oct 10, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firewire: handle sysfs errors

Handle sysfs, driver core errors.

---

 drivers/ieee1394/nodemgr.c         |   36 ++++++++++++++++++++++++++++--------
drivers/ieee1394/nodemgr.c +28 -8
index 8e7b83f..8628e3f 100644
@@ -414,9 +414,11 @@ static BUS_ATTR(destroy_node, S_IWUSR | 
 
 static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, size_t count)
 {
+	int rc;
+
 	if (simple_strtoul(buf, NULL, 10) == 1)
-		bus_rescan_devices(&ieee1394_bus_type);
-	return count;
+		rc = bus_rescan_devices(&ieee1394_bus_type);
+	return rc < 0 ? rc : count;
 }
 static ssize_t fw_get_rescan(struct bus_type *bus, char *buf)
 {
@@ -576,13 +578,23 @@ static struct driver_attribute *const fw
 };
 
 
-static void nodemgr_create_drv_files(struct hpsb_protocol_driver *driver)
+static int nodemgr_create_drv_files(struct hpsb_protocol_driver *driver)
 {
 	struct device_driver *drv = &driver->driver;
-	int i;
+	int i, j, rc;
 
-	for (i = 0; i < ARRAY_SIZE(fw_drv_attrs); i++)
-		driver_create_file(drv, fw_drv_attrs[i]);
+	for (i = 0; i < ARRAY_SIZE(fw_drv_attrs); i++) {
+		rc = driver_create_file(drv, fw_drv_attrs[i]);
+		if (rc)
+			goto err_out;
+	}
+
+	return 0;
+
+err_out:
+	for (j = 0; j < i; j++)
+		driver_remove_file(drv, fw_drv_attrs[j]);
+	return rc;
 }
 
 
@@ -1166,9 +1178,17 @@ int hpsb_register_protocol(struct hpsb_p
 
 	/* This will cause a probe for devices */
 	ret = driver_register(&driver->driver);
-	if (!ret)
-		nodemgr_create_drv_files(driver);
+	if (ret)
+		return ret;
+
+	ret = nodemgr_create_drv_files(driver);
+	if (ret)
+		goto err_out;
+
+	return 0;
 
+err_out:
+	driver_unregister(&driver->driver);
 	return ret;
 }
 
#1 lore raw
Quoted 14 lines · Jeff Garzik

Handle sysfs, driver core errors.

---

 drivers/ieee1394/nodemgr.c         |   36 ++++++++++++++++++++++++++++--------
drivers/ieee1394/nodemgr.c +0 -0
index 8e7b83f..8628e3f 100644
@@ -414,9 +414,11 @@ static BUS_ATTR(destroy_node, S_IWUSR | 
 

drivers/ieee1394/nodemgr.c static BUS_ATTR(destroy_node, S_IWUSR | · line 422

Quoted 10 lines
drivers/ieee1394/nodemgr.c +4 -2
 static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, size_t count)
 {
+	int rc;
+
 	if (simple_strtoul(buf, NULL, 10) == 1)
-		bus_rescan_devices(&ieee1394_bus_type);
-	return count;
+		rc = bus_rescan_devices(&ieee1394_bus_type);
+	return rc < 0 ? rc : count;
 }

gcc 3.4.1-4mdk says:

drivers/ieee1394/nodemgr.c: In function `fw_set_rescan':
drivers/ieee1394/nodemgr.c:417: warning: 'rc' might be used uninitialized in this function

The rest of the patch looks OK.

I get a lot more warn_unused_result warnings at other places in ieee1394/nodemgr.c and ieee1394/hosts.c though. I could fix them all up and fix this new warning in fw_set_rescan too if you don't mind...

Signature · 3 lines
Stefan Richter
-=====-=-==- =-=- -=-=-
http://arcgraph.de/sr/
#2 lore raw
Quoted 5 lines · Stefan Richter

drivers/ieee1394/nodemgr.c: In function `fw_set_rescan':
drivers/ieee1394/nodemgr.c:417: warning: 'rc' might be used uninitialized in this function

The rest of the patch looks OK.

shoops, sorry

Quoted 3 lines

I get a lot more warn_unused_result warnings at other places in ieee1394/nodemgr.c and ieee1394/hosts.c though. I could fix them all up and fix this new warning in fw_set_rescan too if you don't mind...

That would be fantastic...

Jeff

#3 lore raw

PATCH 1/3 ieee1394: lock smaller region by host_num_alloc mutex

We need the mutex only around the iteration over existing hosts.

---
This prepares hosts.c for the following patch which adds checks of driver core errors.

drivers/ieee1394/hosts.c +1 -4
Index: linux-2.6.19-rc1/drivers/ieee1394/hosts.c
===================================================================
@@ -156,10 +156,9 @@ struct hpsb_host *hpsb_alloc_host(struct
 	h->speed_map = (u8 *)(h->csr.speed_map + 2);
 
 	mutex_lock(&host_num_alloc);
-
 	while (nodemgr_for_each_host(&hostnum, alloc_hostnum_cb))
 		hostnum++;
-
+	mutex_unlock(&host_num_alloc);
 	h->id = hostnum;
 
 	memcpy(&h->device, &nodemgr_dev_template_host, sizeof(h->device));
@@ -174,8 +173,6 @@ struct hpsb_host *hpsb_alloc_host(struct
 	class_device_register(&h->class_dev);
 	get_device(&h->device);
 
-	mutex_unlock(&host_num_alloc);
-
 	return h;
 }
 
#4 lore raw

PATCH 2/3 ieee1394: coding style in hosts.c

Some 80-columns pedantry, and touch up of a // comment.

---

drivers/ieee1394/hosts.c +11 -7
Index: linux-2.6.19-rc1/drivers/ieee1394/hosts.c
===================================================================
@@ -43,9 +43,10 @@ static void delayed_reset_bus(void * __r
 
 	CSR_SET_BUS_INFO_GENERATION(host->csr.rom, generation);
 	if (csr1212_generate_csr_image(host->csr.rom) != CSR1212_SUCCESS) {
-		/* CSR image creation failed, reset generation field and do not
-		 * issue a bus reset. */
-		CSR_SET_BUS_INFO_GENERATION(host->csr.rom, host->csr.generation);
+		/* CSR image creation failed.
+		 * Reset generation field and do not issue a bus reset. */
+		CSR_SET_BUS_INFO_GENERATION(host->csr.rom,
+					    host->csr.generation);
 		return;
 	}
 
@@ -53,7 +54,8 @@ static void delayed_reset_bus(void * __r
 
 	host->update_config_rom = 0;
 	if (host->driver->set_hw_config_rom)
-		host->driver->set_hw_config_rom(host, host->csr.rom->bus_info_data);
+		host->driver->set_hw_config_rom(host,
+						host->csr.rom->bus_info_data);
 
 	host->csr.gen_timestamp[host->csr.generation] = jiffies;
 	hpsb_reset_bus(host, SHORT_RESET);
@@ -69,7 +71,8 @@ static int dummy_devctl(struct hpsb_host
 	return -1;
 }
 
-static int dummy_isoctl(struct hpsb_iso *iso, enum isoctl_cmd command, unsigned long arg)
+static int dummy_isoctl(struct hpsb_iso *iso, enum isoctl_cmd command,
+			unsigned long arg)
 {
 	return -1;
 }
@@ -150,7 +151,7 @@ struct hpsb_host *hpsb_alloc_host(struct
 	init_timer(&h->timeout);
 	h->timeout.data = (unsigned long) h;
 	h->timeout.function = abort_timedouts;
-	h->timeout_interval = HZ / 20; // 50ms by default
+	h->timeout_interval = HZ / 20; /* 50ms, half of minimum SPLIT_TIMEOUT */
 
 	h->topology_map = h->csr.topology_map + 3;
 	h->speed_map = (u8 *)(h->csr.speed_map + 2);
@@ -225,7 +240,8 @@ int hpsb_update_config_rom_image(struct 
 	if (time_before(jiffies, host->csr.gen_timestamp[next_gen] + 60 * HZ))
 		/* Wait 60 seconds from the last time this generation number was
 		 * used. */
-		reset_delay = (60 * HZ) + host->csr.gen_timestamp[next_gen] - jiffies;
+		reset_delay =
+			(60 * HZ) + host->csr.gen_timestamp[next_gen] - jiffies;
 	else
 		/* Wait 1 second in case some other code wants to change the
 		 * Config ROM in the near future. */
#5 lore raw

PATCH 3/3 ieee1394: handle sysfs errors

Handle driver core errors with as much care as appropriate.

---

Supersedes patch "firewire: handle sysfs errors" by Jeff Garzik, posted on from 2006-10-10.

 drivers/ieee1394/hosts.c   |   18 ++--
 drivers/ieee1394/nodemgr.c |  149 ++++++++++++++++++++++++++-----------
 2 files changed, 118 insertions(+), 49 deletions(-)
drivers/ieee1394/hosts.c +12 -6
Index: linux-2.6.19-rc1/drivers/ieee1394/hosts.c
===================================================================
@@ -130,10 +130,8 @@ struct hpsb_host *hpsb_alloc_host(struct
 		return NULL;
 
 	h->csr.rom = csr1212_create_csr(&csr_bus_ops, CSR_BUS_INFO_SIZE, h);
-	if (!h->csr.rom) {
-		kfree(h);
-		return NULL;
-	}
+	if (!h->csr.rom)
+		goto fail;
 
 	h->hostdata = h + 1;
 	h->driver = drv;
@@ -172,11 +170,19 @@ struct hpsb_host *hpsb_alloc_host(struct
 	h->class_dev.class = &hpsb_host_class;
 	snprintf(h->class_dev.class_id, BUS_ID_SIZE, "fw-host%d", h->id);
 
-	device_register(&h->device);
-	class_device_register(&h->class_dev);
+	if (device_register(&h->device))
+		goto fail;
+	if (class_device_register(&h->class_dev)) {
+		device_unregister(&h->device);
+		goto fail;
+	}
 	get_device(&h->device);
 
 	return h;
+
+fail:
+	kfree(h);
+	return NULL;
 }
 
 int hpsb_add_host(struct hpsb_host *host)
drivers/ieee1394/nodemgr.c +106 -43

255 lines not on this page · raw message