RE: [PATCH net-next v8 6/9] net: txgbe: Support GPIO to SFP socket

Jiawen Wu
2023-05-23T06:14:16Z

> > > > If you are getting errors when removing the driver it means you are
> > > > missing some level of undoing what us done in probe. Are you sure
> > > > regmap_del_irq_chip() is being called on unload?
> > >
> > > I used devm_* all when I registered them.
> >
> > Look at the ordering. Is regmap_del_irq_chip() being called too late?
> > I've had problems like this with the mv88e6xxx driver and its
> > interrupt controllers. I ended up not using devm_ so i had full
> > control over the order things got undone. In that case, the external
> > devices was PHYs, with the PHY interrupt being inside the Ethernet
> > switch, which i exposed using a Linux interrupt controller.
>
> I use no devm_ functions to add regmap irq chip, register gpio regmap,
> and call their del/unregister functions at the position corresponding to
> release. irq_domain_remove() call trace still exist.
>
> [ 104.553182] Call Trace:
> [ 104.553184] <TASK>
> [ 104.553185] irq_domain_remove+0x2b/0xe0
> [ 104.553190] regmap_del_irq_chip.part.0+0x8a/0x160
> [ 104.553196] txgbe_remove_phy+0x57/0x80 [txgbe]
> [ 104.553201] txgbe_remove+0x2a/0x90 [txgbe]
> [ 104.553205] pci_device_remove+0x36/0xa0
> [ 104.553208] device_release_driver_internal+0xaa/0x140
> [ 104.553213] driver_detach+0x44/0x90
> [ 104.553215] bus_remove_driver+0x69/0xf0
> [ 104.553217] pci_unregister_driver+0x29/0xb0
> [ 104.553220] __x64_sys_delete_module+0x145/0x240
> [ 104.553223] ? exit_to_user_mode_prepare+0x3c/0x1a0
> [ 104.553226] do_syscall_64+0x3b/0x90
> [ 104.553230] entry_SYSCALL_64_after_hwframe+0x72/0xdc

I think this problem is caused by a conflict calling of irq_domain_remove()
between the two functions gpiochip_irqchip_remove() and regmap_del_irq_chip().
The front one is called by gpio_regmap_unregister().

I adjusted the order of release functions, regmap_del_irq_chip() first, then
gpio_regmap_unregister(). Log became:

[ 383.261168] Call Trace:
[ 383.261169] <TASK>
[ 383.261170] irq_domain_remove+0x2b/0xe0
[ 383.261174] gpiochip_irqchip_remove+0xf0/0x210
[ 383.261177] gpiochip_remove+0x4a/0x110
[ 383.261181] gpio_regmap_unregister+0x12/0x20 [gpio_regmap]
[ 383.261186] txgbe_remove_phy+0x57/0x80 [txgbe]
[ 383.261190] txgbe_remove+0x2a/0x90 [txgbe]

irq_domain_remove() just free the memory of irq_domain, but its pointer address
still exists. So it will be called twice.