soc: aspeed: Add NULL check in aspeed_lpc_enable_snoop()
[ 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:3772e5da44
("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 from3772e5da44
] 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>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
b828083b3d
commit
8312b1f776
@@ -200,11 +200,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.minor = MISC_DYNAMIC_MINOR;
|
||||||
lpc_snoop->chan[channel].miscdev.name =
|
lpc_snoop->chan[channel].miscdev.name =
|
||||||
devm_kasprintf(dev, GFP_KERNEL, "%s%d", DEVICE_NAME, channel);
|
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.fops = &snoop_fops;
|
||||||
lpc_snoop->chan[channel].miscdev.parent = dev;
|
lpc_snoop->chan[channel].miscdev.parent = dev;
|
||||||
rc = misc_register(&lpc_snoop->chan[channel].miscdev);
|
rc = misc_register(&lpc_snoop->chan[channel].miscdev);
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
goto err_free_fifo;
|
||||||
|
|
||||||
/* Enable LPC snoop channel at requested port */
|
/* Enable LPC snoop channel at requested port */
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
@@ -221,7 +225,8 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
|
|||||||
hicrb_en = HICRB_ENSNP1D;
|
hicrb_en = HICRB_ENSNP1D;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
rc = -EINVAL;
|
||||||
|
goto err_misc_deregister;
|
||||||
}
|
}
|
||||||
|
|
||||||
regmap_update_bits(lpc_snoop->regmap, HICR5, hicr5_en, hicr5_en);
|
regmap_update_bits(lpc_snoop->regmap, HICR5, hicr5_en, hicr5_en);
|
||||||
@@ -231,6 +236,12 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
|
|||||||
regmap_update_bits(lpc_snoop->regmap, HICRB,
|
regmap_update_bits(lpc_snoop->regmap, HICRB,
|
||||||
hicrb_en, hicrb_en);
|
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;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user