* [PATCH net] can: sja1000: Fix pci_iounmap() buffer
@ 2026-03-30 15:42 Thomas Fourier
2026-03-31 8:52 ` Markus Elfring
2026-04-01 10:59 ` Marc Kleine-Budde
0 siblings, 2 replies; 4+ messages in thread
From: Thomas Fourier @ 2026-03-30 15:42 UTC (permalink / raw)
Cc: Thomas Fourier, stable, Marc Kleine-Budde, Vincent Mailhol,
Wolfgang Grandegger, David S. Miller, linux-can, linux-kernel
The base_addr is mapped in kvaser_pci_init_one() and the pointer is
copied to priv->reg_base in kvaser_pci_add_chan() with offset
channel * KVASER_PCI_PORT_BYTES but unmapped without the offset.
Cancel the offset before calling pci_iounmap().
Fixes: 255a9154319d ("can: sja1000: stop misusing member base_addr of struct net_device")
Cc: <stable@vger.kernel.org>
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
---
drivers/net/can/sja1000/kvaser_pci.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/can/sja1000/kvaser_pci.c b/drivers/net/can/sja1000/kvaser_pci.c
index 95fe9ee1ce32..213fd0eb07e7 100644
--- a/drivers/net/can/sja1000/kvaser_pci.c
+++ b/drivers/net/can/sja1000/kvaser_pci.c
@@ -161,6 +161,7 @@ static void kvaser_pci_del_chan(struct net_device *dev)
{
struct sja1000_priv *priv;
struct kvaser_pci *board;
+ void __iomem *base_addr;
int i;
if (!dev)
@@ -186,7 +187,8 @@ static void kvaser_pci_del_chan(struct net_device *dev)
}
unregister_sja1000dev(dev);
- pci_iounmap(board->pci_dev, priv->reg_base);
+ base_addr = priv->reg_base - board->channel * KVASER_PCI_PORT_BYTES;
+ pci_iounmap(board->pci_dev, base_addr);
pci_iounmap(board->pci_dev, board->conf_addr);
pci_iounmap(board->pci_dev, board->res_addr);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] can: sja1000: Fix pci_iounmap() buffer
2026-03-30 15:42 [PATCH net] can: sja1000: Fix pci_iounmap() buffer Thomas Fourier
@ 2026-03-31 8:52 ` Markus Elfring
2026-04-01 10:59 ` Marc Kleine-Budde
1 sibling, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-03-31 8:52 UTC (permalink / raw)
To: Thomas Fourier, linux-can
Cc: stable, LKML, David S. Miller, Marc Kleine-Budde, Vincent Mailhol,
Wolfgang Grandegger
> The base_addr is mapped in kvaser_pci_init_one() and the pointer is
> copied to priv->reg_base in kvaser_pci_add_chan() with offset
> channel * KVASER_PCI_PORT_BYTES but unmapped without the offset.
>
> Cancel the offset before calling pci_iounmap().
Which action would indicate “cancelling” here?
Would it occasionally be preferred to specify selected message recipients
also in the header “To”?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.0-rc6#n231
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] can: sja1000: Fix pci_iounmap() buffer
2026-03-30 15:42 [PATCH net] can: sja1000: Fix pci_iounmap() buffer Thomas Fourier
2026-03-31 8:52 ` Markus Elfring
@ 2026-04-01 10:59 ` Marc Kleine-Budde
2026-04-07 13:15 ` Thomas Fourier
1 sibling, 1 reply; 4+ messages in thread
From: Marc Kleine-Budde @ 2026-04-01 10:59 UTC (permalink / raw)
To: Thomas Fourier
Cc: stable, Vincent Mailhol, Wolfgang Grandegger, David S. Miller,
linux-can, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2253 bytes --]
On 30.03.2026 17:42:31, Thomas Fourier wrote:
> The base_addr is mapped in kvaser_pci_init_one() and the pointer is
> copied to priv->reg_base in kvaser_pci_add_chan() with offset
> channel * KVASER_PCI_PORT_BYTES but unmapped without the offset.
>
> Cancel the offset before calling pci_iounmap().
>
> Fixes: 255a9154319d ("can: sja1000: stop misusing member base_addr of struct net_device")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
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().
What about switching the driver to pcim_enable_device(),
pcim_request_region(), pcim_iomap() functions instead?
> ---
> drivers/net/can/sja1000/kvaser_pci.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/can/sja1000/kvaser_pci.c b/drivers/net/can/sja1000/kvaser_pci.c
> index 95fe9ee1ce32..213fd0eb07e7 100644
> --- a/drivers/net/can/sja1000/kvaser_pci.c
> +++ b/drivers/net/can/sja1000/kvaser_pci.c
> @@ -161,6 +161,7 @@ static void kvaser_pci_del_chan(struct net_device *dev)
> {
> struct sja1000_priv *priv;
> struct kvaser_pci *board;
> + void __iomem *base_addr;
> int i;
>
> if (!dev)
> @@ -186,7 +187,8 @@ static void kvaser_pci_del_chan(struct net_device *dev)
> }
> unregister_sja1000dev(dev);
>
> - pci_iounmap(board->pci_dev, priv->reg_base);
> + base_addr = priv->reg_base - board->channel * KVASER_PCI_PORT_BYTES;
> + pci_iounmap(board->pci_dev, base_addr);
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?
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
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] can: sja1000: Fix pci_iounmap() buffer
2026-04-01 10:59 ` Marc Kleine-Budde
@ 2026-04-07 13:15 ` Thomas Fourier
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Fourier @ 2026-04-07 13:15 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: stable, Vincent Mailhol, Wolfgang Grandegger, David S. Miller,
linux-can, linux-kernel
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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-07 13:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-30 15:42 [PATCH net] can: sja1000: Fix pci_iounmap() buffer Thomas Fourier
2026-03-31 8:52 ` Markus Elfring
2026-04-01 10:59 ` Marc Kleine-Budde
2026-04-07 13:15 ` Thomas Fourier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox