serial: max310x: Fix to avoid potential NULL pointer dereference [Linux 3.16.72]

This Linux kernel change "serial: max310x: Fix to avoid potential NULL pointer dereference" is included in the Linux 3.16.72 release. This change is authored by Aditya Pakki <pakki001 [at]> on Mon Mar 18 18:44:14 2019 -0500. The commit for this change in Linux stable tree is 2223004 (patch) which is from upstream commit 3a10e3d. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 3a10e3d.

serial: max310x: Fix to avoid potential NULL pointer dereference

commit 3a10e3dd52e80b9a97a3346020024d17b2c272d6 upstream.

of_match_device can return a NULL pointer when matching device is not
found. This patch avoids a scenario causing NULL pointer derefernce.

Signed-off-by: Aditya Pakki <[email protected]>
Signed-off-by: Greg Kroah-Hartman <greg[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/tty/serial/max310x.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index ba285cd..8ccab7c 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -1324,6 +1324,8 @@ static int max310x_spi_probe(struct spi_device *spi)
    if (spi->dev.of_node) {
        const struct of_device_id *of_id =
            of_match_device(max310x_dt_ids, &spi->dev);
+       if (!of_id)
+           return -ENODEV;

        devtype = (struct max310x_devtype *)of_id->data;
    } else {

Leave a Reply

Your email address will not be published. Required fields are marked *