can: mcp251xfd: Add ACPI device ID table for MCP251XFD
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected] [email protected]
v2 cover can: mcp251x: Add ACPI device ID table for MCP2515
Changes in v2:
1. MCP2515 is verified, but MCP251XFD has not been tested.
When testing MCP2515, MCP251XFD was found missing ACPI support, hence this addition. Reference the validated MCP2515 ACPI node as template:
Device(CAN0){
Name(_HID, "MCP2515")
Name(_UID, 0)
Name (_DSD, Package() {2. The original 9-character HID "MCP251XFD" violates ACPI format rules; redefine it to standard compliant ACPI ID MCHP15FD.
guoqi0226 (1):
can: mcp251xfd: Add ACPI device ID table for MCP251XFD
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
Signature · 1 line
2.25.1
PATCH v2 1/1 can: mcp251xfd: Add ACPI device ID table for MCP251XFD
This patch adds an ACPI match table for the MCP251XFD CAN controller, enabling driver binding on ACPI-enumerated SPI platforms.
--- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +10 -1
@@ -20,6 +20,7 @@#include <linux/module.h> #include <linux/pm_runtime.h> #include <linux/property.h> +#include <linux/acpi.h> #include "mcp251xfd.h"
@@ -982,7 +983,6 @@ static int mcp251xfd_handle_rxovif(struct mcp251xfd_priv *priv)static int mcp251xfd_handle_txatif (struct mcp251xfd_priv *priv) { -netdev_info (priv->ndev,"%s\n" , __func__);return 0 ; }
@@ -2212,6 +2212,14 @@ static const struct spi_device_id mcp251xfd_id_table[] = { };MODULE_DEVICE_TABLE (spi, mcp251xfd_id_table); +#ifdef CONFIG_ACPI +static const struct acpi_device_id mcp251xfd_acpi_match[] = { + {"MCHP15FD" , (kernel_ulong_t)&mcp251xfd_devtype_data_mcp251xfd}, + { } +}; +MODULE_DEVICE_TABLE (acpi, mcp251xfd_acpi_match); +#endif +static int mcp251xfd_probe (struct spi_device *spi) {struct net_device *ndev;
@@ -2442,6 +2450,7 @@ static struct spi_driver mcp251xfd_driver = { .name = DEVICE_NAME, .pm = &mcp251xfd_pm_ops, .of_match_table = mcp251xfd_of_match, + .acpi_match_table = ACPI_PTR(mcp251xfd_acpi_match), }, .probe = mcp251xfd_probe, .remove = mcp251xfd_remove,
Signature · 1 line
2.25.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [Medium] Undocumented removal of netdev_info print in mcp251xfd_handle_txatif.
Pre-existing issues:
- [High] Infinite loop / interrupt storm in mcp251xfd_irq due to unhandled TXATIF interrupt flag.
- [High] NULL pointer dereference when retrieving match data if the device is bound manually via sysfs driver_override. --
commit ac99a03d44f8633aff78ad69c67bdd4c8da1aa29
Author: guoqi0226 <[email protected]>
can: mcp251xfd: Add ACPI device ID table for MCP251XFD
This patch adds an ACPI match table for the MCP251XFD CAN controller, enabling driver binding on ACPI-enumerated SPI platforms.
Quoted 4 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +0
-0
[ ... ]
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static int mcp251xfd_handle_rxovif(struct mcp251xfd_priv *priv) · line 988
Quoted 8 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +0
-1@@ -982,7 +983,6 @@ static int mcp251xfd_handle_rxovif(struct mcp251xfd_priv *priv)static int mcp251xfd_handle_txatif (struct mcp251xfd_priv *priv) { -netdev_info (priv->ndev,"%s\n" , __func__);return 0 ; }
[Severity: Medium]
Is this removal intentional? The commit message only mentions adding an ACPI match table, but this modifies the interrupt handler by removing a debug print. If it is intentional, should it be mentioned in the commit message?
[Severity: High]
This is a pre-existing issue, but does this empty function cause an infinite interrupt loop?
Because TXATIF is not part of MCP251XFD_REG_INT_IF_CLEARABLE_MASK, the hardware flag must be manually cleared in the FIFOSTA register. Since mcp251xfd_handle_txatif() returns 0 without clearing the flag, won't the do-while loop in mcp251xfd_irq() continually read TXATIF as pending and loop infinitely?
[ ... ]
Quoted 5 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1
-0@@ -2212,6 +2212,14 @@ static const struct spi_device_id mcp251xfd_id_table[] = { };MODULE_DEVICE_TABLE (spi, mcp251xfd_id_table); +#ifdef CONFIG_ACPI
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static const struct spi_device_id mcp251xfd_id_table[] = { · line 2225
Quoted 10 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +7
-0+static const struct acpi_device_id mcp251xfd_acpi_match[] = { + {"MCHP15FD" , (kernel_ulong_t)&mcp251xfd_devtype_data_mcp251xfd}, + { } +}; +MODULE_DEVICE_TABLE (acpi, mcp251xfd_acpi_match); +#endif +static int mcp251xfd_probe (struct spi_device *spi) {struct net_device *ndev;
[Severity: High]
This is a pre-existing issue, but is it safe to unconditionally dereference the match data retrieved in this function?
Later in mcp251xfd_probe(), the driver does:
priv->devtype_data = *(struct mcp251xfd_devtype_data *)spi_get_device_match_data(spi);
If the driver is bound manually via the sysfs driver_override attribute without matching any table entries, spi_get_device_match_data() will return NULL, which would cause a panic when dereferenced. Should there be a check for NULL before dereferencing it?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
v3 cover can: mcp251xfd: Add ACPI device ID table for MCP251XFD
Sent incorrect patch accidentally, fixed in this version
changed v3
Recover accidentally deleted netdev_info log line with __func__
- netdev_info(priv->ndev, "%s\n", __func__);
guoqi0226 (1):
can: mcp251xfd: Add ACPI device ID table for MCP251XFD
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
Signature · 1 line
2.25.1
PATCH v3 1/1 can: mcp251xfd: Add ACPI device ID table for MCP251XFD
This patch adds an ACPI match table for the MCP251XFD CAN controller, enabling driver binding on ACPI-enumerated SPI platforms.
--- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +10 -0
@@ -20,6 +20,7 @@#include <linux/module.h> #include <linux/pm_runtime.h> #include <linux/property.h> +#include <linux/acpi.h> #include "mcp251xfd.h"
@@ -2212,6 +2213,14 @@ static const struct spi_device_id mcp251xfd_id_table[] = { };MODULE_DEVICE_TABLE (spi, mcp251xfd_id_table); +#ifdef CONFIG_ACPI +static const struct acpi_device_id mcp251xfd_acpi_match[] = { + {"MCHP15FD" , (kernel_ulong_t)&mcp251xfd_devtype_data_mcp251xfd}, + { } +}; +MODULE_DEVICE_TABLE (acpi, mcp251xfd_acpi_match); +#endif +static int mcp251xfd_probe (struct spi_device *spi) {struct net_device *ndev;
@@ -2442,6 +2451,7 @@ static struct spi_driver mcp251xfd_driver = { .name = DEVICE_NAME, .pm = &mcp251xfd_pm_ops, .of_match_table = mcp251xfd_of_match, + .acpi_match_table = ACPI_PTR(mcp251xfd_acpi_match), }, .probe = mcp251xfd_probe, .remove = mcp251xfd_remove,
Signature · 1 line
2.25.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unconditional dereference of the pointer returned by spi_get_device_match_data() can cause a NULL pointer dereference. --
commit 984f1d631588f571112e2f97f02bc97fcb1d8ec1
Author: guoqi0226 <[email protected]>
can: mcp251xfd: Add ACPI device ID table for MCP251XFD
This patch adds an ACPI match table for the MCP251XFD CAN controller, enabling driver binding on ACPI-enumerated SPI platforms.
Quoted 4 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +0
-0
[ ... ]
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static struct spi_driver mcp251xfd_driver = { · line 2456
Quoted 7 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1
-0@@ -2442,6 +2451,7 @@ static struct spi_driver mcp251xfd_driver = { .name = DEVICE_NAME, .pm = &mcp251xfd_pm_ops, .of_match_table = mcp251xfd_of_match, + .acpi_match_table = ACPI_PTR(mcp251xfd_acpi_match), }, .probe = mcp251xfd_probe,
[Severity: High]
This isn't a bug introduced by this patch, but there is a pre-existing issue in mcp251xfd_probe() that might cause a kernel panic.
If the SPI device is bound to the driver manually via sysfs (for example, by writing to the driver_override and bind files), spi_get_device_match_data() can return NULL.
In mcp251xfd_probe(), the return value is dereferenced unconditionally:
static int mcp251xfd_probe(struct spi_device *spi)
{
...
priv->devtype_data = *(struct mcp251xfd_devtype_data *)spi_get_device_match_data(spi);
...
}Could we add a NULL check here that returns -ENODEV or falls back to a default configuration to prevent the dereference?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
v4 cover can: mcp251xfd: Add ACPI device ID table for MCP251XFD
hanges in v4:
- Split into two separate patches:
1. SPI core: add internal NULL guard for spi_get_device_match_data()
2. mcp251xfd driver: cache and validate match data pointer in probe
- Remove duplicate spi_get_device_match_data() invocation and unsafe dereference
guoqi0226 (2):
can: mcp251xfd: mcp251xfd: Cache and validate match data pointer in
probe
spi: Add NULL check for spi_get_device_id() in
spi_get_device_match_data()
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 8 +++++++- drivers/spi/spi.c | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
PATCH v4 1/2 can: mcp251xfd: mcp251xfd: Cache and validate match data pointer in probe
Cache the result of spi_get_device_match_data() to avoid duplicate calls. Add NULL check before dereferencing to eliminate unsafe raw pointer access.
--- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +7 -1
@@ -2231,6 +2231,7 @@ static int mcp251xfd_probe(struct spi_device *spi)bool pll_enable = false;u32 freq =0 ;int err; +const struct mcp251xfd_devtype_data *match_data;if (!spi->irq) return dev_err_probe(&spi->dev, -ENXIO,
@@ -2282,6 +2283,11 @@ static int mcp251xfd_probe(struct spi_device *spi)if (freq <=MCP251XFD_SYSCLOCK_HZ_MAX /MCP251XFD_OSC_PLL_MULTIPLIER ) pll_enable = true; + match_data =spi_get_device_match_data (spi); +if (!match_data) +return dev_err_probe (&spi->dev, -ENODEV , +"Failed to retrieve device match data\n" ); + ndev =alloc_candev (sizeof (struct mcp251xfd_priv ),MCP251XFD_TX_OBJ_NUM_MAX );if (!ndev)
@@ -2317,7 +2323,7 @@ static int mcp251xfd_probe(struct spi_device *spi) priv->reg_vdd = reg_vdd; priv->reg_xceiver = reg_xceiver; priv->xstbyen =device_property_present (&spi->dev,"microchip,xstbyen" ); - priv->devtype_data = *(struct mcp251xfd_devtype_data *)spi_get_device_match_data (spi); + priv->devtype_data = *match_data;/* Errata Reference: * mcp2517fd: DS80000792C 5., mcp2518fd: DS80000789E 4.,
Signature · 1 line
2.25.1
PATCH v4 2/2 spi: Add NULL check for spi_get_device_id() in spi_get_device_match_data()
In reply to guoqi0226Prevent NULL pointer dereference when spi_get_device_id() returns NULL, which can happen when using driver_override without matching SPI ID entry.
--- drivers/spi/spi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/spi/spi.c +5 -1
@@ -355,12 +355,16 @@ EXPORT_SYMBOL_GPL(spi_get_device_id);const void *spi_get_device_match_data (const struct spi_device *sdev) {const void *match; +const struct spi_device_id *id; match =device_get_match_data (&sdev->dev);if (match)return match; -return (const void *)spi_get_device_id (sdev)->driver_data; + id =spi_get_device_id (sdev); +if (!id) +return NULL ; +return (const void *)id->driver_data; }EXPORT_SYMBOL_GPL (spi_get_device_match_data);
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH v4 2/2] spi: Add NULL check for spi_get_device_id() in spi_get_device_match_data()
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] spi_get_device_id() unconditionally dereferences a potentially NULL id_table pointer
- [High] Direct callers of spi_get_device_id() unconditionally dereference its result
- [High] Callers of the patched spi_get_device_match_data() unconditionally dereference its NULL return value --
commit 7e155f379f89eda6ab91795ac56410fd02c722be
Author: guoqi0226 <[email protected]>
spi: Add NULL check for spi_get_device_id() in spi_get_device_match_data()
Prevent NULL pointer dereference when spi_get_device_id() returns NULL, which can happen when using driver_override without matching SPI ID entry.
Quoted 6 lines
drivers/spi/spi.c +0
-0@@ -355,12 +355,16 @@ EXPORT_SYMBOL_GPL(spi_get_device_id);const void *spi_get_device_match_data (const struct spi_device *sdev)
drivers/spi/spi.c EXPORT_SYMBOL_GPL(spi_get_device_id); · line 364
Quoted 10 lines
drivers/spi/spi.c +2
-1{const void *match; +const struct spi_device_id *id; match =device_get_match_data (&sdev->dev);if (match)return match; -return (const void *)spi_get_device_id (sdev)->driver_data; + id =spi_get_device_id (sdev);
[Severity: High]
This is a pre-existing issue, but can spi_get_device_id() itself crash if sdrv->id_table is NULL?
If a spi driver only provides a device tree or acpi match table and lacks an id_table, sdrv->id_table will evaluate to NULL. When spi_get_device_id() is called, it passes this NULL pointer to spi_match_id():
drivers/spi/spi.c:spi_get_device_id() {
...
return spi_match_id(sdrv->id_table, sdev->modalias);
}spi_match_id() then unconditionally evaluates id->name[0] in its while loop:
drivers/spi/spi.c:spi_match_id() {
...
while (id->name[0]) {
...
}Would this result in a NULL pointer dereference when driver_override is used?
[Severity: High]
This is also a pre-existing issue, but do many direct callers of spi_get_device_id() unconditionally dereference its result?
For example, in drivers/iio/adc/max1118.c:max1118_probe():
indio_dev->name = spi_get_device_id(spi)->name;
If driver_override is used to force a bind to a device whose modalias does not match the driver's id_table, spi_get_device_id() can return NULL. Does this mean individual spi drivers might immediately crash if they don't check the return value?
drivers/spi/spi.c EXPORT_SYMBOL_GPL(spi_get_device_id); · line 366
Quoted 2 lines
drivers/spi/spi.c +2
-0+if (!id) +return NULL ;
[Severity: High]
This isn't a bug introduced by this patch, but will returning NULL here just shift the crash to callers that don't check the return value?
For example, in drivers/gpu/drm/tiny/sharp-memory.c:sharp_memory_probe():
smd->mode = spi_get_device_match_data(spi);
...
smd->pitch = (SHARP_ADDR_PERIOD + smd->mode->hdisplay + ...) / 8;If spi_get_device_match_data() returns NULL when driver_override is used, will callers unconditionally dereference it and still cause a kernel panic?
Quoted 3 lines
drivers/spi/spi.c +1
-0+return (const void *)id->driver_data; }EXPORT_SYMBOL_GPL (spi_get_device_match_data);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Mark Brown
maintainerQuoted 5 lines · On Tue, Jun 16, 2026 at 06:30:16PM +0800, guoqi0226 wrote:
hanges in v4:
- Split into two separate patches:
1. SPI core: add internal NULL guard forspi_get_device_match_data()
2. mcp251xfd driver: cache and validate match data pointer in probe
- Remove duplicatespi_get_device_match_data()invocation and unsafe dereference
Why is this a series, are there any dependencies between these two patches?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Mark Brown
maintainerQuoted 1 line · 崔国旗
Hi Mark, While fixing the mcp251xfd driver, I found a latent flaw in
spi_get_device_match_data(), so I sent both fixes as one patch series for unified review. There is no hard build or runtime dependency between the two patches. They can be merged separately into the SPI and CAN subsystem trees respectively. Thanks, guoqi
That's not a good idea since it creates a cross subsystem series which means the flow for getting things merged gets a lot less clear. It is better to keep things for different subsystems separate since that's a lot easier to manage.
Please don't top post, reply in line with needed context. This allows readers to readily follow the flow of conversation and understand what you are talking about and also helps ensure that everything in the discussion is being addressed.
Please fix your mail client to word wrap within paragraphs at something substantially less than 80 columns. Doing this makes your messages much easier to read and reply to.
While fixing the mcp251xfd driver, I found a latent flaw in spi_get_device_match_data(), so I sent both fixes as one patch series for unified review.
There is no hard build or runtime dependency between the two patches.
They can be merged separately into the SPI and CAN subsystem trees respectively.
Thanks,
guoqi
Mark Brown
maintainerRe: (subset) [PATCH v4 0/2] can: mcp251xfd: Add ACPI device ID table for MCP251XFD
In reply to guoqi0226Quoted 9 lines · On Tue, 16 Jun 2026 18:30:16 +0800, guoqi0226 wrote:
can: mcp251xfd: Add ACPI device ID table for MCP251XFD
hanges in v4:
- Split into two separate patches:
1. SPI core: add internal NULL guard forspi_get_device_match_data()
2. mcp251xfd driver: cache and validate match data pointer in probe
- Remove duplicatespi_get_device_match_data()invocation and unsafe dereference[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.2
Thanks!
[2/2] spi: Add NULL check for spi_get_device_id() in spi_get_device_match_data()
https://git.kernel.org/broonie/spi/c/0f82535b5537
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Marc Kleine-Budde
maintainerRe: [PATCH v2 0/1] can: mcp251x: Add ACPI device ID table for MCP2515
In reply to guoqi0226Quoted 2 lines · On 16.06.2026 16:53:58, guoqi0226 wrote:
Changes in v2:
1. MCP2515 is verified, but MCP251XFD has not been tested.
There was a previous attempt to bring ACPI support for the mcp251xfd mainline, see
https://lore.kernel.org/all/[email protected]/
It was not successful. I think it's best to only add ACPI support for devices you have actually tested.
Quoted 8 lines
When testing MCP2515, MCP251XFD was found missing ACPI support, hence this addition. Reference the validated MCP2515 ACPI node as template: Device(CAN0){ Name(_HID, "MCP2515") Name(_UID, 0) Name (_DSD, Package() {2. The original 9-character HID "MCP251XFD" violates ACPI format rules; redefine it to standard compliant ACPI ID MCHP15FD.
regards,
Marc
Signature · 4 lines
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 |