Re: [PATCH net] can: sja1000: Fix pci_iounmap() buffer

From: Thomas Fourier

Date: Tue Apr 07 2026 - 09:15:09 EST


On 01/04/2026 12:59, Marc Kleine-Budde wrote:
The cleanup functions in this driver are a mess. kvaser_pci_del_chan()
should only delete one channel, but it deletes all. It also unmaps the
iomem, which belongs into kvaser_pci_remove_one().
I'm not quite sure because kvaser_pci_init_one() allocs and registers all channels, so kvaser_pci_remove_one() should too?

What about switching the driver to pcim_enable_device(),
pcim_request_region(), pcim_iomap() functions instead?
I can write a second patch to do so, this would for sure solve the problem. Should I? I have no way to test it.

When called from kvaser_pci_remove_one(), "dev" points to the master
dev, which uses priv->reg_base without an offset, as it's board->channel
is "0", right?
I think you are right, the normal path is fine, but not in the error paths for devices with channel other than 0.

Regards,
Thomas

When called from the error path of kvaser_pci_add_chan(), things go
wrong, and in the error path of kvaser_pci_init_one(), the pci mem is
unmapped again.

regards,
Marc