mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
The net_device is allocated during function instance creation and
registered during the bind phase with the gadget device as its sysfs
parent. When the function unbinds, the parent device is destroyed, but
the net_device survives, resulting in dangling sysfs symlinks:
console:/ # ls -l /sys/class/net/usb0
lrwxrwxrwx ... /sys/class/net/usb0 ->
/sys/devices/platform/.../gadget.0/net/usb0
console:/ # ls -l /sys/devices/platform/.../gadget.0/net/usb0
ls: .../gadget.0/net/usb0: No such file or directory
Use device_move() to reparent the net_device between the gadget device
tree and /sys/devices/virtual across bind and unbind cycles. During the
final unbind, calling device_move(NULL) moves the net_device to the
virtual device tree before the gadget device is destroyed. On rebinding,
device_move() reparents the device back under the new gadget, ensuring
proper sysfs topology and power management ordering.
To maintain compatibility with legacy composite drivers (e.g., multi.c),
the bound flag is used to indicate whether the network device is shared
and pre-registered during the legacy driver's bind phase.
Fixes: 8cedba7c73 ("usb: gadget: f_subset: convert to new function interface with backward compatibility")
Cc: stable@vger.kernel.org
Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
Link: https://patch.msgid.link/20260320-usb-net-lifecycle-v1-6-4886b578161b@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
42 lines
1.2 KiB
C
42 lines
1.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* u_gether.h
|
|
*
|
|
* Utility definitions for the subset function
|
|
*
|
|
* Copyright (c) 2013 Samsung Electronics Co., Ltd.
|
|
* http://www.samsung.com
|
|
*
|
|
* Author: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>
|
|
*/
|
|
|
|
#ifndef U_GETHER_H
|
|
#define U_GETHER_H
|
|
|
|
#include <linux/usb/composite.h>
|
|
|
|
/**
|
|
* struct f_gether_opts - subset function options
|
|
* @func_inst: USB function instance.
|
|
* @net: The net_device associated with the subset function.
|
|
* @bound: True if the net_device is shared and pre-registered during the
|
|
* legacy composite driver's bind phase (e.g., multi.c). If false,
|
|
* the subset function will register the net_device during its own
|
|
* bind phase.
|
|
* @bind_count: Tracks the number of configurations the subset function is
|
|
* bound to, preventing double-registration of the @net device.
|
|
* @lock: Protects the data from concurrent access by configfs read/write
|
|
* and create symlink/remove symlink operations.
|
|
* @refcnt: Reference counter for the function instance.
|
|
*/
|
|
struct f_gether_opts {
|
|
struct usb_function_instance func_inst;
|
|
struct net_device *net;
|
|
bool bound;
|
|
int bind_count;
|
|
struct mutex lock;
|
|
int refcnt;
|
|
};
|
|
|
|
#endif /* U_GETHER_H */
|