Commit e25df781 authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Greg Kroah-Hartman

misc: ibmvsm: Fix potential NULL pointer dereference

There is a potential NULL pointer dereference in case kzalloc()
fails and returns NULL.

Fix this by adding a NULL check on *session*

Also, update the function header with information about the
expected return on failure and remove unnecessary variable rc.

This issue was detected with the help of Coccinelle.

Fixes: 0eca353e ("misc: IBM Virtual Management Channel Driver (VMC)")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7e7ca774
...@@ -820,21 +820,24 @@ static int ibmvmc_send_msg(struct crq_server_adapter *adapter, ...@@ -820,21 +820,24 @@ static int ibmvmc_send_msg(struct crq_server_adapter *adapter,
* *
* Return: * Return:
* 0 - Success * 0 - Success
* Non-zero - Failure
*/ */
static int ibmvmc_open(struct inode *inode, struct file *file) static int ibmvmc_open(struct inode *inode, struct file *file)
{ {
struct ibmvmc_file_session *session; struct ibmvmc_file_session *session;
int rc = 0;
pr_debug("%s: inode = 0x%lx, file = 0x%lx, state = 0x%x\n", __func__, pr_debug("%s: inode = 0x%lx, file = 0x%lx, state = 0x%x\n", __func__,
(unsigned long)inode, (unsigned long)file, (unsigned long)inode, (unsigned long)file,
ibmvmc.state); ibmvmc.state);
session = kzalloc(sizeof(*session), GFP_KERNEL); session = kzalloc(sizeof(*session), GFP_KERNEL);
if (!session)
return -ENOMEM;
session->file = file; session->file = file;
file->private_data = session; file->private_data = session;
return rc; return 0;
} }
/** /**
......
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