summaryrefslogtreecommitdiff
path: root/sys/dev/usb/usb_dev.c
Commit message (Collapse)AuthorAgeFilesLines
* usb(4): Fix for use after free in combination with EVDEV_SUPPORT.Hans Petter Selasky2021-11-031-13/+34
| | | | | | | | | | | | | | | | When EVDEV_SUPPORT was introduced, the USB transfers may be running after the main FIFO is closed. In connection to this a race may appear which can lead to use-after-free scenarios. Fix this for all FIFO consumers by initializing and resetting the FIFO queues under the lock used by the client. Then the client driver will see an empty queue in all cases a race may appear. Approved by: re@ (gjb) Found by: pho@ Sponsored by: NVIDIA Networking (cherry picked from commit aad0c65d6b37364d8ba92ecb8c85e004398a5194) (cherry picked from commit bb9bee1ffbb27f903bfd2c11d681d331bea727ea)
* MFC r363420:Mark Johnston2020-07-291-10/+5
| | | | | | | usb(4): Stop checking for failures from malloc(M_WAITOK). Notes: svn path=/stable/12/; revision=363664
* Do pass removing some write-only variables from the kernel.Alexander Kabaev2017-12-251-13/+1
| | | | | | | | | | | | This reduces noise when kernel is compiled by newer GCC versions, such as one used by external toolchain ports. Reviewed by: kib, andrew(sys/arm and sys/arm64), emaste(partial), erj(partial) Reviewed by: jhb (sys/dev/pci/* sys/kern/vfs_aio.c and sys/kern/kern_synch.c) Differential Revision: https://reviews.freebsd.org/D10385 Notes: svn path=/head/; revision=327173
* sys/dev: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326255
* Improve USB polling mode by not locking any mutexes, asserting anyHans Petter Selasky2016-09-141-3/+3
| | | | | | | | | | | | | | | | | | | | | mutexes or using any callouts when active. Trying to lock a mutex when KDB is active or the scheduler is stopped can result in infinite wait loops. The same goes for calling callout related functions which in turn lock mutexes. If the USB controller at which a USB keyboard is connected is idle when KDB is entered, polling the USB keyboard via USB will always succeed. Else polling may fail depending on which state the USB subsystem and USB interrupt handler is in. This is unavoidable unless KDB can wait for USB interrupt threads to complete before stalling the CPU(s). Tested by: Bruce Evans <bde@freebsd.org> MFC after: 4 weeks Notes: svn path=/head/; revision=305806
* Check for signals when locking the USB enumeration thread fromHans Petter Selasky2016-05-251-1/+7
| | | | | | | | | | userspace, so that USB applications can be killed if an enumeration thread should be stuck for various reasons. MFC after: 1 week Notes: svn path=/head/; revision=300667
* dev/usb: minor spelling fixes in comments.Pedro F. Giffuni2016-05-021-1/+1
| | | | | | | | | No functional change. Reviewed by: hselasky Notes: svn path=/head/; revision=298932
* Don't wait forever for USB data to be flushed.Hans Petter Selasky2015-06-051-1/+2
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=284011
* Resolve a special case deadlock: When two or more threads areHans Petter Selasky2015-01-131-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | simultaneously detaching kernel drivers on the same USB device we can get stuck in the "usb_wait_pending_ref_locked()" function because the conditions needed for allowing detach are not met. The "destroy_dev()" function waits for all system calls involving the given character device to return. Character device system calls may lock the USB enumeration lock, which is also held when "destroy_dev()" is called. This can sometimes lead to a deadlock not noticed by WITNESS. The current solution is to ensure the calling thread is the only one holding the USB enumeration lock and prevent other threads from getting refs while a USB device detach is ongoing. This turned out not to be sufficient. To solve this deadlock we could use "destroy_dev_sched()" to schedule the device destruction in the background, but then we don't know when it is safe to free() the private data of the character device. Instead a callback function is executed by the USB explore process to kill off any leftover USB character devices synchronously after the USB device explore code is finished and the USB enumeration lock is no longer locked. This makes porting easier and also ensures us that character devices must eventually go away after a USB device detach. While at it ensure that "flag_iserror" is only written when "priv_mtx" is locked, which is protecting it. MFC after: 5 days Notes: svn path=/head/; revision=277136
* When we fail to get a USB reference we should just return, becauseHans Petter Selasky2014-10-031-9/+12
| | | | | | | | | there are no more references held. MFC after: 3 days Notes: svn path=/head/; revision=272480
* Pull in r267961 and r267973 again. Fix for issues reported will follow.Hans Petter Selasky2014-06-281-2/+1
| | | | Notes: svn path=/head/; revision=267992
* Revert r267961, r267973:Glen Barber2014-06-271-1/+2
| | | | | | | | | | | | | These changes prevent sysctl(8) from returning proper output, such as: 1) no output from sysctl(8) 2) erroneously returning ENOMEM with tools like truss(1) or uname(1) truss: can not get etype: Cannot allocate memory Notes: svn path=/head/; revision=267985
* Extend the meaning of the CTLFLAG_TUN flag to automatically check ifHans Petter Selasky2014-06-271-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | there is an environment variable which shall initialize the SYSCTL during early boot. This works for all SYSCTL types both statically and dynamically created ones, except for the SYSCTL NODE type and SYSCTLs which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to be used in the case a tunable sysctl has a custom initialisation function allowing the sysctl to still be marked as a tunable. The kernel SYSCTL API is mostly the same, with a few exceptions for some special operations like iterating childrens of a static/extern SYSCTL node. This operation should probably be made into a factored out common macro, hence some device drivers use this. The reason for changing the SYSCTL API was the need for a SYSCTL parent OID pointer and not only the SYSCTL parent OID list pointer in order to quickly generate the sysctl path. The motivation behind this patch is to avoid parameter loading cludges inside the OFED driver subsystem. Instead of adding special code to the OFED driver subsystem to post-load tunables into dynamically created sysctls, we generalize this in the kernel. Other changes: - Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask" to "hw.pcic.intr_mask". - Removed redundant TUNABLE statements throughout the kernel. - Some minor code rewrites in connection to removing not needed TUNABLE statements. - Added a missing SYSCTL_DECL(). - Wrapped two very long lines. - Avoid malloc()/free() inside sysctl string handling, in case it is called to initialize a sysctl from a tunable, hence malloc()/free() is not ready when sysctls from the sysctl dataset are registered. - Bumped FreeBSD version to indicate SYSCTL API change. MFC after: 2 weeks Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=267961
* Resolve a deadlock setting the USB configuration index from userspaceHans Petter Selasky2014-06-081-3/+8
| | | | | | | | | | | | | on USB HUBs by moving the code into the USB explore threads. The deadlock happens because child devices of the USB HUB don't have the expected reference count when called from outside the explore thread. Only the HUB device itself, which the IOCTL interface locks, gets the correct reference count. MFC after: 3 days Notes: svn path=/head/; revision=267240
* Try to resolve a possible deadlock when detaching USB devices whichHans Petter Selasky2014-03-201-10/+9
| | | | | | | | | | | | | | | | | create character devices. The deadlock can happen if an application is issuing IOCTLs which require USB refcounting, at the same time the USB device is detaching. There is already a counter in place in the USB device structure to detect this situation, but it was not always checked ahead of invoking functions that might destroy character devices, like detach, set configuration, set alternate interface or detach active kernel driver. Reported by: Daniel O'Connor <doconnor@gsoft.com.au> MFC after: 1 week Notes: svn path=/head/; revision=263423
* Clear the knote list before destroying it.Hans Petter Selasky2014-02-271-0/+2
| | | | | | | | | | Add seldrain() to wakeup any pollers. Submitted by: Kohji Okuno <okuno.kohji@jp.panasonic.com> MFC after: 2 weeks Notes: svn path=/head/; revision=262554
* Add missing call to "knlist_destroy()".Hans Petter Selasky2014-02-271-15/+11
| | | | | | | | Found by: John-Mark Gurney <jmg@funkthat.com> MFC after: 2 weeks Notes: svn path=/head/; revision=262551
* Add support for kqfilter to USB character devices.Hans Petter Selasky2014-02-271-2/+171
| | | | | | | | Submitted by: Kohji Okuno <okuno.kohji@jp.panasonic.com> MFC after: 2 weeks Notes: svn path=/head/; revision=262550
* Hide now harmless warning from dmesg.Hans Petter Selasky2014-01-241-1/+1
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=261123
* Fix a possible memory use after free and leak situation associatedHans Petter Selasky2014-01-171-16/+10
| | | | | | | | | | | | | | with USB device detach when using character device handles. This also includes LibUSB. It turns out that "usb_close()" cannot always get a reference to clean up its USB transfers and such, if called during the kernel USB device detach. Analysis by: hselasky @ Reported by: Juergen Lock <nox@jelal.kn-bremen.de> MFC after: 1 week Notes: svn path=/head/; revision=260814
* Close a minor deadlock.Hans Petter Selasky2014-01-171-0/+7
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=260808
* Fix a deadlock when trying to power off a USB device. The deadlockHans Petter Selasky2013-10-271-1/+1
| | | | | | | | | | happens because the code in question is trying to modify the parent USB port registers outside the USB explore thread. MFC after: 3 days Notes: svn path=/head/; revision=257206
* Resolve a LOR after r246616. Protect control requests using the USB deviceHans Petter Selasky2013-02-131-5/+6
| | | | | | | | | | | | enumeration lock. Make sure all callers of usbd_enum_lock() check the return value. Remove the control transfer specific lock. Bump the FreeBSD version number, hence external USB modules may need to be recompiled due to a USB device structure change. MFC after: 1 week Notes: svn path=/head/; revision=246759
* Modify the FreeBSD USB kernel code so that it can be compiled directlyHans Petter Selasky2013-01-301-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | into the FreeBSD boot loader, typically for non-USB aware BIOSes, EFI systems or embedded platforms. This is also useful for out of the system compilation of the FreeBSD USB stack for various purposes. The USB kernel files can now optionally include a global header file which should include all needed definitions required to compile the FreeBSD USB stack. When the global USB header file is included, no other USB header files will be included by default. Add new file containing the USB stack configuration for the FreeBSD loader build. Replace some __FBSDID()'s by /* $FreeBSD$ */ comments. Now all USB files follow the same style. Use cases: - console in loader via USB - loading kernel via USB Discussed with: Hiroki Sato, hrs @ EuroBSDCon Notes: svn path=/head/; revision=246122
* Add missing CTLFLAG_TUN flag to tunable sysctls in USB stack.Hans Petter Selasky2012-10-261-2/+1
| | | | | | | | | | | Rearrange the tunables and belonging sysctl declarations, so that they are next to eachother. Submitted by: n_hibma @ MFC after: 1 week Notes: svn path=/head/; revision=242126
* Fix compiler warnings, mostly signed issues,Hans Petter Selasky2012-04-021-3/+3
| | | | | | | | | when USB modules are compiled with WARNS=9. MFC after: 1 weeks Notes: svn path=/head/; revision=233774
* Remove direct access to si_name.Ed Schouten2012-02-101-1/+1
| | | | | | | | | | | Code should just use the devtoname() function to obtain the name of a character device. Also add const keywords to pieces of code that need it to build properly. MFC after: 2 weeks Notes: svn path=/head/; revision=231378
* Style change.Hans Petter Selasky2011-11-121-4/+4
| | | | | | | | | | | | | | | - Make it easier to port the USB code to other platforms by only using one set of memory functions for clearing and copying memory. None of the memory copies are overlapping. This means using bcopy() is not required. - Fix a compile warning when USB_HAVE_BUSDMA=0 - Add missing semicolon in avr32dci. - Update some comments. MFC after: 1 week Notes: svn path=/head/; revision=227461
* Mark all SYSCTL_NODEs static that have no corresponding SYSCTL_DECLs.Ed Schouten2011-11-071-1/+1
| | | | | | | | | The SYSCTL_NODE macro defines a list that stores all child-elements of that node. If there's no SYSCTL_DECL macro anywhere else, there's no reason why it shouldn't be static. Notes: svn path=/head/; revision=227309
* In order to maximize the re-usability of kernel code in user space thisKip Macy2011-09-161-2/+2
| | | | | | | | | | | | | | | | patch modifies makesyscalls.sh to prefix all of the non-compatibility calls (e.g. not linux_, freebsd32_) with sys_ and updates the kernel entry points and all places in the code that use them. It also fixes an additional name space collision between the kernel function psignal and the libc function of the same name by renaming the kernel psignal kern_psignal(). By introducing this change now we will ease future MFCs that change syscalls. Reviewed by: rwatson Approved by: re (bz) Notes: svn path=/head/; revision=225617
* Fix for recursive locking in usb_close() after change 224777.Hans Petter Selasky2011-08-201-6/+18
| | | | | | | | | Approved by: re (kib) MFC after: 3 days Reported by: kwm @ Notes: svn path=/head/; revision=225038
* Use synchronous device destruction instead of asynchronous, so that a newHans Petter Selasky2011-08-111-28/+7
| | | | | | | | | | | | device having the same name like a previous one is not created before the old one is gone. This fixes some panics due to asserts in the devfs code which were added recently. Approved by: re (kib) MFC after: 1 week Notes: svn path=/head/; revision=224777
* Remove unneeded includes of <sys/linker_set.h>. Other headers that useJohn Baldwin2011-01-111-1/+0
| | | | | | | | | it internally contain nested includes. Reviewed by: bde Notes: svn path=/head/; revision=217265
* Serialise USB re-enumeration with the USB explore thread.Hans Petter Selasky2010-10-041-13/+36
| | | | | | | | | | This patch can solve problems when multiple USB devices are re-enumerated at the same time on the same bus. Approved by: thompsa (mentor) Notes: svn path=/head/; revision=213432
* Correct IOCTL return code.Hans Petter Selasky2010-10-041-1/+5
| | | | | | | Approved by: thompsa (mentor) Notes: svn path=/head/; revision=213431
* fix a few cases where a string is passed via format argument instead ofAndriy Gapon2010-06-111-1/+1
| | | | | | | | | | | | | via %s Most of the cases looked harmless, but this is done for the sake of correctness. In one case it even allowed to drop an intermediate buffer. Found by: clang MFC after: 2 week Notes: svn path=/head/; revision=209062
* Staticise usb_ref_device and usb_unref_device.Andrew Thompson2010-05-121-2/+2
| | | | | | | Submitted by: Hans Petter Selasky Notes: svn path=/head/; revision=208007
* Use a more obvious prefix for the USB control (endpoint 0) transfers ratherAndrew Thompson2010-04-221-1/+1
| | | | | | | than default_*. Notes: svn path=/head/; revision=207080
* Properly name the sxlocks, mutexes and condvars.Andrew Thompson2010-04-221-4/+4
| | | | Notes: svn path=/head/; revision=207079
* Remove overuse of exclamation marks in kernel printfs, there mere fact aAndrew Thompson2009-11-261-2/+2
| | | | | | | | | message has been printed is enough to get someones attention. Also remove the line number for DPRINTF/DPRINTFN, it already prints the funtion name and a unique message. Notes: svn path=/head/; revision=199816
* Provide tunables for some of the usb sysctls that affect boot behaviour.Andrew Thompson2009-11-221-0/+2
| | | | | | | Submitted by: Andriy Gapon Notes: svn path=/head/; revision=199675
* - Patch to allow USB controller to resume operation afterAlfred Perlstein2009-08-241-11/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | being polled. - Remove the need for Giant from the USB HUB driver. - Leave device unconfigured instead of disabling the USB port when Huawei Autoinstall disk detection triggers. This should fix problems that the Huawei device is not detected after Autoinstall eject is issued. - Reported by: Nikolay Antsiferov - Fix memory use after free race for USB character devices. - Reported by: Lucius Windschuh - Factor out the enumeration lock into three functions to make the coming newbus lock conversion more easy. - usbd_enum_lock - usbd_enum_unlock - usbd_enum_is_locked Submitted by: hps Notes: svn path=/head/; revision=196498
* Temporarily revert the new-bus locking for 8.0 release. It will beJohn Baldwin2009-08-201-6/+0
| | | | | | | | | reintroduced after HEAD is reopened for commits by re@. Approved by: re (kib), attilio Notes: svn path=/head/; revision=196403
* Make the newbus subsystem Giant free by adding the new newbus sxlock.Attilio Rao2009-08-021-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The newbus lock is responsible for protecting newbus internIal structures, device states and devclass flags. It is necessary to hold it when all such datas are accessed. For the other operations, softc locking should ensure enough protection to avoid races. Newbus lock is automatically held when virtual operations on the device and bus are invoked when loading the driver or when the suspend/resume take place. For other 'spourious' operations trying to access/modify the newbus topology, newbus lock needs to be automatically acquired and dropped. For the moment Giant is also acquired in some key point (modules subsystem) in order to avoid problems before the 8.0 release as module handlers could make assumptions about it. This Giant locking should go just after the release happens. Please keep in mind that the public interface can be expanded in order to provide more support, if there are really necessities at some point and also some bugs could arise as long as the patch needs a bit of further testing. Bump __FreeBSD_version in order to reflect the newbus lock introduction. Reviewed by: ed, hps, jhb, imp, mav, scottl No answer by: ariff, thompsa, yongari Tested by: pho, G. Trematerra <giovanni dot trematerra at gmail dot com>, Brandon Gooch <jamesbrandongooch at gmail dot com> Sponsored by: Yahoo! Incorporated Approved by: re (ksmith) Notes: svn path=/head/; revision=196037
* USB core:Alfred Perlstein2009-07-301-16/+67
| | | | | | | | | | | | | | | | | | - add support for defragging of written device data. - improve handling of alternate settings in device side mode. - correct return value from usbd_get_no_alts() function. - reported by: HPS - P4 ID: 166156, 166168 - report USB device release information to devd and pnpinfo. - reported by: MIHIRA Sanpei Yoshiro - P4 ID: 166221 Submitted by: hps Approved by: re Notes: svn path=/head/; revision=195963
* - Make struct usb_xfer opaque so that drivers can not access the internalsAndrew Thompson2009-06-231-4/+33
| | | | | | | - Reduce the number of headers needed for a usb driver, the common case is just usb.h and usbdi.h Notes: svn path=/head/; revision=194677
* s/usb2_/usb_|usbd_/ on all function names for the USB stack.Andrew Thompson2009-06-151-233/+233
| | | | Notes: svn path=/head/; revision=194228
* Remove usb2_cv_* and just use the kernel condvar implementation, it was neededAndrew Thompson2009-06-151-13/+13
| | | | | | | | earlier since condition variables didnt work with Giant but this was fixed 10 months ago. Notes: svn path=/head/; revision=194227
* Make variables static where appropriate.Andrew Thompson2009-06-131-1/+1
| | | | | | | Found by: cscout Notes: svn path=/head/; revision=194099
* Rename usb pipes to endpoints as it better represents what they are, and structAndrew Thompson2009-06-071-34/+34
| | | | | | | usb_pipe may be used for a different purpose later on. Notes: svn path=/head/; revision=193644