From: Oliver Neukum <oneukum@suse.com>
To: andrew@lunn.ch, bjorn@mork.no, netdev@vger.kernel.org
Cc: Oliver Neukum <oneukum@suse.com>
Subject: [RFCv2 08/13] net: usb: usbnet: allow drivers to specify private space needed
Date: Tue, 3 Mar 2026 15:50:28 +0100 [thread overview]
Message-ID: <20260303145242.1377514-8-oneukum@suse.com> (raw)
In-Reply-To: <20260303145242.1377514-1-oneukum@suse.com>
usbnet has been providing a fixed space of unsigned long[5]
for minidrivers. This has led to various constructions in drivers
this is not enough space for.
Allow minidrivers to tell usbnet how much they need by means
of struct driver_info. For backwards compatibility zero
is taken to mean enough space for unsigned long[5]
Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
drivers/net/usb/qmi_wwan.c | 3 ---
drivers/net/usb/sierra_net.c | 3 ---
drivers/net/usb/usbnet.c | 5 ++++-
include/linux/usb/usbnet.h | 6 +++++-
4 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index 3a4985b582cb..fc2591ccb682 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -753,9 +753,6 @@ static int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf)
struct qmi_wwan_state *info = (void *)&dev->data;
struct usb_cdc_parsed_header hdr;
- BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data) <
- sizeof(struct qmi_wwan_state)));
-
/* set up initial state */
info->control = intf;
info->data = intf;
diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
index 4d3ed642b3e7..5a32796a7a89 100644
--- a/drivers/net/usb/sierra_net.c
+++ b/drivers/net/usb/sierra_net.c
@@ -855,9 +855,6 @@ static struct sk_buff *sierra_net_tx_fixup(struct usbnet *dev,
u16 len;
bool need_tail;
- BUILD_BUG_ON(sizeof_field(struct usbnet, data)
- < sizeof(struct cdc_state));
-
dev_dbg(&dev->udev->dev, "%s", __func__);
if (priv->link_up && check_ethip_packet(skb, dev) && is_ip(skb)) {
/* enough head room as is? */
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 8a9e0d98d9c6..b3cc3428b342 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1734,6 +1734,7 @@ usbnet_probe(struct usb_interface *udev, const struct usb_device_id *prod)
int status;
const char *name;
struct usb_driver *driver = to_usb_driver(udev->dev.driver);
+ unsigned int extra;
/* usbnet already took usb runtime pm, so have to enable the feature
* for usb interface, otherwise usb_autopm_get_interface may return
@@ -1756,7 +1757,9 @@ usbnet_probe(struct usb_interface *udev, const struct usb_device_id *prod)
status = -ENOMEM;
// set up our own records
- net = alloc_etherdev(sizeof(*dev));
+ extra = info->required_room ?
+ info->required_room : 5 * sizeof(unsigned long);
+ net = alloc_etherdev(sizeof(*dev) + extra);
if (!net)
goto out;
diff --git a/include/linux/usb/usbnet.h b/include/linux/usb/usbnet.h
index 766862427620..41582346360f 100644
--- a/include/linux/usb/usbnet.h
+++ b/include/linux/usb/usbnet.h
@@ -50,7 +50,6 @@ struct usbnet {
struct net_device *net;
int msg_enable;
struct cdc_state cdc; /* too common to leave out*/
- unsigned long data[5];
u32 xid;
u32 hard_mtu; /* count any extra framing */
size_t rx_urb_size; /* size for rx urbs */
@@ -93,6 +92,8 @@ struct usbnet {
* that must be broken
*/
# define EVENT_UNPLUG 31
+
+ DECLARE_FLEX_ARRAY(unsigned long, data);
};
static inline bool usbnet_going_away(struct usbnet *ubn)
@@ -142,6 +143,9 @@ struct driver_info {
#define FLAG_RX_ASSEMBLE 0x4000 /* rx packets may span >1 frames */
#define FLAG_NOARP 0x8000 /* device can't do ARP */
+ /* tells us how much private space is need in the descriptor */
+ unsigned int required_room;
+
/* init device ... can sleep, or cause probe() failure */
int (*bind)(struct usbnet *, struct usb_interface *);
--
2.53.0
next prev parent reply other threads:[~2026-03-03 14:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 14:50 [RFCv2 01/13] net: usb: usbnet: use proper ep number macros Oliver Neukum
2026-03-03 14:50 ` [RFCv2 02/13] net: usb: move updating filter and status from cdc to usbnet Oliver Neukum
2026-03-03 14:50 ` [RFCv2 03/13] net: usb: centralize usbnet_cdc_zte_rx_fixup in usbnet Oliver Neukum
2026-03-03 14:50 ` [RFCv2 04/13] net: usb: usbnet: add access helper for private data Oliver Neukum
2026-03-03 14:50 ` [RFCv2 05/13] net: usb: use accessor helper for usbnet " Oliver Neukum
2026-03-03 14:50 ` [RFCv2 06/13] net: usb: usbnet: add cdc_state to struct usbnet Oliver Neukum
2026-03-03 14:50 ` [RFCv2 07/13] net: usb: use cdc_state in " Oliver Neukum
2026-03-03 14:50 ` Oliver Neukum [this message]
2026-03-03 14:50 ` [RFCv2 09/13] net: usb: use allocation on demand for usbnet Oliver Neukum
2026-03-03 14:50 ` [RFCv2 10/13] net: usb: sierra_net: use dynamic private allocation Oliver Neukum
2026-03-03 14:50 ` [RFCv2 11/13] net: usb: cdc_ncm: " Oliver Neukum
2026-03-03 14:50 ` [RFCv2 12/13] net: usb: smsc95xx: " Oliver Neukum
2026-03-03 14:50 ` [RFCv2 13/13] net: usb: lg-vl600: " Oliver Neukum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260303145242.1377514-8-oneukum@suse.com \
--to=oneukum@suse.com \
--cc=andrew@lunn.ch \
--cc=bjorn@mork.no \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox