serial: mvebu-uart: drop of_match_ptr for ID table
PATCH v2 1/1 serial: mvebu-uart: drop of_match_ptr for ID table
mvebu_uart_of_match[] is always compiled in and already referenced directly in mvebu_uart_probe(). Wrapping it in of_match_ptr() in mvebu_uart_platform_driver is redundant and prevents ACPI PRP0001 matching when CONFIG_OF is disabled.
Switch mvebu_uart_probe() from of_match_device() to device_get_match_data() and check for NULL so both Device Tree and ACPI PRP0001 bindings resolve match data safely. Also drop the now-unused forward declaration and <linux/of_device.h> include.
---
Changes in v2:
- Use device_get_match_data() with a NULL check in mvebu_uart_probe() to prevent a NULL pointer dereference on ACPI PRP0001 match.
- Drop unused forward declaration and <linux/of_device.h> include.
drivers/tty/serial/mvebu-uart.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/tty/serial/mvebu-uart.c +7 -7
@@ -18,10 +18,10 @@#include <linux/math64.h> #include <linux/of.h> #include <linux/of_address.h> -#include <linux/of_device.h> #include <linux/of_irq.h> #include <linux/of_platform.h> #include <linux/platform_device.h> +#include <linux/property.h> #include <linux/serial.h> #include <linux/serial_core.h> #include <linux/slab.h>
@@ -154,7 +154,7 @@ struct mvebu_uart {struct uart_port *port;struct clk *clk;int irq[UART_IRQ_COUNT ]; -struct mvebu_uart_driver_data *data; +const struct mvebu_uart_driver_data *data;#if defined(CONFIG_PM )struct mvebu_uart_pm_regs pm_regs;#endif /* CONFIG_PM */
@@ -859,15 +859,12 @@ static const struct dev_pm_ops mvebu_uart_pm_ops = { };#endif /* CONFIG_PM */ -static const struct of_device_id mvebu_uart_of_match[];/* Counter to keep track of each UART port id when not using CONFIG_OF */ static int uart_num_counter;static int mvebu_uart_probe (struct platform_device *pdev) { -const struct of_device_id *match =of_match_device (mvebu_uart_of_match, - &pdev->dev);struct uart_port *port;struct mvebu_uart *mvuart;struct resource *reg;
@@ -919,7 +916,10 @@ static int mvebu_uart_probe(struct platform_device *pdev)return -ENOMEM ;/* Get controller data depending on the compatible string */ - mvuart->data = (struct mvebu_uart_driver_data *)match->data; + mvuart->data =device_get_match_data (&pdev->dev); +if (!mvuart->data) +return -ENODEV ; + mvuart->port = port; port->private_data = mvuart;
@@ -1016,7 +1016,7 @@ static struct platform_driver mvebu_uart_platform_driver = { .probe = mvebu_uart_probe, .driver = { .name = "mvebu-uart", - .of_match_table = of_match_ptr(mvebu_uart_of_match), + .of_match_table = mvebu_uart_of_match, .suppress_bind_attrs = true,#if defined(CONFIG_PM ) .pm = &mvebu_uart_pm_ops,
Signature · 1 line
2.56.1
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 11 lines
mvebu_uart_of_match[] is always compiled in and already referenced directly in
mvebu_uart_probe(). Wrapping it inof_match_ptr()inmvebu_uart_platform_driveris redundant and prevents ACPI PRP0001 matching whenCONFIG_OFis disabled.Switch
mvebu_uart_probe()fromof_match_device()todevice_get_match_data()and check for NULL so both Device Tree and ACPI PRP0001 bindings resolve match data safely. Also drop the now-unused forward declaration and <linux/of_device.h> include.Signed-off-by Bramuel Barack <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1