can: sja1000: fix use after free in ems_pcmcia_add_card()
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 24 Nov 2021 14:50:41 +0000 (17:50 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Dec 2021 09:04:47 +0000 (10:04 +0100)
commit1dd5b819f7e406dc15bbc7670596ff25261aaa2a
treecb1845279ee9f2c7f04322c67ae6dc85eae64bb5
parent10d0f0aaa5cde52bd5685ee8d0adc02f1efb1983
can: sja1000: fix use after free in ems_pcmcia_add_card()

commit 3ec6ca6b1a8e64389f0212b5a1b0f6fed1909e45 upstream.

If the last channel is not available then "dev" is freed.  Fortunately,
we can just use "pdev->irq" instead.

Also we should check if at least one channel was set up.

Fixes: fd734c6f25ae ("can/sja1000: add driver for EMS PCMCIA card")
Link: https://lore.kernel.org/all/20211124145041.GB13656@kili
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Tested-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/can/sja1000/ems_pcmcia.c