Skip to content

Commit 0aa7d35

Browse files
committed
Merge branch '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue
Tony Nguyen says: ==================== Intel Wired LAN Driver Updates 2023-01-09 (ice) This series contains updates to ice driver only. Jiasheng Jiang frees allocated cmd_buf if write_buf allocation failed to prevent memory leak. Yuan Can adds check, and proper cleanup, of gnss_tty_port allocation call to avoid memory leaks. * '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue: ice: Add check for kzalloc ice: Fix potential memory leak in ice_gnss_tty_write() ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 9639856 + 40543b3 commit 0aa7d35

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

drivers/net/ethernet/intel/ice/ice_gnss.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ ice_gnss_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
363363
/* Send the data out to a hardware port */
364364
write_buf = kzalloc(sizeof(*write_buf), GFP_KERNEL);
365365
if (!write_buf) {
366+
kfree(cmd_buf);
366367
err = -ENOMEM;
367368
goto exit;
368369
}
@@ -460,6 +461,9 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
460461
for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) {
461462
pf->gnss_tty_port[i] = kzalloc(sizeof(*pf->gnss_tty_port[i]),
462463
GFP_KERNEL);
464+
if (!pf->gnss_tty_port[i])
465+
goto err_out;
466+
463467
pf->gnss_serial[i] = NULL;
464468

465469
tty_port_init(pf->gnss_tty_port[i]);
@@ -469,21 +473,23 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
469473
err = tty_register_driver(tty_driver);
470474
if (err) {
471475
dev_err(dev, "Failed to register TTY driver err=%d\n", err);
472-
473-
for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) {
474-
tty_port_destroy(pf->gnss_tty_port[i]);
475-
kfree(pf->gnss_tty_port[i]);
476-
}
477-
kfree(ttydrv_name);
478-
tty_driver_kref_put(pf->ice_gnss_tty_driver);
479-
480-
return NULL;
476+
goto err_out;
481477
}
482478

483479
for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++)
484480
dev_info(dev, "%s%d registered\n", ttydrv_name, i);
485481

486482
return tty_driver;
483+
484+
err_out:
485+
while (i--) {
486+
tty_port_destroy(pf->gnss_tty_port[i]);
487+
kfree(pf->gnss_tty_port[i]);
488+
}
489+
kfree(ttydrv_name);
490+
tty_driver_kref_put(pf->ice_gnss_tty_driver);
491+
492+
return NULL;
487493
}
488494

489495
/**

0 commit comments

Comments
 (0)