From patchwork Fri Aug 19 06:07:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 12948382 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D51CCC25B0E for ; Fri, 19 Aug 2022 06:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345309AbiHSGIM (ORCPT ); Fri, 19 Aug 2022 02:08:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245318AbiHSGIH (ORCPT ); Fri, 19 Aug 2022 02:08:07 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E437CC57B4 for ; Thu, 18 Aug 2022 23:08:06 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id j8so6968806ejx.9 for ; Thu, 18 Aug 2022 23:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=8hlJvz8Cg/RSrujn6eg6W9O1c50l+s7v5Bap/Ro2DSs=; b=QpTQj96OHSBiF7tI4jxZPrwsWxnv4EMkhARwtlJprTIv0jkFZqhlyuPYYGl9KsPENl V2MRG7o8n1+53/ashGW+rbaOAwckPTDDZDNRLjDq7/V7AYlSfCrPfInQ9W6vxdbNp/wF ZRFqu6lJtWWZ75FOnCHvpGQtfg3P657Qk/k00u8/4fg2escTuXxi4US8QHzEhCkwf5ub oScgZsOAZ9OSr/s7CTzJOLQN1cMzXs2UdmC9xtl4D4MRU0C8CvYTVWQ4TkuTvaQFbonH BSXM8qdXESIWM1gpwM9CIahklf7IxLUpxK6WtBRkVSTcgKBgAzhi/jaloiDTsDuEUGHv 5Y6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=8hlJvz8Cg/RSrujn6eg6W9O1c50l+s7v5Bap/Ro2DSs=; b=4aez6+fbPtj3hkingqJEm+TLLpAezndcQk0VCL9M6aO5qZPinpLvZpJ4oyAI2bfhCl DCdtBPxNa++U4NanayGQCmzRhfQTQVlkuF0qEl367yz8DaQz4AuRO2ATaQCRbHBuNQ15 XQ/jmJjgRgWmGn3idIEAe5A8A/P7a4kMAq3s1Df9Peeqz66OLYCiJK7BJrVrLfkFy4Un 97QXaB6pGLrA/JfYlYNZ70eZobUzRsmizGKa0gATlsIS/uRCLEhHYH83Ukeex8Sazy77 daT+Qz+iklB1qndINU4P7EvUjFFElSt1YMJNxOn9wcdC8jGxBvaouKdsvurVu44MthT+ G5mg== X-Gm-Message-State: ACgBeo2f8eK0Vb1KFtZTkTACfxOd6L+0r6hzt+C7t0oUO93se/dzg0ji vLVPW8msHEnX1dZnrUhoMxK9JQ== X-Google-Smtp-Source: AA6agR7/JhpdOMPLzO6RkZBvrR6nCK3+sQ6xgvqtcn+PCOKPalLO6+fAFWB2nSXAP9dj6tiCFYn9Uw== X-Received: by 2002:a17:906:8b81:b0:733:183b:988e with SMTP id nr1-20020a1709068b8100b00733183b988emr3834146ejc.457.1660889285398; Thu, 18 Aug 2022 23:08:05 -0700 (PDT) Received: from lb02065.fritz.box ([2001:9e8:143b:fd00:5207:8c7f:747a:b80d]) by smtp.gmail.com with ESMTPSA id y14-20020a1709063a8e00b0073a644ef803sm1809660ejd.101.2022.08.18.23.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 23:08:04 -0700 (PDT) From: Jack Wang To: linux-kernel@vger.kernel.org Cc: Jason Gunthorpe , Leon Romanovsky , Christophe JAILLET , Kees Cook , =?utf-8?q?H=C3=A5kon_Bugge?= , linux-rdma@vger.kernel.org Subject: [PATCH v1 02/19] infiniband/mthca: Fix dma_map_sg error check Date: Fri, 19 Aug 2022 08:07:44 +0200 Message-Id: <20220819060801.10443-3-jinpu.wang@ionos.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220819060801.10443-1-jinpu.wang@ionos.com> References: <20220819060801.10443-1-jinpu.wang@ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org dma_map_sg return 0 on error, in case of error set EIO as return code. Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: Christophe JAILLET Cc: Kees Cook Cc: "HÃ¥kon Bugge" Cc: linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Jack Wang Reviewed-by: Kees Cook --- drivers/infiniband/hw/mthca/mthca_memfree.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c index f2734a5c5f26..44fd5fdf64d5 100644 --- a/drivers/infiniband/hw/mthca/mthca_memfree.c +++ b/drivers/infiniband/hw/mthca/mthca_memfree.c @@ -189,7 +189,7 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages, chunk->npages, DMA_BIDIRECTIONAL); - if (chunk->nsg <= 0) + if (!chunk->nsg) goto fail; } @@ -208,7 +208,7 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages, chunk->nsg = dma_map_sg(&dev->pdev->dev, chunk->mem, chunk->npages, DMA_BIDIRECTIONAL); - if (chunk->nsg <= 0) + if (!chunk->nsg) goto fail; } @@ -482,8 +482,9 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar, ret = dma_map_sg(&dev->pdev->dev, &db_tab->page[i].mem, 1, DMA_TO_DEVICE); - if (ret < 0) { + if (!ret) { unpin_user_page(pages[0]); + ret = -EIO; goto out; } From patchwork Fri Aug 19 06:08:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 12948383 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C249DC32772 for ; Fri, 19 Aug 2022 06:10:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346676AbiHSGKD (ORCPT ); Fri, 19 Aug 2022 02:10:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346670AbiHSGJT (ORCPT ); Fri, 19 Aug 2022 02:09:19 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADEB43F326 for ; Thu, 18 Aug 2022 23:08:34 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id c39so4476887edf.0 for ; Thu, 18 Aug 2022 23:08:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=MQQ5ueYXwF1mgVuBzhpDoSiarWWxcP+kFd0K52asQnw=; b=UJ8fUY4TBBq/TG6MOQupt3Ca8oMqHbkfKb3rW32eIJXKGf8rriXtcQuht5HRT+uI+b /1I/3QlQTBiYtQyoCjG3k8PmdewX1V/uYmtVT9QY4yVxm9VZ7arJUigNUV//Z6LZj1ts UP6L4uHCOc8l1xbbiZPLnLO9Lu3mj2x0J4S9A9ZshmFeIPMpzFFoGn4rIxOhHdCNlp3v ks8QLaHIx2sYfETf4glt1lcF4B1ty3UFK4WsMunfm8bv0UoPjy7V0NA5t4JFcwwU6z1y mvfHq/oAbzId5oj+M3S89Vds8ALHVVB/ojTU0sWRNMVajI/dW+sLa9z3o3F3pOPVYaBq 73hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=MQQ5ueYXwF1mgVuBzhpDoSiarWWxcP+kFd0K52asQnw=; b=nQ5gOSBdChSWTj2ZCqCKBd9JhGyRSZ+3CLjcWmUPzcmMYaqQJojQK7homdD3mjqzKK EYc6enYiEeUbqUjQW3CvVE9PPbcHbqdFOz/8wnOt+1wuySvJJLYwNXZwdipE3xNPNinQ MZtBQr98waiqdWvLe5PvBygNRye/Yj6Oo9Yxf94ChV/38Z7uNmMHZVfvLnkzo+PBdpvf WqnZwAW2fF7BS1nWO2YxLN+/XNyTYO1obW6Y3EF9h0qPRWdMzdmyGl0HVD9vkVu3AoG6 v2qhRHHh4/3Nvg8KvoeOVwGTGoOmT1U8BTa8j6ryOzgPoE1Vcw6rDHGDQlecOE2coOxa b+nA== X-Gm-Message-State: ACgBeo3X1eMcjGy0sEjBbJkxykCKvOVwpaJx8o8vserSlRBP0kojB7Nj UPNuYtBBF7nkFxL83PiOIZmOWUHWEQaKN6ez X-Google-Smtp-Source: AA6agR5qrhKSw7oa0pDZk68ViIpC2FB5ZmkkWaDCBIhx8mIj19+nf9D2Fwy8CN4MThe75Z3lcCNpuw== X-Received: by 2002:aa7:dd50:0:b0:440:3e9d:784 with SMTP id o16-20020aa7dd50000000b004403e9d0784mr4859887edw.195.1660889313038; Thu, 18 Aug 2022 23:08:33 -0700 (PDT) Received: from lb02065.fritz.box ([2001:9e8:143b:fd00:5207:8c7f:747a:b80d]) by smtp.gmail.com with ESMTPSA id y14-20020a1709063a8e00b0073a644ef803sm1809660ejd.101.2022.08.18.23.08.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 23:08:32 -0700 (PDT) From: Jack Wang To: linux-kernel@vger.kernel.org Cc: Tariq Toukan , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH v1 19/19] net/mlx4: Fix error check for dma_map_sg Date: Fri, 19 Aug 2022 08:08:01 +0200 Message-Id: <20220819060801.10443-20-jinpu.wang@ionos.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220819060801.10443-1-jinpu.wang@ionos.com> References: <20220819060801.10443-1-jinpu.wang@ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org dma_map_sg return 0 on error. Cc: Tariq Toukan Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: netdev@vger.kernel.org Cc: linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Jack Wang Reviewed-by: Leon Romanovsky --- drivers/net/ethernet/mellanox/mlx4/icm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/icm.c b/drivers/net/ethernet/mellanox/mlx4/icm.c index d89a3da89e5a..59b8b3c73582 100644 --- a/drivers/net/ethernet/mellanox/mlx4/icm.c +++ b/drivers/net/ethernet/mellanox/mlx4/icm.c @@ -208,7 +208,7 @@ struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages, chunk->sg, chunk->npages, DMA_BIDIRECTIONAL); - if (chunk->nsg <= 0) + if (!chunk->nsg) goto fail; } @@ -222,7 +222,7 @@ struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages, chunk->nsg = dma_map_sg(&dev->persist->pdev->dev, chunk->sg, chunk->npages, DMA_BIDIRECTIONAL); - if (chunk->nsg <= 0) + if (!chunk->nsg) goto fail; }