Commit 40543b3d authored by Jiasheng Jiang's avatar Jiasheng Jiang Committed by Tony Nguyen

ice: Add check for kzalloc

Add the check for the return value of kzalloc in order to avoid
NULL pointer dereference.
Moreover, use the goto-label to share the clean code.

Fixes: d6b98c8d ("ice: add write functionality for GNSS TTY")
Signed-off-by: default avatarJiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
parent f5898562
...@@ -461,6 +461,9 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf) ...@@ -461,6 +461,9 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) { for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) {
pf->gnss_tty_port[i] = kzalloc(sizeof(*pf->gnss_tty_port[i]), pf->gnss_tty_port[i] = kzalloc(sizeof(*pf->gnss_tty_port[i]),
GFP_KERNEL); GFP_KERNEL);
if (!pf->gnss_tty_port[i])
goto err_out;
pf->gnss_serial[i] = NULL; pf->gnss_serial[i] = NULL;
tty_port_init(pf->gnss_tty_port[i]); tty_port_init(pf->gnss_tty_port[i]);
...@@ -470,8 +473,16 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf) ...@@ -470,8 +473,16 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
err = tty_register_driver(tty_driver); err = tty_register_driver(tty_driver);
if (err) { if (err) {
dev_err(dev, "Failed to register TTY driver err=%d\n", err); dev_err(dev, "Failed to register TTY driver err=%d\n", err);
goto err_out;
}
for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) { for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++)
dev_info(dev, "%s%d registered\n", ttydrv_name, i);
return tty_driver;
err_out:
while (i--) {
tty_port_destroy(pf->gnss_tty_port[i]); tty_port_destroy(pf->gnss_tty_port[i]);
kfree(pf->gnss_tty_port[i]); kfree(pf->gnss_tty_port[i]);
} }
...@@ -479,12 +490,6 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf) ...@@ -479,12 +490,6 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
tty_driver_kref_put(pf->ice_gnss_tty_driver); tty_driver_kref_put(pf->ice_gnss_tty_driver);
return NULL; return NULL;
}
for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++)
dev_info(dev, "%s%d registered\n", ttydrv_name, i);
return tty_driver;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment