From patchwork Thu Mar 13 02:32:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3821641 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4BDA6BF540 for ; Thu, 13 Mar 2014 02:32:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6C818201FB for ; Thu, 13 Mar 2014 02:32:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D914201F0 for ; Thu, 13 Mar 2014 02:32:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753295AbaCMCct (ORCPT ); Wed, 12 Mar 2014 22:32:49 -0400 Received: from mail-pb0-f54.google.com ([209.85.160.54]:54454 "EHLO mail-pb0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752907AbaCMCcm (ORCPT ); Wed, 12 Mar 2014 22:32:42 -0400 Received: by mail-pb0-f54.google.com with SMTP id ma3so407410pbc.27 for ; Wed, 12 Mar 2014 19:32:42 -0700 (PDT) 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=T5QO1u2myjdD1lwVPmZhVknFkXTV90x3WKNGz6IZUTE=; b=kVFZ58miSGTmzPIYbLbvj1sp6H/GA163+SIjUW+b2fHROCcEyEFndwXsdMnHosF+I7 anHZZouwJ4X3QPXnruxflIk5/LtOf8TVmWfKC9LH8+WyWgad29qFQaptJwljm3MTWzZg Fz8V6/0hlN+Ru1iqhwwcqO2eludW2PjDIGGlG4bMkIP38Huum6sUMmAsCzMLbxJxzNci 6m7+CczI58OFmmC/tbeMzxe7uDk2O11vyytysrFESlq7CPz8Nx+ZHPBmGLGCqYVFhuSE ydkv1eK8pGhX2bbwjdNOf+WXno533qc11Z7hq8PDZoOItRzhxcDgPx2m9KToXTsD/xA6 zYwA== X-Gm-Message-State: ALoCoQlJykbwtiwcaDiHvZc4VWqsTs+dAsIm9BBzZz9oGnFZ6cBlRWR5WwtF+FSxThs2bHRN12Ob X-Received: by 10.66.11.202 with SMTP id s10mr1186258pab.86.1394677962016; Wed, 12 Mar 2014 19:32:42 -0700 (PDT) Received: from [192.168.1.102] (111-240-56-74.dynamic.hinet.net. [111.240.56.74]) by mx.google.com with ESMTPSA id sm5sm1810973pab.19.2014.03.12.19.32.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Mar 2014 19:32:41 -0700 (PDT) Message-ID: <1394677957.15733.1.camel@phoenix> Subject: [PATCH] spi: sh-sci: Prevent NULL pointer dereference From: Axel Lin To: Mark Brown Cc: Magnus Damm , linux-spi@vger.kernel.org Date: Thu, 13 Mar 2014 10:32:37 +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 sp->info is NULL, we will hit NULL pointer dereference in probe() while setting bus_num and num_chipselect for master: sp->bitbang.master->bus_num = sp->info->bus_num; sp->bitbang.master->num_chipselect = sp->info->num_chipselect; Thus add NULL test for sp->info in probe() to prevent NULL pointer dereference. Signed-off-by: Axel Lin Reviewed-by: Geert Uytterhoeven --- drivers/spi/spi-sh-sci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-sh-sci.c b/drivers/spi/spi-sh-sci.c index 85c2efd..8b44b71 100644 --- a/drivers/spi/spi-sh-sci.c +++ b/drivers/spi/spi-sh-sci.c @@ -108,7 +108,7 @@ static void sh_sci_spi_chipselect(struct spi_device *dev, int value) { struct sh_sci_spi *sp = spi_master_get_devdata(dev->master); - if (sp->info && sp->info->chip_select) + if (sp->info->chip_select) (sp->info->chip_select)(sp->info, dev->chip_select, value); } @@ -130,6 +130,11 @@ static int sh_sci_spi_probe(struct platform_device *dev) platform_set_drvdata(dev, sp); sp->info = dev_get_platdata(&dev->dev); + if (!sp->info) { + dev_err(&dev->dev, "platform data is missing\n"); + ret = -ENOENT; + goto err1; + } /* setup spi bitbang adaptor */ sp->bitbang.master = master;