diff options
author | Gustavo A. R. Silva <gustavo@embeddedor.com> | 2019-01-16 11:46:16 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-01-18 08:14:14 -0500 |
commit | e25df7812c91f62581301f9a7ac102acf92e4937 (patch) | |
tree | 6e5615c058f1384c5772c7d5ec2ef194f0764d73 /drivers/misc/ibmvmc.c | |
parent | 7e7ca7744a539f1a172e3b81c29d000787e3d774 (diff) |
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: 0eca353e7ae7 ("misc: IBM Virtual Management Channel Driver (VMC)")
Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc/ibmvmc.c')
-rw-r--r-- | drivers/misc/ibmvmc.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/misc/ibmvmc.c b/drivers/misc/ibmvmc.c index b8aaa684c397..2ed23c99f59f 100644 --- a/drivers/misc/ibmvmc.c +++ b/drivers/misc/ibmvmc.c | |||
@@ -820,21 +820,24 @@ static int ibmvmc_send_msg(struct crq_server_adapter *adapter, | |||
820 | * | 820 | * |
821 | * Return: | 821 | * Return: |
822 | * 0 - Success | 822 | * 0 - Success |
823 | * Non-zero - Failure | ||
823 | */ | 824 | */ |
824 | static int ibmvmc_open(struct inode *inode, struct file *file) | 825 | static int ibmvmc_open(struct inode *inode, struct file *file) |
825 | { | 826 | { |
826 | struct ibmvmc_file_session *session; | 827 | struct ibmvmc_file_session *session; |
827 | int rc = 0; | ||
828 | 828 | ||
829 | pr_debug("%s: inode = 0x%lx, file = 0x%lx, state = 0x%x\n", __func__, | 829 | pr_debug("%s: inode = 0x%lx, file = 0x%lx, state = 0x%x\n", __func__, |
830 | (unsigned long)inode, (unsigned long)file, | 830 | (unsigned long)inode, (unsigned long)file, |
831 | ibmvmc.state); | 831 | ibmvmc.state); |
832 | 832 | ||
833 | session = kzalloc(sizeof(*session), GFP_KERNEL); | 833 | session = kzalloc(sizeof(*session), GFP_KERNEL); |
834 | if (!session) | ||
835 | return -ENOMEM; | ||
836 | |||
834 | session->file = file; | 837 | session->file = file; |
835 | file->private_data = session; | 838 | file->private_data = session; |
836 | 839 | ||
837 | return rc; | 840 | return 0; |
838 | } | 841 | } |
839 | 842 | ||
840 | /** | 843 | /** |