From patchwork Sun Mar 9 06:11:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3799431 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1CA239F2BB for ; Sun, 9 Mar 2014 06:11:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 405B72035D for ; Sun, 9 Mar 2014 06:11:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6181E20340 for ; Sun, 9 Mar 2014 06:11:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751398AbaCIGLQ (ORCPT ); Sun, 9 Mar 2014 01:11:16 -0500 Received: from mail-pa0-f52.google.com ([209.85.220.52]:53210 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751231AbaCIGLQ (ORCPT ); Sun, 9 Mar 2014 01:11:16 -0500 Received: by mail-pa0-f52.google.com with SMTP id rd3so5910355pab.25 for ; Sat, 08 Mar 2014 22:11:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:content-type :mime-version:content-transfer-encoding; bh=vpTsV46VAFb+DL89CCAkL8EKZf8ZUryeSKEigY1bEfE=; b=F7N8JmFufsnM1pAiP2JT0EANm6lW0F6dq0/Yr3iPFz7b0CAGp9AQveA/BRKX9ET6ep dqKpUxHgPJQAS2U1Dnlk9Ci3AsVhan5plIdk7OkxJOu+EWlzrcqx5oEsmYEMOarDOWjn sRy7HdMzl7jTCyjRpis10q62BnzWt/JKvT+6Nn40y7GAOqF71yLJt24ofAm1dImOXuRD FALtjk08E33mdIByofSzu0vriW0M+uLMZVWTWjTdw+UTERPWjkTrByqxAV3fV+E8uG5u Hcdm7a1SAFA4NbXn4V0qel4sGO8nijHM6ITi3XJj0Ckw70taQwtMwvZQo7O5jFZpJcCz iFDg== X-Gm-Message-State: ALoCoQm+JjW63AG7Yo80WJGYAUJzdE9T8QJJm5QJ5JWF/TSG3dXJC5V1DCG/Qq4wqjExSaiCGA1B X-Received: by 10.66.243.131 with SMTP id wy3mr32800941pac.32.1394345475655; Sat, 08 Mar 2014 22:11:15 -0800 (PST) Received: from [192.168.0.102] (218-164-148-253.dynamic.hinet.net. [218.164.148.253]) by mx.google.com with ESMTPSA id un5sm48486422pab.3.2014.03.08.22.11.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 08 Mar 2014 22:11:15 -0800 (PST) Message-ID: <1394345470.15686.1.camel@phoenix> Subject: [PATCH] spi: coldfire-qspi: Prevent NULL pointer dereference From: Axel Lin To: Mark Brown Cc: Steven King , linux-spi@vger.kernel.org Date: Sun, 09 Mar 2014 14:11:10 +0800 X-Mailer: Evolution 3.6.4-0ubuntu1 Mime-Version: 1.0 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.9 required=5.0 tests=BAYES_00, 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 If pdata->cs_control is NULL, we will hit NULL pointer dereference in mcfqspi_cs_select() and mcfqspi_cs_deselect(). Thus add NULL test for pdata->cs_control in probe(). Signed-off-by: Axel Lin --- drivers/spi/spi-coldfire-qspi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-coldfire-qspi.c b/drivers/spi/spi-coldfire-qspi.c index c29bbb0..b01616c 100644 --- a/drivers/spi/spi-coldfire-qspi.c +++ b/drivers/spi/spi-coldfire-qspi.c @@ -133,13 +133,13 @@ static void mcfqspi_cs_deselect(struct mcfqspi *mcfqspi, u8 chip_select, static int mcfqspi_cs_setup(struct mcfqspi *mcfqspi) { - return (mcfqspi->cs_control && mcfqspi->cs_control->setup) ? + return (mcfqspi->cs_control->setup) ? mcfqspi->cs_control->setup(mcfqspi->cs_control) : 0; } static void mcfqspi_cs_teardown(struct mcfqspi *mcfqspi) { - if (mcfqspi->cs_control && mcfqspi->cs_control->teardown) + if (mcfqspi->cs_control->teardown) mcfqspi->cs_control->teardown(mcfqspi->cs_control); } @@ -366,6 +366,11 @@ static int mcfqspi_probe(struct platform_device *pdev) return -ENOENT; } + if (!pdata->cs_control) { + dev_dbg(&pdev->dev, "pdata->cs_control is NULL\n"); + return -EINVAL; + } + master = spi_alloc_master(&pdev->dev, sizeof(*mcfqspi)); if (master == NULL) { dev_dbg(&pdev->dev, "spi_alloc_master failed\n");