Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH rtw-next] wifi: rtw89: usb: Avoid crash with dynamically added device ID
@ 2026-08-16 18:20 Bitterblue Smith
  2026-08-17  3:38 ` Ping-Ke Shih
  0 siblings, 1 reply; 3+ messages in thread
From: Bitterblue Smith @ 2026-08-16 18:20 UTC (permalink / raw)
  To: linux-wireless@vger.kernel.org; +Cc: Ping-Ke Shih

Adding a device ID via sysfs causes a crash when the device is plugged
in, because the driver_info pointer is null.

Add a wrapper around rtw89_usb_probe() in each driver to check if
driver_info is null and provide a reasonable default value for it.

Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
The PCI side has the same problem, but new device IDs are a lot less
likely there.
---
 drivers/net/wireless/realtek/rtw89/rtw8851bu.c | 15 ++++++++++++++-
 drivers/net/wireless/realtek/rtw89/rtw8852au.c | 15 ++++++++++++++-
 drivers/net/wireless/realtek/rtw89/rtw8852bu.c | 15 ++++++++++++++-
 drivers/net/wireless/realtek/rtw89/rtw8852cu.c | 15 ++++++++++++++-
 drivers/net/wireless/realtek/rtw89/rtw8922au.c | 15 ++++++++++++++-
 drivers/net/wireless/realtek/rtw89/usb.c       |  5 +----
 drivers/net/wireless/realtek/rtw89/usb.h       |  2 +-
 7 files changed, 72 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw89/rtw8851bu.c b/drivers/net/wireless/realtek/rtw89/rtw8851bu.c
index 1e827205f254..432d216de874 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8851bu.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8851bu.c
@@ -59,10 +59,23 @@ static const struct usb_device_id rtw_8851bu_id_table[] = {
 };
 MODULE_DEVICE_TABLE(usb, rtw_8851bu_id_table);
 
+static int rtw8851bu_probe(struct usb_interface *intf,
+			   const struct usb_device_id *id)
+{
+	const struct rtw89_driver_info *info;
+
+	if (id->driver_info)
+		info = (const struct rtw89_driver_info *)id->driver_info;
+	else
+		info = &rtw89_8851bu_info;
+
+	return rtw89_usb_probe(intf, info);
+}
+
 static struct usb_driver rtw_8851bu_driver = {
 	.name = KBUILD_MODNAME,
 	.id_table = rtw_8851bu_id_table,
-	.probe = rtw89_usb_probe,
+	.probe = rtw8851bu_probe,
 	.disconnect = rtw89_usb_disconnect,
 };
 module_usb_driver(rtw_8851bu_driver);
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852au.c b/drivers/net/wireless/realtek/rtw89/rtw8852au.c
index 065f4e5b17af..a37b60b584f2 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8852au.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8852au.c
@@ -73,10 +73,23 @@ static const struct usb_device_id rtw_8852au_id_table[] = {
 };
 MODULE_DEVICE_TABLE(usb, rtw_8852au_id_table);
 
+static int rtw8852au_probe(struct usb_interface *intf,
+			   const struct usb_device_id *id)
+{
+	const struct rtw89_driver_info *info;
+
+	if (id->driver_info)
+		info = (const struct rtw89_driver_info *)id->driver_info;
+	else
+		info = &rtw89_8852au_info;
+
+	return rtw89_usb_probe(intf, info);
+}
+
 static struct usb_driver rtw_8852au_driver = {
 	.name = KBUILD_MODNAME,
 	.id_table = rtw_8852au_id_table,
-	.probe = rtw89_usb_probe,
+	.probe = rtw8852au_probe,
 	.disconnect = rtw89_usb_disconnect,
 };
 module_usb_driver(rtw_8852au_driver);
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852bu.c b/drivers/net/wireless/realtek/rtw89/rtw8852bu.c
index de79a19a2824..81b6156a8d27 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8852bu.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8852bu.c
@@ -73,10 +73,23 @@ static const struct usb_device_id rtw_8852bu_id_table[] = {
 };
 MODULE_DEVICE_TABLE(usb, rtw_8852bu_id_table);
 
+static int rtw8852bu_probe(struct usb_interface *intf,
+			   const struct usb_device_id *id)
+{
+	const struct rtw89_driver_info *info;
+
+	if (id->driver_info)
+		info = (const struct rtw89_driver_info *)id->driver_info;
+	else
+		info = &rtw89_8852bu_info;
+
+	return rtw89_usb_probe(intf, info);
+}
+
 static struct usb_driver rtw_8852bu_driver = {
 	.name = KBUILD_MODNAME,
 	.id_table = rtw_8852bu_id_table,
-	.probe = rtw89_usb_probe,
+	.probe = rtw8852bu_probe,
 	.disconnect = rtw89_usb_disconnect,
 };
 module_usb_driver(rtw_8852bu_driver);
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852cu.c b/drivers/net/wireless/realtek/rtw89/rtw8852cu.c
index 2dec9b845481..067c6bb007b3 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8852cu.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8852cu.c
@@ -133,10 +133,23 @@ static const struct usb_device_id rtw_8852cu_id_table[] = {
 };
 MODULE_DEVICE_TABLE(usb, rtw_8852cu_id_table);
 
+static int rtw8852cu_probe(struct usb_interface *intf,
+			   const struct usb_device_id *id)
+{
+	const struct rtw89_driver_info *info;
+
+	if (id->driver_info)
+		info = (const struct rtw89_driver_info *)id->driver_info;
+	else
+		info = &rtw89_8852cu_info;
+
+	return rtw89_usb_probe(intf, info);
+}
+
 static struct usb_driver rtw_8852cu_driver = {
 	.name = KBUILD_MODNAME,
 	.id_table = rtw_8852cu_id_table,
-	.probe = rtw89_usb_probe,
+	.probe = rtw8852cu_probe,
 	.disconnect = rtw89_usb_disconnect,
 };
 module_usb_driver(rtw_8852cu_driver);
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922au.c b/drivers/net/wireless/realtek/rtw89/rtw8922au.c
index 56c79b1ec865..2f60021704e0 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8922au.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8922au.c
@@ -74,10 +74,23 @@ static const struct usb_device_id rtw_8922au_id_table[] = {
 };
 MODULE_DEVICE_TABLE(usb, rtw_8922au_id_table);
 
+static int rtw8922au_probe(struct usb_interface *intf,
+			   const struct usb_device_id *id)
+{
+	const struct rtw89_driver_info *info;
+
+	if (id->driver_info)
+		info = (const struct rtw89_driver_info *)id->driver_info;
+	else
+		info = &rtw89_8922au_info;
+
+	return rtw89_usb_probe(intf, info);
+}
+
 static struct usb_driver rtw_8922au_driver = {
 	.name = KBUILD_MODNAME,
 	.id_table = rtw_8922au_id_table,
-	.probe = rtw89_usb_probe,
+	.probe = rtw8922au_probe,
 	.disconnect = rtw89_usb_disconnect,
 };
 module_usb_driver(rtw_8922au_driver);
diff --git a/drivers/net/wireless/realtek/rtw89/usb.c b/drivers/net/wireless/realtek/rtw89/usb.c
index 6f19d0eb3417..1cdf5b812ed4 100644
--- a/drivers/net/wireless/realtek/rtw89/usb.c
+++ b/drivers/net/wireless/realtek/rtw89/usb.c
@@ -1207,15 +1207,12 @@ static const struct attribute_group rtw89_usb_group = {
 __ATTRIBUTE_GROUPS(rtw89_usb);
 
 int rtw89_usb_probe(struct usb_interface *intf,
-		    const struct usb_device_id *id)
+		    const struct rtw89_driver_info *info)
 {
-	const struct rtw89_driver_info *info;
 	struct rtw89_dev *rtwdev;
 	struct rtw89_usb *rtwusb;
 	int ret;
 
-	info = (const struct rtw89_driver_info *)id->driver_info;
-
 	rtwdev = rtw89_alloc_ieee80211_hw(&intf->dev,
 					  sizeof(struct rtw89_usb), info);
 	if (!rtwdev) {
diff --git a/drivers/net/wireless/realtek/rtw89/usb.h b/drivers/net/wireless/realtek/rtw89/usb.h
index bdf312559743..372620d0851e 100644
--- a/drivers/net/wireless/realtek/rtw89/usb.h
+++ b/drivers/net/wireless/realtek/rtw89/usb.h
@@ -95,7 +95,7 @@ static inline struct rtw89_usb *rtw89_usb_priv(struct rtw89_dev *rtwdev)
 }
 
 int rtw89_usb_probe(struct usb_interface *intf,
-		    const struct usb_device_id *id);
+		    const struct rtw89_driver_info *info);
 void rtw89_usb_disconnect(struct usb_interface *intf);
 
 #endif
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH rtw-next] wifi: rtw89: usb: Avoid crash with dynamically added device ID
  2026-08-16 18:20 [PATCH rtw-next] wifi: rtw89: usb: Avoid crash with dynamically added device ID Bitterblue Smith
@ 2026-08-17  3:38 ` Ping-Ke Shih
  2026-08-17 15:24   ` Bitterblue Smith
  0 siblings, 1 reply; 3+ messages in thread
From: Ping-Ke Shih @ 2026-08-17  3:38 UTC (permalink / raw)
  To: Bitterblue Smith, linux-wireless@vger.kernel.org

Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
> Adding a device ID via sysfs causes a crash when the device is plugged
> in, because the driver_info pointer is null.

I don't know about this before. Does it looks like?

   echo "1234 5678" | sudo tee /sys/bus/usb/drivers/my_driver/new_id

> 
> Add a wrapper around rtw89_usb_probe() in each driver to check if
> driver_info is null and provide a reasonable default value for it.
> 
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>

Acked-by: Ping-Ke Shih <pkshih@realtek.com>

I'd give my acked-by in advance. But you still can consider my opinion below.

> ---
> The PCI side has the same problem, but new device IDs are a lot less
> likely there.

Thanks for the info.

[...]

> +static int rtw8851bu_probe(struct usb_interface *intf,
> +                          const struct usb_device_id *id)
> +{
> +       const struct rtw89_driver_info *info;
> +
> +       if (id->driver_info)
> +               info = (const struct rtw89_driver_info *)id->driver_info;
> +       else
> +               info = &rtw89_8851bu_info;
> +
> +       return rtw89_usb_probe(intf, info);
> +}
> +

If you want to simply specific probe(), here might be 

static int rtw8851bu_probe(struct usb_interface *intf,
                           const struct usb_device_id *id)
{
        return rtw89_usb_probe(intf, id, &rtw89_8851bu_info);
}

Then

int rtw89_usb_probe(struct usb_interface *intf,
                    const struct usb_device_id *id,
                    const struct rtw89_driver_info *default_info)
{
        ...

        info = (const struct rtw89_driver_info *)id->driver_info;
        if (!info)
                info = default_info;
}



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH rtw-next] wifi: rtw89: usb: Avoid crash with dynamically added device ID
  2026-08-17  3:38 ` Ping-Ke Shih
@ 2026-08-17 15:24   ` Bitterblue Smith
  0 siblings, 0 replies; 3+ messages in thread
From: Bitterblue Smith @ 2026-08-17 15:24 UTC (permalink / raw)
  To: Ping-Ke Shih, linux-wireless@vger.kernel.org

On 17/08/2026 06:38, Ping-Ke Shih wrote:
> Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:
>> Adding a device ID via sysfs causes a crash when the device is plugged
>> in, because the driver_info pointer is null.
> 
> I don't know about this before. Does it looks like?
> 
>    echo "1234 5678" | sudo tee /sys/bus/usb/drivers/my_driver/new_id
> 

Yes, like that. A few people have tried to use it recently to test new
devices and got crashes.

>>
>> Add a wrapper around rtw89_usb_probe() in each driver to check if
>> driver_info is null and provide a reasonable default value for it.
>>
>> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> 
> Acked-by: Ping-Ke Shih <pkshih@realtek.com>
> 
> I'd give my acked-by in advance. But you still can consider my opinion below.
> 
>> ---
>> The PCI side has the same problem, but new device IDs are a lot less
>> likely there.
> 
> Thanks for the info.
> 
> [...]
> 
>> +static int rtw8851bu_probe(struct usb_interface *intf,
>> +                          const struct usb_device_id *id)
>> +{
>> +       const struct rtw89_driver_info *info;
>> +
>> +       if (id->driver_info)
>> +               info = (const struct rtw89_driver_info *)id->driver_info;
>> +       else
>> +               info = &rtw89_8851bu_info;
>> +
>> +       return rtw89_usb_probe(intf, info);
>> +}
>> +
> 
> If you want to simply specific probe(), here might be 
> 
> static int rtw8851bu_probe(struct usb_interface *intf,
>                            const struct usb_device_id *id)
> {
>         return rtw89_usb_probe(intf, id, &rtw89_8851bu_info);
> }
> 
> Then
> 
> int rtw89_usb_probe(struct usb_interface *intf,
>                     const struct usb_device_id *id,
>                     const struct rtw89_driver_info *default_info)
> {
>         ...
> 
>         info = (const struct rtw89_driver_info *)id->driver_info;
>         if (!info)
>                 info = default_info;
> }
> 
> 

Ah, yes, that is better.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-17 15:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-16 18:20 [PATCH rtw-next] wifi: rtw89: usb: Avoid crash with dynamically added device ID Bitterblue Smith
2026-08-17  3:38 ` Ping-Ke Shih
2026-08-17 15:24   ` Bitterblue Smith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox