---
name: "usb_set_device_state"
section: "9"
platform: "linux"
package: "linux-manual-4.9"
version: "4.9.228-1"
release: "Debian 9 (Stretch)"
platforms: ["linux"]
url: "https://new.carta.tech/usb_set_device_state"
---

# usb\_set\_device\_state(9)

change a device's current state (usbcore, hcds)

## NAME

usb\_set\_device\_state - change a device's current state (usbcore, hcds)

## SYNOPSIS

**void usb\_set\_device\_state(struct usb\_device \*** *udev***, enum usb\_device\_state** *new\_state***);**

## ARGUMENTS

*udev*

pointer to device whose state should be changed

*new\_state*

new state value to be stored

## DESCRIPTION

udev-\>state is \_not\_ fully protected by the device lock. Although most transitions are made only while holding the lock, the state can can change to USB\_STATE\_NOTATTACHED at almost any time. This is so that devices can be marked as disconnected as soon as possible, without having to wait for any semaphores to be released. As a result, all changes to any device's state must be protected by the device\_state\_lock spinlock.

Once a device has been added to the device tree, all changes to its state should be made using this routine. The state should \_not\_ be set directly.

If udev-\>state is already USB\_STATE\_NOTATTACHED then no change is made. Otherwise udev-\>state is set to new\_state, and if new\_state is USB\_STATE\_NOTATTACHED then all of udev's descendants' states are also set to USB\_STATE\_NOTATTACHED.

## COPYRIGHT
