From patchwork Wed Oct 7 09:33:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Vincent_Stehl=C3=A9?= X-Patchwork-Id: 7343481 X-Patchwork-Delegate: kvalo@adurom.com 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 96DCFBEEA4 for ; Wed, 7 Oct 2015 09:34:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F1E5720613 for ; Wed, 7 Oct 2015 09:33:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F19BC20612 for ; Wed, 7 Oct 2015 09:33:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752749AbbJGJdl (ORCPT ); Wed, 7 Oct 2015 05:33:41 -0400 Received: from smtp3-g21.free.fr ([212.27.42.3]:17439 "EHLO smtp3-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752190AbbJGJdj (ORCPT ); Wed, 7 Oct 2015 05:33:39 -0400 Received: from romuald.bergerie (unknown [88.178.86.202]) by smtp3-g21.free.fr (Postfix) with ESMTPS id 97F4FA6257; Wed, 7 Oct 2015 11:33:37 +0200 (CEST) Received: from radicelle.bergerie (radicelle.bergerie [192.168.124.12]) by romuald.bergerie (Postfix) with SMTP id 29842E2A604; Wed, 7 Oct 2015 11:33:36 +0200 (CEST) Received: by radicelle.bergerie (sSMTP sendmail emulation); Wed, 07 Oct 2015 11:33:36 +0200 From: =?UTF-8?q?Vincent=20Stehl=C3=A9?= To: linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Vincent=20Stehl=C3=A9?= , Thierry Escande , Samuel Ortiz Subject: [PATCH] nfc: netlink: avoid NULL pointer dereference on error Date: Wed, 7 Oct 2015 11:33:19 +0200 Message-Id: <1444210399-3913-1-git-send-email-vincent.stehle@laposte.net> X-Mailer: git-send-email 2.5.1 MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,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 The function nfc_genl_llc_sdreq() can dereference the dev pointer while it is NULL on its error path. Create a new error handling label to avoid that. This fixes the following coccinelle error: ./net/nfc/netlink.c:1175:21-24: ERROR: dev is NULL but dereferenced. Signed-off-by: Vincent Stehlé Cc: Thierry Escande Cc: Samuel Ortiz --- net/nfc/netlink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c index 853172c..51c48f0 100644 --- a/net/nfc/netlink.c +++ b/net/nfc/netlink.c @@ -1111,7 +1111,7 @@ static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info) dev = nfc_get_device(idx); if (!dev) { rc = -ENODEV; - goto exit; + goto exit_nodev; } device_lock(&dev->dev); @@ -1176,6 +1176,7 @@ exit: nfc_put_device(dev); +exit_nodev: return rc; }