Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: core: Centralize device state update logic

Introduce a new static function, update_usb_device_state(), to
centralize the process of changing a device's state, including the
management of active_duration during suspend/resume transitions.

This change prepares for adding tracepoints, allowing tracing logic to
be added in a single, central location within the new helper function.

Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://patch.msgid.link/20251015-usbcore-tracing-v2-1-5a14b5b9d4e0@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kuen-Han Tsai and committed by
Greg Kroah-Hartman
c05ebd0e 877c80df

+16 -12
+16 -12
drivers/usb/core/hub.c
··· 2142 2142 } 2143 2143 } 2144 2144 2145 + static void update_usb_device_state(struct usb_device *udev, 2146 + enum usb_device_state new_state) 2147 + { 2148 + if (udev->state == USB_STATE_SUSPENDED && 2149 + new_state != USB_STATE_SUSPENDED) 2150 + udev->active_duration -= jiffies; 2151 + else if (new_state == USB_STATE_SUSPENDED && 2152 + udev->state != USB_STATE_SUSPENDED) 2153 + udev->active_duration += jiffies; 2154 + 2155 + udev->state = new_state; 2156 + update_port_device_state(udev); 2157 + } 2158 + 2145 2159 static void recursively_mark_NOTATTACHED(struct usb_device *udev) 2146 2160 { 2147 2161 struct usb_hub *hub = usb_hub_to_struct_hub(udev); ··· 2165 2151 if (hub->ports[i]->child) 2166 2152 recursively_mark_NOTATTACHED(hub->ports[i]->child); 2167 2153 } 2168 - if (udev->state == USB_STATE_SUSPENDED) 2169 - udev->active_duration -= jiffies; 2170 - udev->state = USB_STATE_NOTATTACHED; 2171 - update_port_device_state(udev); 2154 + update_usb_device_state(udev, USB_STATE_NOTATTACHED); 2172 2155 } 2173 2156 2174 2157 /** ··· 2215 2204 else 2216 2205 wakeup = 0; 2217 2206 } 2218 - if (udev->state == USB_STATE_SUSPENDED && 2219 - new_state != USB_STATE_SUSPENDED) 2220 - udev->active_duration -= jiffies; 2221 - else if (new_state == USB_STATE_SUSPENDED && 2222 - udev->state != USB_STATE_SUSPENDED) 2223 - udev->active_duration += jiffies; 2224 - udev->state = new_state; 2225 - update_port_device_state(udev); 2207 + update_usb_device_state(udev, new_state); 2226 2208 } else 2227 2209 recursively_mark_NOTATTACHED(udev); 2228 2210 spin_unlock_irqrestore(&device_state_lock, flags);