Skip to content

Commit f1706e0

Browse files
Henry Martinarndb
authored andcommitted
soc: aspeed: Add NULL check in aspeed_lpc_enable_snoop()
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: 3772e5d ("drivers/misc: Aspeed LPC snoop output using misc chardev") Signed-off-by: Henry Martin <[email protected]> Link: https://patch.msgid.link/[email protected] [arj: Fix Fixes: tag to use subject from 3772e5d] Signed-off-by: Andrew Jeffery <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]>
1 parent d9f0a97 commit f1706e0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

drivers/soc/aspeed/aspeed-lpc-snoop.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,15 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
200200
lpc_snoop->chan[channel].miscdev.minor = MISC_DYNAMIC_MINOR;
201201
lpc_snoop->chan[channel].miscdev.name =
202202
devm_kasprintf(dev, GFP_KERNEL, "%s%d", DEVICE_NAME, channel);
203+
if (!lpc_snoop->chan[channel].miscdev.name) {
204+
rc = -ENOMEM;
205+
goto err_free_fifo;
206+
}
203207
lpc_snoop->chan[channel].miscdev.fops = &snoop_fops;
204208
lpc_snoop->chan[channel].miscdev.parent = dev;
205209
rc = misc_register(&lpc_snoop->chan[channel].miscdev);
206210
if (rc)
207-
return rc;
211+
goto err_free_fifo;
208212

209213
/* Enable LPC snoop channel at requested port */
210214
switch (channel) {
@@ -221,7 +225,8 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
221225
hicrb_en = HICRB_ENSNP1D;
222226
break;
223227
default:
224-
return -EINVAL;
228+
rc = -EINVAL;
229+
goto err_misc_deregister;
225230
}
226231

227232
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,
231236
regmap_update_bits(lpc_snoop->regmap, HICRB,
232237
hicrb_en, hicrb_en);
233238

239+
return 0;
240+
241+
err_misc_deregister:
242+
misc_deregister(&lpc_snoop->chan[channel].miscdev);
243+
err_free_fifo:
244+
kfifo_free(&lpc_snoop->chan[channel].fifo);
234245
return rc;
235246
}
236247

0 commit comments

Comments
 (0)