From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from userp1040.oracle.com ([156.151.31.81]:23717 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751904AbbKDNhz (ORCPT ); Wed, 4 Nov 2015 08:37:55 -0500 Date: Wed, 4 Nov 2015 16:37:28 +0300 From: Dan Carpenter To: Lauro Ramos Venancio , Robert Dolca Cc: Aloisio Almeida Jr , Samuel Ortiz , Christophe Ricard , Julien Lefrique , Robert Baldyga , linux-wireless@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] NFC: nci: memory leak in nci_core_conn_create() Message-ID: <20151104133728.GG20966@mwanda> (sfid-20151104_143800_342492_B4104C65) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-wireless-owner@vger.kernel.org List-ID: I've moved the check for "number_destination_params" forward a few lines to avoid leaking "cmd". Fixes: caa575a86ec1 ('NFC: nci: fix possible crash in nci_core_conn_create') Signed-off-by: Dan Carpenter diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c index 10c99a5..fbb7a2b 100644 --- a/net/nfc/nci/core.c +++ b/net/nfc/nci/core.c @@ -610,14 +610,14 @@ int nci_core_conn_create(struct nci_dev *ndev, u8 destination_type, struct nci_core_conn_create_cmd *cmd; struct core_conn_create_data data; + if (!number_destination_params) + return -EINVAL; + data.length = params_len + sizeof(struct nci_core_conn_create_cmd); cmd = kzalloc(data.length, GFP_KERNEL); if (!cmd) return -ENOMEM; - if (!number_destination_params) - return -EINVAL; - cmd->destination_type = destination_type; cmd->number_destination_params = number_destination_params; memcpy(cmd->params, params, params_len);