From patchwork Mon Nov 16 12:57:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 7624971 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 19A1EBF90C for ; Mon, 16 Nov 2015 12:58:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 483112057E for ; Mon, 16 Nov 2015 12:58:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3ED8D2053F for ; Mon, 16 Nov 2015 12:58:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752255AbbKPM53 (ORCPT ); Mon, 16 Nov 2015 07:57:29 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:34445 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752251AbbKPM5Y (ORCPT ); Mon, 16 Nov 2015 07:57:24 -0500 Received: by padhx2 with SMTP id hx2so174857179pad.1; Mon, 16 Nov 2015 04:57:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=ImhzgQp9FbELb5KjcXQG0OkY3cPQbnBS9QvR+gpZ0G4=; b=sYiatVbg0KzoeOZfKde0Y4heN3KoEUHZAVc8q/149q2HDW9TeHU89GjXJzFDLd2scf 0C6gqopeQBQA0wuw70jjhPf97xEknTMVasJNvE0VE2+Vw1c/N7JpO9cwK3f+U7c5OvKY 9Grqi40aQsoxLwUgGi4c7+CMblsxSpCfoXNwCxb38wcipZ6Qrcz7rUqWe2DHDf4JJnID 5bAg7RQfPpSC6qRUaF6Vxz2s7xWixPMAr0c+e4DbDWcgCG5BZ46MctMLga/xOHChcq9j /NAYOw20PgQRAOsebUUw7HYG6I0fbES3frSlCNA+f8cKs81PIseWRuenvJ0QlmB4IHuT y0Pw== X-Received: by 10.68.139.98 with SMTP id qx2mr54474211pbb.150.1447678644249; Mon, 16 Nov 2015 04:57:24 -0800 (PST) Received: from sudip-pc.vectortproxy.org ([122.169.153.10]) by smtp.gmail.com with ESMTPSA id ve8sm36532123pbc.48.2015.11.16.04.57.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Nov 2015 04:57:23 -0800 (PST) From: Sudip Mukherjee To: Lauro Ramos Venancio , Aloisio Almeida Jr , Samuel Ortiz , "David S. Miller" Cc: linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Sudip Mukherjee Subject: [PATCH] NFC: nci: fix memory leak Date: Mon, 16 Nov 2015 18:27:15 +0530 Message-Id: <1447678635-11146-1-git-send-email-sudipm.mukherjee@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In case of invalid number_destination_params we were returning error but we missed releasing cmd. Lets check for the number of parameter before allocating memory so that we don't have a memory leak. Signed-off-by: Sudip Mukherjee --- net/nfc/nci/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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);