]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
soc: aspeed: Add NULL check in aspeed_lpc_enable_snoop()
authorHenry Martin <bsdhenrymartin@gmail.com>
Thu, 15 May 2025 06:30:44 +0000 (16:00 +0930)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:04:05 +0000 (11:04 +0100)
[ Upstream commit f1706e0e1a74b095cbc60375b9b1e6205f5f4c98 ]

devm_kasprintf() returns NULL when memory allocation fails. Currently,
aspeed_lpc_enable_snoop() does not check for this case, which results in a
NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

Fixes: 3772e5da4454 ("drivers/misc: Aspeed LPC snoop output using misc chardev")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
Link: https://patch.msgid.link/20250401074647.21300-1-bsdhenrymartin@gmail.com
[arj: Fix Fixes: tag to use subject from 3772e5da4454]
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/soc/aspeed/aspeed-lpc-snoop.c

index 8a2a22c40ef5317946754ca24e83cbf26e556512..43e30937fc9da2a8d86fd50c91cc7f76d33f26e7 100644 (file)
@@ -202,11 +202,15 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
        lpc_snoop->chan[channel].miscdev.minor = MISC_DYNAMIC_MINOR;
        lpc_snoop->chan[channel].miscdev.name =
                devm_kasprintf(dev, GFP_KERNEL, "%s%d", DEVICE_NAME, channel);
+       if (!lpc_snoop->chan[channel].miscdev.name) {
+               rc = -ENOMEM;
+               goto err_free_fifo;
+       }
        lpc_snoop->chan[channel].miscdev.fops = &snoop_fops;
        lpc_snoop->chan[channel].miscdev.parent = dev;
        rc = misc_register(&lpc_snoop->chan[channel].miscdev);
        if (rc)
-               return rc;
+               goto err_free_fifo;
 
        /* Enable LPC snoop channel at requested port */
        switch (channel) {
@@ -223,7 +227,8 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
                hicrb_en = HICRB_ENSNP1D;
                break;
        default:
-               return -EINVAL;
+               rc = -EINVAL;
+               goto err_misc_deregister;
        }
 
        regmap_update_bits(lpc_snoop->regmap, HICR5, hicr5_en, hicr5_en);
@@ -233,6 +238,12 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
                regmap_update_bits(lpc_snoop->regmap, HICRB,
                                hicrb_en, hicrb_en);
 
+       return 0;
+
+err_misc_deregister:
+       misc_deregister(&lpc_snoop->chan[channel].miscdev);
+err_free_fifo:
+       kfifo_free(&lpc_snoop->chan[channel].fifo);
        return rc;
 }