misc: hisi_hikey_usb: cancel role switch work on remove
PATCH 1/1 misc: hisi_hikey_usb: cancel role switch work on remove
The hub role switch set callback schedules private work that dereferences both driver data and the downstream role switch. Unregistering the hub switch does not drain work already queued, and a callback that fetched driver data before unregister can queue more work during removal.
Mark the instance as removing under its mutex and serialize removal with role switch set callbacks by setting the role to USB_ROLE_NONE. The callback clears the switch driver data when it observes removal and no longer queues work. Unregister the switch, cancel the work, and only then drop the downstream role switch reference.
This issue was found by a static analysis tool.
--- drivers/misc/hisi_hikey_usb.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
drivers/misc/hisi_hikey_usb.c +21 -6
@@ -45,6 +45,7 @@ struct hisi_hikey_usb {struct mutex lock;struct work_struct work; +bool removing;struct notifier_block nb; };
@@ -130,17 +131,23 @@ static void relay_set_role_switch(struct work_struct *work)static int hub_usb_role_switch_set (struct usb_role_switch *sw,enum usb_role role) {struct hisi_hikey_usb *hisi_hikey_usb =usb_role_switch_get_drvdata (sw); +int ret =0 ; -if (!hisi_hikey_usb || !hisi_hikey_usb->dev_role_sw) -return -EINVAL ; +if (!hisi_hikey_usb) +return -ENODEV ;mutex_lock (&hisi_hikey_usb->lock); - hisi_hikey_usb->role = role; +if (hisi_hikey_usb->removing || !hisi_hikey_usb->dev_role_sw) { +if (hisi_hikey_usb->removing) +usb_role_switch_set_drvdata (sw,NULL ); + ret = -ENODEV ; + }else { + hisi_hikey_usb->role = role; +schedule_work (&hisi_hikey_usb->work); + }mutex_unlock (&hisi_hikey_usb->lock); -schedule_work (&hisi_hikey_usb->work); - -return 0 ; +return ret; } static int hisi_hikey_usb_of_role_switch(struct platform_device *pdev,
@@ -244,7 +251,15 @@ static int hisi_hikey_usb_remove(struct platform_device *pdev)struct hisi_hikey_usb *hisi_hikey_usb =platform_get_drvdata (pdev);if (hisi_hikey_usb->hub_role_sw) { +mutex_lock (&hisi_hikey_usb->lock); + hisi_hikey_usb->removing = true; +mutex_unlock (&hisi_hikey_usb->lock); + +/* Serialize with set callbacks and clear their private data. */ +usb_role_switch_set_role (hisi_hikey_usb->hub_role_sw, +USB_ROLE_NONE );usb_role_switch_unregister (hisi_hikey_usb->hub_role_sw); +cancel_work_sync (&hisi_hikey_usb->work);if (hisi_hikey_usb->dev_role_sw)usb_role_switch_put (hisi_hikey_usb->dev_role_sw);
Signature · 1 line
2.50.1.windows.1
Quoted 12 lines · Hongyan Xu
The hub role switch set callback schedules private work that dereferences both driver data and the downstream role switch. Unregistering the hub switch does not drain work already queued, and a callback that fetched driver data before unregister can queue more work during removal.
Mark the instance as removing under its mutex and serialize removal with role switch set callbacks by setting the role to
USB_ROLE_NONE. The callback clears the switch driver data when it observes removal and no longer queues work. Unregister the switch, cancel the work, and only then drop the downstream role switch reference.
Quoted 7 lines
This issue was found by a static analysis tool.
Signed-off-by Hongyan Xu <[email protected]>--- drivers/misc/hisi_hikey_usb.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
I no longer have hardware to test with, but on quick glance this looks reasonable to me. Adding Linaro folks who might still be able to test and validate.
For what it's worth:
Arnd Bergmann
maintainerQuoted 8 lines · John Stultz
On Mon, Jul 27, 2026 at 11:56 PM Hongyan Xu <[email protected]> wrote:
I no longer have hardware to test with, but on quick glance this looks reasonable to me. Adding Linaro folks who might still be able to test and validate.
For what it's worth:
Acked-by John Stultz <[email protected]>
From what I can tell, the driver never actually worked upstream. Mauro tried fixing it until late 2021 in this series
https://lore.kernel.org/all/[email protected]/
and then gave up. The .compatible="hisilicon,usbhub" ID does not match on any dts file and there is no binding for it.
Arnd
Thanks for the context. I wasn't aware that the driver had no upstream DT user or binding.
Given that, I will hold off on revising this patch. If removing the unused driver is the preferred direction, I can prepare a separate removal patch.
Thanks,
Hongyan
Greg Kroah-Hartman
maintainerQuoted 2 lines · Hongyan Xu
Thanks for the context. I wasn't aware that the driver had no upstream DT user or binding.
If so, should we just drop the driver if there are no in-kernel users of it and no one has hardware for it anymore?
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 6 lines · Hongyan Xu
Thanks for the context. I wasn't aware that the driver had no upstream DT user or binding.
Given that, I will hold off on revising this patch. If removing the unused driver is the preferred direction, I can prepare a separate removal patch.
Sorry, yes, that's what I was wanting to ask as well.
Arnd Bergmann
maintainerQuoted 9 lines · Greg Kroah-Hartman
Quoted 6 lines · Hongyan Xu
Thanks for the context. I wasn't aware that the driver had no upstream DT user or binding.
Given that, I will hold off on revising this patch. If removing the unused driver is the preferred direction, I can prepare a separate removal patch.
Sorry, yes, that's what I was wanting to ask as well.
I asked around internally, and Ben Copeland mentioned that the hikey960 itself should still work fine with mainline kernels, but the role switch driver was never getting tested.
I think we can just remove this driver. If anyone wants to get the functionality working later, they can reintroduce a working version in drivers/phy/, where all other usb-role-switch support lives these days.
Arnd
Hi Greg, Arnd,
Thanks, that makes sense.
I'll drop the role-switch work cancellation patch and send a separate patch to remove this driver instead.
Thanks,
Hongyan
PATCH 1/1 misc: hisi_hikey_usb: remove untested role-switch driver
In reply to Hongyan XuDuring review of a lifetime fix for this driver, it turned out that the role-switch path has no upstream DT binding or in-tree user and has not been tested in years.
Rather than keep carrying and fixing an effectively unused board-specific driver, remove it. If this functionality is needed again later, it can be reintroduced in drivers/phy/, where USB role-switch support lives today.
--- MAINTAINERS | 6 - drivers/misc/Kconfig | 10 -- drivers/misc/Makefile | 1 - drivers/misc/hisi_hikey_usb.c | 274 ---------------------------------- 4 files changed, 291 deletions(-) delete mode 100644 drivers/misc/hisi_hikey_usb.c
MAINTAINERS +0 -6
@@ -10636,12 +10636,6 @@ W: http://www.highpoint-tech.com F: Documentation/scsi/hptiop.rst F: drivers/scsi/hptiop.c -HIKEY960 ONBOARD USB GPIO HUB DRIVER -M: John Stultz <[email protected]> -L: [email protected] -S: Maintained -F: drivers/misc/hisi_hikey_usb.c - HIMAX HX83112B TOUCHSCREEN SUPPORT M: Job Noorman <[email protected]> L: [email protected]
drivers/misc/Kconfig +0 -10
@@ -492,16 +492,6 @@ config MISC_RTSX tristate default MISC_RTSX_PCI || MISC_RTSX_USB -config HISI_HIKEY_USB - tristate "USB GPIO Hub on HiSilicon Hikey 960/970 Platform" - depends on (OF && GPIOLIB) || COMPILE_TEST - depends on USB_ROLE_SWITCH - help - If you say yes here this adds support for the on-board USB GPIO hub - found on HiKey 960/970 boards, which is necessary to support - switching between the dual-role USB-C port and the USB-A host ports - using only one USB controller. - config OPEN_DICE tristate "Open Profile for DICE driver" depends on OF_RESERVED_MEM
drivers/misc/Makefile +0 -1
@@ -58,7 +58,6 @@ obj-y += cardreader/ obj-$(CONFIG_PVPANIC) += pvpanic/ obj-$(CONFIG_UACCE) += uacce/ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o -obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o obj-$(CONFIG_NTSYNC) += ntsync.o obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o obj-$(CONFIG_OPEN_DICE) += open-dice.o
drivers/misc/hisi_hikey_usb.c deleted +0 -274
274 lines not on this page · raw message
Signature · 1 line
2.50.1.windows.1