GIT bf9bc053512d564232dde3276925f1c94cba969c git+ssh://master.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6.git commit Author: Stefan Richter Date: Sun Oct 29 19:58:25 2006 +0100 ieee1394: ohci1394: proper log messages in suspend and resume - correct thinko in one of my last commits: cannot use PRINT macro with ohci == NULL - add log messages on ohci == NULL and on pci_enable_device != 0 - update log macros from patch "revert fail on error in suspend" to use PRINT and DBGMSG where possible Signed-off-by: Stefan Richter commit 346f5c7ee7fa4ebee0e4c96415a7e59716bfa1d0 Author: Stefan Richter Date: Sun Oct 29 19:52:49 2006 +0100 ieee1394: ohci1394: revert fail on error in suspend Some errors during preparation for suspended state can be skipped with a warning instead of a failure of the whole suspend transition, notably an error in pci_set_power_state. Signed-off-by: Stefan Richter commit 5e654928a910e4223f3043c9b4e77f7964523655 Author: Stefan Richter Date: Sun Oct 22 16:16:27 2006 +0200 ieee1394: nodemgr: revise semaphore protection of driver core data - The list "struct class.children" is supposed to be protected by class.sem, not by class.subsys.rwsem. - nodemgr_remove_uds() iterated over nodemgr_ud_class.children without proper protection. This was never observed as a bug since the code is usually only accessed by knodemgrd. All knodemgrds are currently globally serialized. But userspace can trigger this code too by writing to /sys/bus/ieee1394/destroy_node. - Clean up access to the FireWire bus type's subsys.rwsem: Access it uniformly via ieee1394_bus_type. Shrink rwsem protected regions where possible. Expand them where necessary. The latter wasn't a problem so far because knodemgr is globally serialized. This should harden the interaction of ieee1394 with sysfs and lay ground for deserialized operation of multiple knodemgrds and for implementation of subthreads for parallelized scanning and probing. Signed-off-by: Stefan Richter commit 36aba07b426c0fbabf4a95b22dc4ee7a77352afe Author: Randy Dunlap Date: Tue Oct 24 11:19:11 2006 -0700 ieee1394: only build OUI database files if config enabled Only build IEEE1394 OUI database files if the config option is enabled. Signed-off-by: Randy Dunlap Signed-off-by: Stefan Richter commit 5ca5b390e767170395315f04d6e4e6c47084f101 Author: Randy Dunlap Date: Mon Oct 23 21:44:36 2006 -0700 ieee1394: fix printk format warning Fix printk format warning: drivers/ieee1394/nodemgr.c:364: warning: long long unsigned int format, u64 arg (arg 3) Signed-off-by: Randy Dunlap Signed-off-by: Stefan Richter commit d7db90561f57e2af8e79c2286937918d9873d203 Author: Stefan Richter Date: Sat Oct 21 01:23:56 2006 +0200 ieee1394: nodemgr: reflect which return values are errors Give better names to local variables. Signed-off-by: Stefan Richter commit 0ac5be3ff67785371885db14c84d0db4a79f6f48 Author: Stefan Richter Date: Sat Oct 21 01:22:36 2006 +0200 ieee1394: nodemgr: small fix after sysfs errors patch One hunk in "ieee1394: handle sysfs errors" was wrong. Signed-off-by: Stefan Richter commit bbae3db851d929544415ac2d27492bdf8dde37b3 Author: Stefan Richter Date: Fri Oct 20 21:01:58 2006 +0200 dv1394: remove BKL contention Purges the one remaining call to lock_kernel() from the 1394 subsystem. Signed-off-by: Stefan Richter commit d59493d527be8f74f5e19902b931a449d690e289 Author: Daniel Drake Date: Fri Oct 20 14:56:01 2006 +0100 video1394: remove BKL contention video1394 does not need to take the BKL. The data structures shared between file_operations and interrupts are already protected through context-specific spinlocks. The only other danger is video1394_release() being called during another operation, however this cannot happen because release is only ever invoked when the last thread has closed the fd. Signed-off-by: Daniel Drake Signed-off-by: Stefan Richter commit 3ef15a7d79ffdf4b24eb63aabe88641c945da116 Author: Daniel Drake Date: Wed Oct 18 21:37:14 2006 +0100 video1394: small optimizations to frame retrieval codepath Add some GCC branch prediction optimizations to unlikely error/safety conditions in the ioctl handling code commonly called during an application's capture loop. Signed-off-by: Daniel Drake Signed-off-by: Stefan Richter commit ecec02dcb1b3ce9050b5c16d1a66d22d7786ce92 Author: Stefan Richter Date: Tue Oct 10 21:19:21 2006 +0200 ieee1394: handle sysfs errors Handle driver core errors with as much care as appropriate. Signed-off-by: Stefan Richter commit 3385e5aa1dea5917ec3824e7e9ad5b28463f0ca2 Author: Stefan Richter Date: Tue Oct 10 21:12:39 2006 +0200 ieee1394: coding style in hosts.c Some 80-columns pedantry, and touch up of a // comment. Signed-off-by: Stefan Richter commit 4b06814da9919f909b07c890a57c4b5d323684ac Author: Stefan Richter Date: Tue Oct 10 21:11:43 2006 +0200 ieee1394: lock smaller region by host_num_alloc mutex We need the mutex only around the iteration over existing hosts. Signed-off-by: Stefan Richter commit de40e7aadf48344d3aa32e78bf4c50123c218c6d Author: Stefan Richter Date: Sun Oct 8 11:45:13 2006 +0200 ieee1394: usecs_to_jiffies takes unsigned int argument Signed-off-by: Stefan Richter commit 6429e0e94a9185b92b33f7b1bb0195eb54022a89 Author: Stefan Richter Date: Sun Sep 24 11:01:00 2006 +0200 ieee1394: ohci1394: suspend/resume cosmetics Reorder the definitions of ohci1394_pci_suspend and _resume. Remove redundant comments. Beautify return statements. Signed-off-by: Stefan Richter commit c914d3cf8c54ec472b93eed03dc515435aaf29d0 Author: Bernhard Kaindl Date: Wed Sep 6 14:58:30 2006 +0200 ieee1394: ohci1394: steps to implement suspend/resume I did a quick shot on what I described and the appended patch does the first thing needed for working suspend/resume in ohci1394 which is HW de- and re-initialisation. It works with suspend2disk on my Ricoh R5C552 IEEE 1394 Controller with the 2.6.17 kernel to the extent that if I call dvgrab --interactive after suspend2disk without unloading ohci1394, it does not lock up dvgrab with 100% CPU but properly connects to the camera, given that I first unplug and plug the camera after coming back from suspend. I guess that could be fixed by forcing a bus reset in the resume function. I cannot test suspend to RAM here at the moment and should follow the guidelines in Documentation/power/pci.txt also, so this is rather a quick report than a finished patch and there are some rough edges: However, with this patch, I have to unload at least some in-kernel users of ohci1394 like dv1394 or video1394 before suspending. Not doing that caused an Oops and a bad tasklet error, probably from not handling ISO tasklets during suspend/resume properly. Maybe these can be temporarily cleared or unregistered and re-registered for suspend/resume with help from the other layers or from the highlevel 1394 core, but I do not really know what these do. But this patch provides a useful base to start from and is already of much help for people which do not need dv1394 and video1394 or can unload them at least during suspend. I cannot test function with sbp2 at the moment, but raw1394 seems to work fine. Signed-off-by: Bernhard Kaindl Update: merge with previous two ohci1394 suspend/resume patches Signed-off-by: Stefan Richter commit 4dec0165b4793f467413dcafeced4757dc3e3fc9 Author: Stefan Richter Date: Thu Sep 14 22:06:48 2006 +0200 ieee1394: raw1394: add comments on lock usage Add a who-is-who about some locks and list heads in raw1394's struct definitions. Signed-off-by: Stefan Richter commit e575953ec17c3f5c1e738847d2d16c241bb99783 Author: Stefan Richter Date: Thu Sep 14 22:05:16 2006 +0200 ieee1394: raw1394: arm functions slept in atomic context Sleeping functions like copy_to_user were accessed inside spinlocks in raw1394's arm_register, arm_unregister, arm_get_buf, arm_set_buf. http://bugzilla.kernel.org/show_bug.cgi?id=7120 Signed-off-by: Stefan Richter Tested-by: David Trent commit 7db8c834c9169a76540104e05fe8c7ec47dbb5f3 Author: Stefan Richter Date: Mon Sep 11 20:17:14 2006 +0200 ieee1394: sbp2: slightly reorder sbp2scsi_abort Put the target's fetch agent into reset state before the underlying ORB DMA is unmapped and the ->done handler is called. It is highly unlikely but the target could access that ORB right before sbp2 sends the reset request. Signed-off-by: Stefan Richter commit 34d6ad74ff8007f2a8f67c551adeff4ab17583a7 Author: Stefan Richter Date: Wed Sep 6 23:42:00 2006 +0200 ieee1394: remove unused struct member from highlevel API struct hpsb_highlevel's struct module *owner is neither used by the IEEE 1394 core nor set by any of the in-tree drivers or the two out-of-tree highlevel drivers I know about (dfg1394, mem1394) --- nor is this member documented. An unscheduled removal seems acceptable. Signed-off-by: Stefan Richter drivers/ieee1394/Makefile | 5 - drivers/ieee1394/csr.c | 8 - drivers/ieee1394/dv1394.c | 14 - drivers/ieee1394/highlevel.h | 1 drivers/ieee1394/hosts.c | 41 ++-- drivers/ieee1394/nodemgr.c | 355 +++++++++++++++++++++++------------- drivers/ieee1394/ohci1394.c | 94 ++++++++-- drivers/ieee1394/raw1394-private.h | 10 + drivers/ieee1394/sbp2.c | 10 - drivers/ieee1394/video1394.c | 48 ++--- 10 files changed, 360 insertions(+), 226 deletions(-) diff --git a/drivers/ieee1394/Makefile b/drivers/ieee1394/Makefile index 6f53611..d9650d3 100644 --- a/drivers/ieee1394/Makefile +++ b/drivers/ieee1394/Makefile @@ -3,8 +3,11 @@ # Makefile for the Linux IEEE 1394 imple # ieee1394-objs := ieee1394_core.o ieee1394_transactions.o hosts.o \ - highlevel.o csr.o nodemgr.o oui.o dma.o iso.o \ + highlevel.o csr.o nodemgr.o dma.o iso.o \ csr1212.o config_roms.o +ifdef CONFIG_IEEE1394_OUI_DB +ieee1394-objs += oui.o +endif obj-$(CONFIG_IEEE1394) += ieee1394.o obj-$(CONFIG_IEEE1394_PCILYNX) += pcilynx.o diff --git a/drivers/ieee1394/csr.c b/drivers/ieee1394/csr.c index ab0c80f..52ac83e 100644 --- a/drivers/ieee1394/csr.c +++ b/drivers/ieee1394/csr.c @@ -158,12 +158,10 @@ static void host_reset(struct hpsb_host */ static inline void calculate_expire(struct csr_control *csr) { - unsigned long usecs = - (csr->split_timeout_hi & 0x07) * USEC_PER_SEC + - (csr->split_timeout_lo >> 19) * 125L; - - csr->expire = usecs_to_jiffies(usecs > 100000L ? usecs : 100000L); + unsigned int usecs = (csr->split_timeout_hi & 7) * 1000000 + + (csr->split_timeout_lo >> 19) * 125; + csr->expire = usecs_to_jiffies(usecs > 100000 ? usecs : 100000); HPSB_VERBOSE("CSR: setting expire to %lu, HZ=%u", csr->expire, HZ); } diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c index 6c72f04..d0e11c1 100644 --- a/drivers/ieee1394/dv1394.c +++ b/drivers/ieee1394/dv1394.c @@ -1536,27 +1536,20 @@ static ssize_t dv1394_read(struct file * static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct video_card *video; + struct video_card *video = file_to_video_card(file); unsigned long flags; int ret = -EINVAL; void __user *argp = (void __user *)arg; DECLARE_WAITQUEUE(wait, current); - lock_kernel(); - video = file_to_video_card(file); - /* serialize this to prevent multi-threaded mayhem */ if (file->f_flags & O_NONBLOCK) { - if (!mutex_trylock(&video->mtx)) { - unlock_kernel(); + if (!mutex_trylock(&video->mtx)) return -EAGAIN; - } } else { - if (mutex_lock_interruptible(&video->mtx)) { - unlock_kernel(); + if (mutex_lock_interruptible(&video->mtx)) return -ERESTARTSYS; - } } switch(cmd) @@ -1780,7 +1773,6 @@ static long dv1394_ioctl(struct file *fi out: mutex_unlock(&video->mtx); - unlock_kernel(); return ret; } diff --git a/drivers/ieee1394/highlevel.h b/drivers/ieee1394/highlevel.h index 50f2dd2..4b33011 100644 --- a/drivers/ieee1394/highlevel.h +++ b/drivers/ieee1394/highlevel.h @@ -24,7 +24,6 @@ struct hpsb_address_serve { /* Only the following structures are of interest to actual highlevel drivers. */ struct hpsb_highlevel { - struct module *owner; const char *name; /* Any of the following pointers can legally be NULL, except for diff --git a/drivers/ieee1394/hosts.c b/drivers/ieee1394/hosts.c index d90a3a1..c9fa577 100644 --- a/drivers/ieee1394/hosts.c +++ b/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; } @@ -127,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; @@ -150,16 +151,15 @@ 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); 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)); @@ -170,13 +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); - mutex_unlock(&host_num_alloc); - return h; + +fail: + kfree(h); + return NULL; } int hpsb_add_host(struct hpsb_host *host) @@ -228,7 +234,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. */ diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c index 8e7b83f..4d59a6b 100644 --- a/drivers/ieee1394/nodemgr.c +++ b/drivers/ieee1394/nodemgr.c @@ -66,7 +66,7 @@ static int nodemgr_check_speed(struct no { quadlet_t q; u8 i, *speed, old_speed, good_speed; - int ret; + int error; speed = &(ci->host->speed[NODEID_TO_NODE(ci->nodeid)]); old_speed = *speed; @@ -78,9 +78,9 @@ static int nodemgr_check_speed(struct no * just finished its initialization. */ for (i = IEEE1394_SPEED_100; i <= old_speed; i++) { *speed = i; - ret = hpsb_read(ci->host, ci->nodeid, ci->generation, addr, - &q, sizeof(quadlet_t)); - if (ret) + error = hpsb_read(ci->host, ci->nodeid, ci->generation, addr, + &q, sizeof(quadlet_t)); + if (error) break; *buffer = q; good_speed = i; @@ -94,19 +94,19 @@ static int nodemgr_check_speed(struct no return 0; } *speed = old_speed; - return ret; + return error; } static int nodemgr_bus_read(struct csr1212_csr *csr, u64 addr, u16 length, void *buffer, void *__ci) { struct nodemgr_csr_info *ci = (struct nodemgr_csr_info*)__ci; - int i, ret; + int i, error; for (i = 1; ; i++) { - ret = hpsb_read(ci->host, ci->nodeid, ci->generation, addr, - buffer, length); - if (!ret) { + error = hpsb_read(ci->host, ci->nodeid, ci->generation, addr, + buffer, length); + if (!error) { ci->speed_unverified = 0; break; } @@ -117,14 +117,14 @@ static int nodemgr_bus_read(struct csr12 /* The ieee1394_core guessed the node's speed capability from * the self ID. Check whether a lower speed works. */ if (ci->speed_unverified && length == sizeof(quadlet_t)) { - ret = nodemgr_check_speed(ci, addr, buffer); - if (!ret) + error = nodemgr_check_speed(ci, addr, buffer); + if (!error) break; } if (msleep_interruptible(334)) return -EINTR; } - return ret; + return error; } static int nodemgr_get_max_rom(quadlet_t *bus_info_data, void *__ci) @@ -361,7 +361,7 @@ #else #endif spin_unlock_irqrestore(&hpsb_tlabel_lock, flags); - return sprintf(buf, "0x%016llx\n", tm); + return sprintf(buf, "0x%016llx\n", (unsigned long long)tm); } static DEVICE_ATTR(tlabels_mask, S_IRUGO, fw_show_ne_tlabels_mask, NULL); #endif /* HPSB_DEBUG_TLABELS */ @@ -373,11 +373,11 @@ static ssize_t fw_set_ignore_driver(stru int state = simple_strtoul(buf, NULL, 10); if (state == 1) { - down_write(&dev->bus->subsys.rwsem); - device_release_driver(dev); ud->ignore_driver = 1; - up_write(&dev->bus->subsys.rwsem); - } else if (!state) + down_write(&ieee1394_bus_type.subsys.rwsem); + device_release_driver(dev); + up_write(&ieee1394_bus_type.subsys.rwsem); + } else if (state == 0) ud->ignore_driver = 0; return count; @@ -412,11 +412,14 @@ static ssize_t fw_get_destroy_node(struc static BUS_ATTR(destroy_node, S_IWUSR | S_IRUGO, fw_get_destroy_node, fw_set_destroy_node); -static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, size_t count) +static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, + size_t count) { + int error = 0; + if (simple_strtoul(buf, NULL, 10) == 1) - bus_rescan_devices(&ieee1394_bus_type); - return count; + error = bus_rescan_devices(&ieee1394_bus_type); + return error ? error : count; } static ssize_t fw_get_rescan(struct bus_type *bus, char *buf) { @@ -432,7 +435,7 @@ static ssize_t fw_set_ignore_drivers(str if (state == 1) ignore_drivers = 1; - else if (!state) + else if (state == 0) ignore_drivers = 0; return count; @@ -582,7 +585,11 @@ static void nodemgr_create_drv_files(str int i; for (i = 0; i < ARRAY_SIZE(fw_drv_attrs); i++) - driver_create_file(drv, fw_drv_attrs[i]); + if (driver_create_file(drv, fw_drv_attrs[i])) + goto fail; + return; +fail: + HPSB_ERR("Failed to add sysfs attribute for driver %s", driver->name); } @@ -602,7 +609,12 @@ static void nodemgr_create_ne_dev_files( int i; for (i = 0; i < ARRAY_SIZE(fw_ne_attrs); i++) - device_create_file(dev, fw_ne_attrs[i]); + if (device_create_file(dev, fw_ne_attrs[i])) + goto fail; + return; +fail: + HPSB_ERR("Failed to add sysfs attribute for node %016Lx", + (unsigned long long)ne->guid); } @@ -612,11 +624,16 @@ static void nodemgr_create_host_dev_file int i; for (i = 0; i < ARRAY_SIZE(fw_host_attrs); i++) - device_create_file(dev, fw_host_attrs[i]); + if (device_create_file(dev, fw_host_attrs[i])) + goto fail; + return; +fail: + HPSB_ERR("Failed to add sysfs attribute for host %d", host->id); } -static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, nodeid_t nodeid); +static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, + nodeid_t nodeid); static void nodemgr_update_host_dev_links(struct hpsb_host *host) { @@ -627,12 +644,18 @@ static void nodemgr_update_host_dev_link sysfs_remove_link(&dev->kobj, "busmgr_id"); sysfs_remove_link(&dev->kobj, "host_id"); - if ((ne = find_entry_by_nodeid(host, host->irm_id))) - sysfs_create_link(&dev->kobj, &ne->device.kobj, "irm_id"); - if ((ne = find_entry_by_nodeid(host, host->busmgr_id))) - sysfs_create_link(&dev->kobj, &ne->device.kobj, "busmgr_id"); - if ((ne = find_entry_by_nodeid(host, host->node_id))) - sysfs_create_link(&dev->kobj, &ne->device.kobj, "host_id"); + if ((ne = find_entry_by_nodeid(host, host->irm_id)) && + sysfs_create_link(&dev->kobj, &ne->device.kobj, "irm_id")) + goto fail; + if ((ne = find_entry_by_nodeid(host, host->busmgr_id)) && + sysfs_create_link(&dev->kobj, &ne->device.kobj, "busmgr_id")) + goto fail; + if ((ne = find_entry_by_nodeid(host, host->node_id)) && + sysfs_create_link(&dev->kobj, &ne->device.kobj, "host_id")) + goto fail; + return; +fail: + HPSB_ERR("Failed to update sysfs attributes for host %d", host->id); } static void nodemgr_create_ud_dev_files(struct unit_directory *ud) @@ -641,25 +664,32 @@ static void nodemgr_create_ud_dev_files( int i; for (i = 0; i < ARRAY_SIZE(fw_ud_attrs); i++) - device_create_file(dev, fw_ud_attrs[i]); - + if (device_create_file(dev, fw_ud_attrs[i])) + goto fail; if (ud->flags & UNIT_DIRECTORY_SPECIFIER_ID) - device_create_file(dev, &dev_attr_ud_specifier_id); - + if (device_create_file(dev, &dev_attr_ud_specifier_id)) + goto fail; if (ud->flags & UNIT_DIRECTORY_VERSION) - device_create_file(dev, &dev_attr_ud_version); - + if (device_create_file(dev, &dev_attr_ud_version)) + goto fail; if (ud->flags & UNIT_DIRECTORY_VENDOR_ID) { - device_create_file(dev, &dev_attr_ud_vendor_id); - if (ud->vendor_name_kv) - device_create_file(dev, &dev_attr_ud_vendor_name_kv); + if (device_create_file(dev, &dev_attr_ud_vendor_id)) + goto fail; + if (ud->vendor_name_kv && + device_create_file(dev, &dev_attr_ud_vendor_name_kv)) + goto fail; } - if (ud->flags & UNIT_DIRECTORY_MODEL_ID) { - device_create_file(dev, &dev_attr_ud_model_id); - if (ud->model_name_kv) - device_create_file(dev, &dev_attr_ud_model_name_kv); + if (device_create_file(dev, &dev_attr_ud_model_id)) + goto fail; + if (ud->model_name_kv && + device_create_file(dev, &dev_attr_ud_model_name_kv)) + goto fail; } + return; +fail: + HPSB_ERR("Failed to add sysfs attributes for unit %s", + ud->device.bus_id); } @@ -703,20 +733,65 @@ static int nodemgr_bus_match(struct devi } +static DEFINE_MUTEX(nodemgr_serialize_remove_uds); + static void nodemgr_remove_uds(struct node_entry *ne) { - struct class_device *cdev, *next; - struct unit_directory *ud; + struct class_device *cdev; + struct unit_directory *ud, **unreg; + size_t i, count; + + /* + * This is awkward: + * Iteration over nodemgr_ud_class.children has to be protected by + * nodemgr_ud_class.sem, but class_device_unregister() will eventually + * take nodemgr_ud_class.sem too. Therefore store all uds to be + * unregistered in a temporary array, release the semaphore, and then + * unregister the uds. + * + * Since nodemgr_remove_uds can also run in other contexts than the + * knodemgrds (which are currently globally serialized), protect the + * gap after release of the semaphore by nodemgr_serialize_remove_uds. + */ - list_for_each_entry_safe(cdev, next, &nodemgr_ud_class.children, node) { - ud = container_of(cdev, struct unit_directory, class_dev); + mutex_lock(&nodemgr_serialize_remove_uds); - if (ud->ne != ne) - continue; + down(&nodemgr_ud_class.sem); + count = 0; + list_for_each_entry(cdev, &nodemgr_ud_class.children, node) { + ud = container_of(cdev, struct unit_directory, class_dev); + if (ud->ne == ne) + count++; + } + if (!count) { + up(&nodemgr_ud_class.sem); + mutex_unlock(&nodemgr_serialize_remove_uds); + return; + } + unreg = kcalloc(count, sizeof(*unreg), GFP_KERNEL); + if (!unreg) { + HPSB_ERR("NodeMgr: out of memory in nodemgr_remove_uds"); + up(&nodemgr_ud_class.sem); + mutex_unlock(&nodemgr_serialize_remove_uds); + return; + } + i = 0; + list_for_each_entry(cdev, &nodemgr_ud_class.children, node) { + ud = container_of(cdev, struct unit_directory, class_dev); + if (ud->ne == ne) { + BUG_ON(i >= count); + unreg[i++] = ud; + } + } + up(&nodemgr_ud_class.sem); - class_device_unregister(&ud->class_dev); - device_unregister(&ud->device); + for (i = 0; i < count; i++) { + class_device_unregister(&unreg[i]->class_dev); + device_unregister(&unreg[i]->device); } + kfree(unreg); + + mutex_unlock(&nodemgr_serialize_remove_uds); } @@ -747,7 +822,7 @@ static int __nodemgr_remove_host_dev(str static void nodemgr_remove_host_dev(struct device *dev) { - device_for_each_child(dev, NULL, __nodemgr_remove_host_dev); + WARN_ON(device_for_each_child(dev, NULL, __nodemgr_remove_host_dev)); sysfs_remove_link(&dev->kobj, "irm_id"); sysfs_remove_link(&dev->kobj, "busmgr_id"); sysfs_remove_link(&dev->kobj, "host_id"); @@ -791,7 +866,7 @@ static struct node_entry *nodemgr_create ne = kzalloc(sizeof(*ne), GFP_KERNEL); if (!ne) - return NULL; + goto fail_alloc; ne->host = host; ne->nodeid = nodeid; @@ -814,12 +889,15 @@ static struct node_entry *nodemgr_create snprintf(ne->class_dev.class_id, BUS_ID_SIZE, "%016Lx", (unsigned long long)(ne->guid)); - device_register(&ne->device); - class_device_register(&ne->class_dev); + if (device_register(&ne->device)) + goto fail_devreg; + if (class_device_register(&ne->class_dev)) + goto fail_classdevreg; get_device(&ne->device); - if (ne->guid_vendor_oui) - device_create_file(&ne->device, &dev_attr_ne_guid_vendor_oui); + if (ne->guid_vendor_oui && + device_create_file(&ne->device, &dev_attr_ne_guid_vendor_oui)) + goto fail_addoiu; nodemgr_create_ne_dev_files(ne); nodemgr_update_bus_options(ne); @@ -829,17 +907,28 @@ static struct node_entry *nodemgr_create NODE_BUS_ARGS(host, nodeid), (unsigned long long)guid); return ne; + +fail_addoiu: + put_device(&ne->device); +fail_classdevreg: + device_unregister(&ne->device); +fail_devreg: + kfree(ne); +fail_alloc: + HPSB_ERR("Failed to create node ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]", + NODE_BUS_ARGS(host, nodeid), (unsigned long long)guid); + + return NULL; } static struct node_entry *find_entry_by_guid(u64 guid) { - struct class *class = &nodemgr_ne_class; struct class_device *cdev; struct node_entry *ne, *ret_ne = NULL; - down_read(&class->subsys.rwsem); - list_for_each_entry(cdev, &class->children, node) { + down(&nodemgr_ne_class.sem); + list_for_each_entry(cdev, &nodemgr_ne_class.children, node) { ne = container_of(cdev, struct node_entry, class_dev); if (ne->guid == guid) { @@ -847,20 +936,20 @@ static struct node_entry *find_entry_by_ break; } } - up_read(&class->subsys.rwsem); + up(&nodemgr_ne_class.sem); return ret_ne; } -static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, nodeid_t nodeid) +static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, + nodeid_t nodeid) { - struct class *class = &nodemgr_ne_class; struct class_device *cdev; struct node_entry *ne, *ret_ne = NULL; - down_read(&class->subsys.rwsem); - list_for_each_entry(cdev, &class->children, node) { + down(&nodemgr_ne_class.sem); + list_for_each_entry(cdev, &nodemgr_ne_class.children, node) { ne = container_of(cdev, struct node_entry, class_dev); if (ne->host == host && ne->nodeid == nodeid) { @@ -868,7 +957,7 @@ static struct node_entry *find_entry_by_ break; } } - up_read(&class->subsys.rwsem); + up(&nodemgr_ne_class.sem); return ret_ne; } @@ -890,13 +979,25 @@ static void nodemgr_register_device(stru snprintf(ud->class_dev.class_id, BUS_ID_SIZE, "%s-%u", ne->device.bus_id, ud->id); - device_register(&ud->device); - class_device_register(&ud->class_dev); + if (device_register(&ud->device)) + goto fail_devreg; + if (class_device_register(&ud->class_dev)) + goto fail_classdevreg; get_device(&ud->device); - if (ud->vendor_oui) - device_create_file(&ud->device, &dev_attr_ud_vendor_oui); + if (ud->vendor_oui && + device_create_file(&ud->device, &dev_attr_ud_vendor_oui)) + goto fail_addoui; nodemgr_create_ud_dev_files(ud); + + return; + +fail_addoui: + put_device(&ud->device); +fail_classdevreg: + device_unregister(&ud->device); +fail_devreg: + HPSB_ERR("Failed to create unit %s", ud->device.bus_id); } @@ -1093,10 +1194,16 @@ static void nodemgr_process_root_directo last_key_id = kv->key.id; } - if (ne->vendor_oui) - device_create_file(&ne->device, &dev_attr_ne_vendor_oui); - if (ne->vendor_name_kv) - device_create_file(&ne->device, &dev_attr_ne_vendor_name_kv); + if (ne->vendor_oui && + device_create_file(&ne->device, &dev_attr_ne_vendor_oui)) + goto fail; + if (ne->vendor_name_kv && + device_create_file(&ne->device, &dev_attr_ne_vendor_name_kv)) + goto fail; + return; +fail: + HPSB_ERR("Failed to add sysfs attribute for node %016Lx", + (unsigned long long)ne->guid); } #ifdef CONFIG_HOTPLUG @@ -1162,14 +1269,11 @@ #endif /* CONFIG_HOTPLUG */ int hpsb_register_protocol(struct hpsb_protocol_driver *driver) { - int ret; - /* This will cause a probe for devices */ - ret = driver_register(&driver->driver); - if (!ret) + int error = driver_register(&driver->driver); + if (!error) nodemgr_create_drv_files(driver); - - return ret; + return error; } void hpsb_unregister_protocol(struct hpsb_protocol_driver *driver) @@ -1316,7 +1420,6 @@ static void nodemgr_node_scan(struct hos } -/* Caller needs to hold nodemgr_ud_class.subsys.rwsem as reader. */ static void nodemgr_suspend_ne(struct node_entry *ne) { struct class_device *cdev; @@ -1326,21 +1429,22 @@ static void nodemgr_suspend_ne(struct no NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid); ne->in_limbo = 1; - device_create_file(&ne->device, &dev_attr_ne_in_limbo); + WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo)); - down_write(&ne->device.bus->subsys.rwsem); + down(&nodemgr_ud_class.sem); list_for_each_entry(cdev, &nodemgr_ud_class.children, node) { ud = container_of(cdev, struct unit_directory, class_dev); - if (ud->ne != ne) continue; + down_write(&ieee1394_bus_type.subsys.rwsem); if (ud->device.driver && (!ud->device.driver->suspend || ud->device.driver->suspend(&ud->device, PMSG_SUSPEND))) device_release_driver(&ud->device); + up_write(&ieee1394_bus_type.subsys.rwsem); } - up_write(&ne->device.bus->subsys.rwsem); + up(&nodemgr_ud_class.sem); } @@ -1352,45 +1456,47 @@ static void nodemgr_resume_ne(struct nod ne->in_limbo = 0; device_remove_file(&ne->device, &dev_attr_ne_in_limbo); - down_read(&nodemgr_ud_class.subsys.rwsem); - down_read(&ne->device.bus->subsys.rwsem); + down(&nodemgr_ud_class.sem); list_for_each_entry(cdev, &nodemgr_ud_class.children, node) { ud = container_of(cdev, struct unit_directory, class_dev); - if (ud->ne != ne) continue; + down_read(&ieee1394_bus_type.subsys.rwsem); if (ud->device.driver && ud->device.driver->resume) ud->device.driver->resume(&ud->device); + up_read(&ieee1394_bus_type.subsys.rwsem); } - up_read(&ne->device.bus->subsys.rwsem); - up_read(&nodemgr_ud_class.subsys.rwsem); + up(&nodemgr_ud_class.sem); HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]", NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid); } -/* Caller needs to hold nodemgr_ud_class.subsys.rwsem as reader. */ static void nodemgr_update_pdrv(struct node_entry *ne) { struct unit_directory *ud; struct hpsb_protocol_driver *pdrv; struct class_device *cdev; + down(&nodemgr_ud_class.sem); list_for_each_entry(cdev, &nodemgr_ud_class.children, node) { ud = container_of(cdev, struct unit_directory, class_dev); - if (ud->ne != ne || !ud->device.driver) + if (ud->ne != ne) continue; - pdrv = container_of(ud->device.driver, struct hpsb_protocol_driver, driver); - - if (pdrv->update && pdrv->update(ud)) { - down_write(&ud->device.bus->subsys.rwsem); - device_release_driver(&ud->device); - up_write(&ud->device.bus->subsys.rwsem); + down_write(&ieee1394_bus_type.subsys.rwsem); + if (ud->device.driver) { + pdrv = container_of(ud->device.driver, + struct hpsb_protocol_driver, + driver); + if (pdrv->update && pdrv->update(ud)) + device_release_driver(&ud->device); } + up_write(&ieee1394_bus_type.subsys.rwsem); } + up(&nodemgr_ud_class.sem); } @@ -1404,7 +1510,7 @@ static void nodemgr_irm_write_bc(struct { const u64 bc_addr = (CSR_REGISTER_BASE | CSR_BROADCAST_CHANNEL); quadlet_t bc_remote, bc_local; - int ret; + int error; if (!ne->host->is_irm || ne->generation != generation || ne->nodeid == ne->host->node_id) @@ -1413,16 +1519,14 @@ static void nodemgr_irm_write_bc(struct bc_local = cpu_to_be32(ne->host->csr.broadcast_channel); /* Check if the register is implemented and 1394a compliant. */ - ret = hpsb_read(ne->host, ne->nodeid, generation, bc_addr, &bc_remote, - sizeof(bc_remote)); - if (!ret && bc_remote & cpu_to_be32(0x80000000) && + error = hpsb_read(ne->host, ne->nodeid, generation, bc_addr, &bc_remote, + sizeof(bc_remote)); + if (!error && bc_remote & cpu_to_be32(0x80000000) && bc_remote != bc_local) hpsb_node_write(ne, bc_addr, &bc_local, sizeof(bc_local)); } -/* Caller needs to hold nodemgr_ud_class.subsys.rwsem as reader because the - * calls to nodemgr_update_pdrv() and nodemgr_suspend_ne() here require it. */ static void nodemgr_probe_ne(struct host_info *hi, struct node_entry *ne, int generation) { struct device *dev; @@ -1455,7 +1559,6 @@ static void nodemgr_probe_ne(struct host static void nodemgr_node_probe(struct host_info *hi, int generation) { struct hpsb_host *host = hi->host; - struct class *class = &nodemgr_ne_class; struct class_device *cdev; struct node_entry *ne; @@ -1468,18 +1571,18 @@ static void nodemgr_node_probe(struct ho * while probes are time-consuming. (Well, those probes need some * improvement...) */ - down_read(&class->subsys.rwsem); - list_for_each_entry(cdev, &class->children, node) { + down(&nodemgr_ne_class.sem); + list_for_each_entry(cdev, &nodemgr_ne_class.children, node) { ne = container_of(cdev, struct node_entry, class_dev); if (!ne->needs_probe) nodemgr_probe_ne(hi, ne, generation); } - list_for_each_entry(cdev, &class->children, node) { + list_for_each_entry(cdev, &nodemgr_ne_class.children, node) { ne = container_of(cdev, struct node_entry, class_dev); if (ne->needs_probe) nodemgr_probe_ne(hi, ne, generation); } - up_read(&class->subsys.rwsem); + up(&nodemgr_ne_class.sem); /* If we had a bus reset while we were scanning the bus, it is @@ -1497,7 +1600,7 @@ static void nodemgr_node_probe(struct ho * just removed. */ if (generation == get_hpsb_generation(host)) - bus_rescan_devices(&ieee1394_bus_type); + WARN_ON(bus_rescan_devices(&ieee1394_bus_type)); return; } @@ -1505,7 +1608,7 @@ static void nodemgr_node_probe(struct ho static int nodemgr_send_resume_packet(struct hpsb_host *host) { struct hpsb_packet *packet; - int ret = 1; + int error = -ENOMEM; packet = hpsb_make_phypacket(host, EXTPHYPACKET_TYPE_RESUME | @@ -1513,12 +1616,12 @@ static int nodemgr_send_resume_packet(st if (packet) { packet->no_waiter = 1; packet->generation = get_hpsb_generation(host); - ret = hpsb_send_packet(packet); + error = hpsb_send_packet(packet); } - if (ret) + if (error) HPSB_WARN("fw-host%d: Failed to broadcast resume packet", host->id); - return ret; + return error; } /* Perform a few high-level IRM responsibilities. */ @@ -1691,19 +1794,18 @@ exit: int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *)) { - struct class *class = &hpsb_host_class; struct class_device *cdev; struct hpsb_host *host; int error = 0; - down_read(&class->subsys.rwsem); - list_for_each_entry(cdev, &class->children, node) { + down(&hpsb_host_class.sem); + list_for_each_entry(cdev, &hpsb_host_class.children, node) { host = container_of(cdev, struct hpsb_host, class_dev); if ((error = cb(host, __data))) break; } - up_read(&class->subsys.rwsem); + up(&hpsb_host_class.sem); return error; } @@ -1788,20 +1890,19 @@ static struct hpsb_highlevel nodemgr_hig int init_ieee1394_nodemgr(void) { - int ret; + int error; - ret = class_register(&nodemgr_ne_class); - if (ret < 0) - return ret; + error = class_register(&nodemgr_ne_class); + if (error) + return error; - ret = class_register(&nodemgr_ud_class); - if (ret < 0) { + error = class_register(&nodemgr_ud_class); + if (error) { class_unregister(&nodemgr_ne_class); - return ret; + return error; } hpsb_register_highlevel(&nodemgr_highlevel); - return 0; } diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c index dea1352..4d3b58f 100644 --- a/drivers/ieee1394/ohci1394.c +++ b/drivers/ieee1394/ohci1394.c @@ -3529,49 +3529,105 @@ #endif /* CONFIG_PPC_PMAC */ } #ifdef CONFIG_PM -static int ohci1394_pci_resume (struct pci_dev *pdev) +static int ohci1394_pci_suspend(struct pci_dev *pdev, pm_message_t state) { -/* PowerMac resume code comes first */ + int err; + struct ti_ohci *ohci = pci_get_drvdata(pdev); + + printk(KERN_INFO "%s does not fully support suspend and resume yet\n", + OHCI1394_DRIVER_NAME); + + if (!ohci) { + printk(KERN_ERR "%s: tried to suspend nonexisting host\n", + OHCI1394_DRIVER_NAME); + return -ENXIO; + } + DBGMSG("suspend called"); + + /* Clear the async DMA contexts and stop using the controller */ + hpsb_bus_reset(ohci->host); + + /* See ohci1394_pci_remove() for comments on this sequence */ + reg_write(ohci, OHCI1394_ConfigROMhdr, 0); + reg_write(ohci, OHCI1394_BusOptions, + (reg_read(ohci, OHCI1394_BusOptions) & 0x0000f007) | + 0x00ff0000); + reg_write(ohci, OHCI1394_IntMaskClear, 0xffffffff); + reg_write(ohci, OHCI1394_IntEventClear, 0xffffffff); + reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, 0xffffffff); + reg_write(ohci, OHCI1394_IsoXmitIntEventClear, 0xffffffff); + reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, 0xffffffff); + reg_write(ohci, OHCI1394_IsoRecvIntEventClear, 0xffffffff); + set_phy_reg(ohci, 4, ~0xc0 & get_phy_reg(ohci, 4)); + reg_write(ohci, OHCI1394_LinkControlClear, 0xffffffff); + ohci_devctl(ohci->host, RESET_BUS, LONG_RESET_NO_FORCE_ROOT); + ohci_soft_reset(ohci); + + err = pci_save_state(pdev); + if (err) { + PRINT(KERN_ERR, "pci_save_state failed with %d", err); + return err; + } + err = pci_set_power_state(pdev, pci_choose_state(pdev, state)); + if (err) + DBGMSG("pci_set_power_state failed with %d", err); + +/* PowerMac suspend code comes last */ #ifdef CONFIG_PPC_PMAC if (machine_is(powermac)) { struct device_node *of_node; - /* Re-enable 1394 */ + /* Disable 1394 */ of_node = pci_device_to_OF_node (pdev); if (of_node) - pmac_call_feature (PMAC_FTR_1394_ENABLE, of_node, 0, 1); + pmac_call_feature(PMAC_FTR_1394_ENABLE, of_node, 0, 0); } #endif /* CONFIG_PPC_PMAC */ - pci_set_power_state(pdev, PCI_D0); - pci_restore_state(pdev); - return pci_enable_device(pdev); + return 0; } -static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) +static int ohci1394_pci_resume(struct pci_dev *pdev) { int err; + struct ti_ohci *ohci = pci_get_drvdata(pdev); - err = pci_save_state(pdev); - if (err) - goto out; - err = pci_set_power_state(pdev, pci_choose_state(pdev, state)); - if (err) - goto out; + if (!ohci) { + printk(KERN_ERR "%s: tried to resume nonexisting host\n", + OHCI1394_DRIVER_NAME); + return -ENXIO; + } + DBGMSG("resume called"); -/* PowerMac suspend code comes last */ +/* PowerMac resume code comes first */ #ifdef CONFIG_PPC_PMAC if (machine_is(powermac)) { struct device_node *of_node; - /* Disable 1394 */ + /* Re-enable 1394 */ of_node = pci_device_to_OF_node (pdev); if (of_node) - pmac_call_feature(PMAC_FTR_1394_ENABLE, of_node, 0, 0); + pmac_call_feature (PMAC_FTR_1394_ENABLE, of_node, 0, 1); } #endif /* CONFIG_PPC_PMAC */ -out: - return err; + + pci_set_power_state(pdev, PCI_D0); + pci_restore_state(pdev); + err = pci_enable_device(pdev); + if (err) { + PRINT(KERN_ERR, "pci_enable_device failed with %d", err); + return err; + } + + /* See ohci1394_pci_probe() for comments on this sequence */ + ohci_soft_reset(ohci); + reg_write(ohci, OHCI1394_HCControlSet, OHCI1394_HCControl_LPS); + reg_write(ohci, OHCI1394_IntEventClear, 0xffffffff); + reg_write(ohci, OHCI1394_IntMaskClear, 0xffffffff); + mdelay(50); + ohci_initialize(ohci); + + return 0; } #endif /* CONFIG_PM */ diff --git a/drivers/ieee1394/raw1394-private.h b/drivers/ieee1394/raw1394-private.h index c7731d1..50daabf 100644 --- a/drivers/ieee1394/raw1394-private.h +++ b/drivers/ieee1394/raw1394-private.h @@ -27,12 +27,12 @@ struct file_info { struct hpsb_host *host; - struct list_head req_pending; - struct list_head req_complete; + struct list_head req_pending; /* protected by reqlists_lock */ + struct list_head req_complete; /* protected by reqlists_lock */ spinlock_t reqlists_lock; wait_queue_head_t wait_complete; - struct list_head addr_list; + struct list_head addr_list; /* protected by host_info_lock */ u8 __user *fcp_buffer; @@ -63,7 +63,7 @@ struct arm_addr { u8 client_transactions; u64 recvb; u16 rec_length; - u8 *addr_space_buffer; /* accessed by read/write/lock */ + u8 *addr_space_buffer; /* accessed by read/write/lock requests */ }; struct pending_request { @@ -79,7 +79,7 @@ struct pending_request { struct host_info { struct list_head list; struct hpsb_host *host; - struct list_head file_info_list; + struct list_head file_info_list; /* protected by host_info_lock */ }; #endif /* IEEE1394_RAW1394_PRIVATE_H */ diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 6986ac1..a155d96 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -2560,11 +2560,9 @@ static int sbp2scsi_abort(struct scsi_cm scsi_print_command(SCpnt); if (sbp2util_node_is_available(scsi_id)) { + sbp2_agent_reset(scsi_id, 1); - /* - * Right now, just return any matching command structures - * to the free pool. - */ + /* Return a matching command structure to the free pool. */ spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); command = sbp2util_find_command_for_SCpnt(scsi_id, SCpnt); if (command) { @@ -2585,10 +2583,6 @@ static int sbp2scsi_abort(struct scsi_cm } spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); - /* - * Initiate a fetch agent reset. - */ - sbp2_agent_reset(scsi_id, 1); sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY); } diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c index 9bc6505..77f58bc 100644 --- a/drivers/ieee1394/video1394.c +++ b/drivers/ieee1394/video1394.c @@ -714,8 +714,8 @@ static inline unsigned video1394_buffer_ return ret; } -static int __video1394_ioctl(struct file *file, - unsigned int cmd, unsigned long arg) +static long video1394_ioctl(struct file *file, + unsigned int cmd, unsigned long arg) { struct file_ctx *ctx = (struct file_ctx *)file->private_data; struct ti_ohci *ohci = ctx->ohci; @@ -884,13 +884,14 @@ static int __video1394_ioctl(struct file struct dma_iso_ctx *d; int next_prg; - if (copy_from_user(&v, argp, sizeof(v))) + if (unlikely(copy_from_user(&v, argp, sizeof(v)))) return -EFAULT; d = find_ctx(&ctx->context_list, OHCI_ISO_RECEIVE, v.channel); - if (d == NULL) return -EFAULT; + if (unlikely(d == NULL)) + return -EFAULT; - if ((v.buffer<0) || (v.buffer>=d->num_desc - 1)) { + if (unlikely((v.buffer<0) || (v.buffer>=d->num_desc - 1))) { PRINT(KERN_ERR, ohci->host->id, "Buffer %d out of range",v.buffer); return -EINVAL; @@ -898,7 +899,7 @@ static int __video1394_ioctl(struct file spin_lock_irqsave(&d->lock,flags); - if (d->buffer_status[v.buffer]==VIDEO1394_BUFFER_QUEUED) { + if (unlikely(d->buffer_status[v.buffer]==VIDEO1394_BUFFER_QUEUED)) { PRINT(KERN_ERR, ohci->host->id, "Buffer %d is already used",v.buffer); spin_unlock_irqrestore(&d->lock,flags); @@ -949,13 +950,14 @@ static int __video1394_ioctl(struct file struct dma_iso_ctx *d; int i = 0; - if (copy_from_user(&v, argp, sizeof(v))) + if (unlikely(copy_from_user(&v, argp, sizeof(v)))) return -EFAULT; d = find_ctx(&ctx->context_list, OHCI_ISO_RECEIVE, v.channel); - if (d == NULL) return -EFAULT; + if (unlikely(d == NULL)) + return -EFAULT; - if ((v.buffer<0) || (v.buffer>d->num_desc - 1)) { + if (unlikely((v.buffer<0) || (v.buffer>d->num_desc - 1))) { PRINT(KERN_ERR, ohci->host->id, "Buffer %d out of range",v.buffer); return -EINVAL; @@ -1008,7 +1010,7 @@ static int __video1394_ioctl(struct file spin_unlock_irqrestore(&d->lock, flags); v.buffer=i; - if (copy_to_user(argp, &v, sizeof(v))) + if (unlikely(copy_to_user(argp, &v, sizeof(v)))) return -EFAULT; return 0; @@ -1156,15 +1158,6 @@ static int __video1394_ioctl(struct file } } -static long video1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg) -{ - int err; - lock_kernel(); - err = __video1394_ioctl(file, cmd, arg); - unlock_kernel(); - return err; -} - /* * This maps the vmalloced and reserved buffer to user space. * @@ -1177,17 +1170,14 @@ static long video1394_ioctl(struct file static int video1394_mmap(struct file *file, struct vm_area_struct *vma) { struct file_ctx *ctx = (struct file_ctx *)file->private_data; - int res = -EINVAL; - lock_kernel(); if (ctx->current_ctx == NULL) { PRINT(KERN_ERR, ctx->ohci->host->id, "Current iso context not set"); - } else - res = dma_region_mmap(&ctx->current_ctx->dma, file, vma); - unlock_kernel(); + return -EINVAL; + } - return res; + return dma_region_mmap(&ctx->current_ctx->dma, file, vma); } static unsigned int video1394_poll(struct file *file, poll_table *pt) @@ -1198,14 +1188,12 @@ static unsigned int video1394_poll(struc struct dma_iso_ctx *d; int i; - lock_kernel(); ctx = file->private_data; d = ctx->current_ctx; if (d == NULL) { PRINT(KERN_ERR, ctx->ohci->host->id, "Current iso context not set"); - mask = POLLERR; - goto done; + return POLLERR; } poll_wait(file, &d->waitq, pt); @@ -1218,8 +1206,6 @@ static unsigned int video1394_poll(struc } } spin_unlock_irqrestore(&d->lock, flags); -done: - unlock_kernel(); return mask; } @@ -1255,7 +1241,6 @@ static int video1394_release(struct inod struct list_head *lh, *next; u64 mask; - lock_kernel(); list_for_each_safe(lh, next, &ctx->context_list) { struct dma_iso_ctx *d; d = list_entry(lh, struct dma_iso_ctx, link); @@ -1276,7 +1261,6 @@ static int video1394_release(struct inod kfree(ctx); file->private_data = NULL; - unlock_kernel(); return 0; }