From patchwork Sat May 17 17:15:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rickard Strandqvist X-Patchwork-Id: 4196791 Return-Path: X-Original-To: patchwork-linux-rdma@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 4C3299F32B for ; Sat, 17 May 2014 17:14:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 542E820395 for ; Sat, 17 May 2014 17:14:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D1FC20306 for ; Sat, 17 May 2014 17:14:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030196AbaEQROn (ORCPT ); Sat, 17 May 2014 13:14:43 -0400 Received: from mail-ee0-f50.google.com ([74.125.83.50]:63100 "EHLO mail-ee0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964813AbaEQROm (ORCPT ); Sat, 17 May 2014 13:14:42 -0400 Received: by mail-ee0-f50.google.com with SMTP id e51so2337170eek.37 for ; Sat, 17 May 2014 10:14:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=whF7YXXDKv20S7pdq0f3ftVIoTOSp7uL8uOw9qMm/2I=; b=CzMkPsZKS2MI5V6noYgCB4ZbHSjJeZxPz6v6pvB2P2chX4v8E9WHbJSmzDBYOyB3gp nbIMNOW8LojAcfHeEXaGegsPrXSMcHiiIb+ldOdKxx29/+LKjG1QwNlba++nSNMy8gsC aQ3gqsm89ZOTXDyIeJgMb1E0+7gXs/C1KOP/Q29NGTOM2Mo71PNyqZ1viyQxT8RHI5Sg Vnp4LfQLpfEdlSX78SklHIw2gZosY2JUutOcYpAppaylSOOpTbUf9GdXV4NCxr7oW1vs YiI9X3HAGfK153wVCb1ZHIKXuNya7aE4MY80hiYojxtIoRmW/xYV6QDE8K3vK7UNvD5g aMoQ== X-Gm-Message-State: ALoCoQkYPl+KMSCEU/2JOONk9tY+000vxpWWUIRfaXp/f49Qxxirx4OnSovzmN4hRClvI4foSkBN X-Received: by 10.14.225.65 with SMTP id y41mr5455945eep.75.1400346881520; Sat, 17 May 2014 10:14:41 -0700 (PDT) Received: from localhost.localdomain (h-245-62.a218.priv.bahnhof.se. [85.24.245.62]) by mx.google.com with ESMTPSA id b12sm16614430eeh.45.2014.05.17.10.14.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 May 2014 10:14:40 -0700 (PDT) From: Rickard Strandqvist To: Hoang-Nam Nguyen , Christoph Raisch Cc: Rickard Strandqvist , Roland Dreier , Sean Hefty , Hal Rosenstock , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] infiniband: hw: ehca: ehca_mrmw.c: Fix for possible null pointer dereference Date: Sat, 17 May 2014 19:15:26 +0200 Message-Id: <1400346926-25235-1-git-send-email-rickard_strandqvist@spectrumdigital.se> X-Mailer: git-send-email 1.7.10.4 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 There is otherwise a risk of a possible null pointer dereference. Was largely found by using a static code analysis program called cppcheck. Signed-off-by: Rickard Strandqvist --- drivers/infiniband/hw/ehca/ehca_mrmw.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/ehca/ehca_mrmw.c b/drivers/infiniband/hw/ehca/ehca_mrmw.c index 3488e8c..1fe4344 100644 --- a/drivers/infiniband/hw/ehca/ehca_mrmw.c +++ b/drivers/infiniband/hw/ehca/ehca_mrmw.c @@ -316,9 +316,8 @@ struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, { struct ib_mr *ib_mr; struct ehca_mr *e_mr; - struct ehca_shca *shca = - container_of(pd->device, struct ehca_shca, ib_device); - struct ehca_pd *e_pd = container_of(pd, struct ehca_pd, ib_pd); + struct ehca_shca *shca; + struct ehca_pd *e_pd; struct ehca_mr_pginfo pginfo; int ret, page_shift; u32 num_kpages; @@ -330,6 +329,9 @@ struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, return ERR_PTR(-EFAULT); } + shca = container_of(pd->device, struct ehca_shca, ib_device); + e_pd = container_of(pd, struct ehca_pd, ib_pd); + if (((mr_access_flags & IB_ACCESS_REMOTE_WRITE) && !(mr_access_flags & IB_ACCESS_LOCAL_WRITE)) || ((mr_access_flags & IB_ACCESS_REMOTE_ATOMIC) &&