From patchwork Thu Sep 10 11:18:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 7153551 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6EB4B9F314 for ; Thu, 10 Sep 2015 11:18:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A18AA2088A for ; Thu, 10 Sep 2015 11:18:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC75320888 for ; Thu, 10 Sep 2015 11:18:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753440AbbIJLSY (ORCPT ); Thu, 10 Sep 2015 07:18:24 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:33189 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753335AbbIJLSV (ORCPT ); Thu, 10 Sep 2015 07:18:21 -0400 Received: by pacex6 with SMTP id ex6so40909084pac.0; Thu, 10 Sep 2015 04:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=6VPQ+q/tR6K4vkeSTRHKplBd29NRlMAhdUw8uMGC3pI=; b=zS02laFeCDzNtBF6YEvaI1aXU9Lbt0DB5OHL1JpqnR3ctDgECzsCv5Ap9K1ZtXCBGm pNDNB8nCsNO6cQNue4pR9ZB0azAk49ht1Go/aujcF45uPwji82wa5NxZvkXZN9SBc4RM nO5qWCLxgLrYKJqgxkaE5UB+2S7qSNZeOSWhJPUyJlwL6UBYMbhROXxBYQKurf2F8vQ2 I0Ej20rGdmMtdvsrArjfz2vjmxtLghQstMrZXz2N/lNTpVSSpmVcMF1Tbu4uHj9qIdpR 4T05fhu/0lI8lnntj2bKsIiegzZFmE+ONGCb4SAVmW9Sw7t10UWmTa1KTY2nnUZqq8QL zTbA== X-Received: by 10.66.124.229 with SMTP id ml5mr72078880pab.77.1441883901177; Thu, 10 Sep 2015 04:18:21 -0700 (PDT) Received: from localhost.localdomain ([49.206.249.64]) by smtp.gmail.com with ESMTPSA id wk6sm11483387pab.30.2015.09.10.04.18.19 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Sep 2015 04:18:20 -0700 (PDT) From: Sudip Mukherjee To: Mark Brown Cc: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Sudip Mukherjee Subject: [PATCH] spi: spidev: fix possible NULL dereference Date: Thu, 10 Sep 2015 16:48:13 +0530 Message-Id: <1441883893-20596-1-git-send-email-sudipm.mukherjee@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, 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 During the last close we are freeing spidev if spidev->spi is NULL, but just before checking if spidev->spi is NULL we are dereferencing it. Lets add a check there to avoid the NULL dereference. Signed-off-by: Sudip Mukherjee Reviewed-by: Jarkko Nikula Tested-by: Jarkko Nikula --- drivers/spi/spidev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index fba92a5..ef008e5 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c @@ -651,7 +651,8 @@ static int spidev_release(struct inode *inode, struct file *filp) kfree(spidev->rx_buffer); spidev->rx_buffer = NULL; - spidev->speed_hz = spidev->spi->max_speed_hz; + if (spidev->spi) + spidev->speed_hz = spidev->spi->max_speed_hz; /* ... after we unbound from the underlying device? */ spin_lock_irq(&spidev->spi_lock);