ice: Fix potential memory leak in ice_gnss_tty_write()
authorYuan Can <yuancan@huawei.com>
Wed, 7 Dec 2022 08:55:02 +0000 (08:55 +0000)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Mon, 9 Jan 2023 22:02:39 +0000 (14:02 -0800)
The ice_gnss_tty_write() return directly if the write_buf alloc failed,
leaking the cmd_buf.

Fix by free cmd_buf if write_buf alloc failed.

Fixes: d6b98c8d242a ("ice: add write functionality for GNSS TTY")
Signed-off-by: Yuan Can <yuancan@huawei.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/ice/ice_gnss.c

index b5a7f246d230fdc8aad9b5fe6e6c95acdeadfd53..a1915551c69a898151e7227cad57fada4fa33734 100644 (file)
@@ -363,6 +363,7 @@ ice_gnss_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
        /* Send the data out to a hardware port */
        write_buf = kzalloc(sizeof(*write_buf), GFP_KERNEL);
        if (!write_buf) {
+               kfree(cmd_buf);
                err = -ENOMEM;
                goto exit;
        }