From patchwork Sat Nov 15 18:56:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 5312081 Return-Path: X-Original-To: patchwork-linux-mmc@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 853AF9F2ED for ; Sat, 15 Nov 2014 18:55:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AE95E201BC for ; Sat, 15 Nov 2014 18:55:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9FBE8201B9 for ; Sat, 15 Nov 2014 18:55:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754314AbaKOSzq (ORCPT ); Sat, 15 Nov 2014 13:55:46 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:29632 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754297AbaKOSzp (ORCPT ); Sat, 15 Nov 2014 13:55:45 -0500 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id sAFItOoH004245 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 15 Nov 2014 18:55:25 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id sAFItKWA004830 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Sat, 15 Nov 2014 18:55:22 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id sAFItKkh019866; Sat, 15 Nov 2014 18:55:20 GMT Received: from mwanda (/154.0.139.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 15 Nov 2014 10:55:19 -0800 Date: Sat, 15 Nov 2014 21:56:41 +0300 From: Dan Carpenter To: Chris Ball , Ondrej Zary Cc: Ulf Hansson , linux-mmc@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] mmc: toshsd: move dereference below check for NULL Message-ID: <20141115185641.GA6530@mwanda> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@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=unavailable 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 We check for NULL pointers after dereferencing so it's too late. Oddly enough, Smatch misses this code but complains about the caller passing NULL pointers to this function: drivers/mmc/host/toshsd.c:389 toshsd_irq() error: we previously assumed 'host->cmd' could be null (see line 349) Signed-off-by: Dan Carpenter --- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/host/toshsd.c b/drivers/mmc/host/toshsd.c index edb06d6..4666262 100644 --- a/drivers/mmc/host/toshsd.c +++ b/drivers/mmc/host/toshsd.c @@ -206,14 +206,14 @@ static irqreturn_t toshsd_thread_irq(int irq, void *dev_id) static void toshsd_cmd_irq(struct toshsd_host *host) { struct mmc_command *cmd = host->cmd; - u8 *buf = (u8 *) cmd->resp; + u8 *buf; u16 data; if (!host->cmd) { dev_warn(&host->pdev->dev, "Spurious CMD irq\n"); return; } - + buf = (u8 *)cmd->resp; host->cmd = NULL; if (cmd->flags & MMC_RSP_PRESENT && cmd->flags & MMC_RSP_136) {