net: marvell: fix a missing check of acpi_match_device
authorKangjie Lu <kjlu@umn.edu>
Wed, 26 Dec 2018 06:31:08 +0000 (00:31 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Dec 2019 08:20:55 +0000 (09:20 +0100)
[ Upstream commit 92ee77d148bf06d8c52664be4d1b862583fd5c0e ]

When acpi_match_device fails, its return value is NULL. Directly using
the return value without a check may result in a NULL-pointer
dereference. The fix checks if acpi_match_device fails, and if so,
returns -EINVAL.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c

index 1cc0e8f..a50977c 100644 (file)
@@ -5132,6 +5132,8 @@ static int mvpp2_probe(struct platform_device *pdev)
        if (has_acpi_companion(&pdev->dev)) {
                acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
                                            &pdev->dev);
+               if (!acpi_id)
+                       return -EINVAL;
                priv->hw_version = (unsigned long)acpi_id->driver_data;
        } else {
                priv->hw_version =