Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1585811pxa; Thu, 6 Aug 2020 10:54:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5+5gQlMOjbbiQmU8fZf7ybqhDFxZz1dAn1LvCY40YTM2PLjo+S1cuwNK4j6tzgD5ZrsiO X-Received: by 2002:a50:b285:: with SMTP id p5mr5210985edd.139.1596736474876; Thu, 06 Aug 2020 10:54:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596736474; cv=none; d=google.com; s=arc-20160816; b=IJv8OA/A0iFnMqHQLbO00ie1Ktd2G0ZHiC9SLRFe5R0WCneBb/SA33nKjJZQPWsCvb kduJORhMUhguEKY2H9SB8QE1Vx+nLzuq6ignNr8mq9PAQkXdFMTalvjULAMUOHgwUIyo zakIsQ/oepalK+jzc+3tJDbmrndBZiuckga+qtcy5bACfq0XrbVqcWXda5ptddnicXqO v62ve6S78RaVpOWLRgf0zBlpjMS+5DLW4f4zetimElaEB9Uxx6GALTbbXNgQmI7q/f9Y l3KGzn1UWKt2x0IJxPrYbAMrOTETEMez+/mWkw0/7xalsQxFkkmDnX3QOgI8Wa2AFicP 4LQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=8yTHvMgTpXz9fcKn9XWvyY/57LlgDyemqBTyMwDyQec=; b=ZD3Q89CiwKvPqelc5ncdD07zzfOGldeljE3q4QArLICLtRqzXlUhrPask4WajaL90w oCSfi6nLCTLqE4ezr517Afdk4oOJBq0Idm+uygm5rRGxBvH8fnFUz+jBgIoad1P58/ei Oha2kAJM/Ifvpp/vS5lEwXTh4WnkMUza/HT0WnSIJdFf/uSbNj/yujT/sRhchzf/aU1G a8NUbGHGYh4wnbnymM/yPU1wvwZK8HBfP7iKiCtLZby78QunXa9e9rAuzutHJWhwy8Gv K8UhQUuXHI0lKnihJJzTLfpjmujsfiFjM05MJczfc4UpYANM99DSJ0eOr9gDTbX43hbH HI/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n7si3942843ejl.448.2020.08.06.10.54.12; Thu, 06 Aug 2020 10:54:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730573AbgHFRxr (ORCPT + 99 others); Thu, 6 Aug 2020 13:53:47 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:50371 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728328AbgHFQa7 (ORCPT ); Thu, 6 Aug 2020 12:30:59 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1k3iRR-0001NL-01; Thu, 06 Aug 2020 16:08:29 +0000 From: Colin King To: "Michael S . Tsirkin" , Jason Wang , Eli Cohen , Parav Pandit , virtualization@lists.linux-foundation.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] vdpa/mlx5: fix memory allocation failure checks Date: Thu, 6 Aug 2020 17:08:28 +0100 Message-Id: <20200806160828.90463-1-colin.king@canonical.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King The memory allocation failure checking for in and out is currently checking if the pointers are valid rather than the contents of what they point to. Hence the null check on failed memory allocations is incorrect. Fix this by adding the missing indirection in the check. Also for the default case, just set the *in and *out to null as these don't have any thing allocated to kfree. Finally remove the redundant *in and *out check as these have been already done on each allocation in the case statement. Addresses-Coverity: ("Null pointer dereference") Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices") Signed-off-by: Colin Ian King --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 3ec44a4f0e45..55bc58e1dae9 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -867,7 +867,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl *outlen = MLX5_ST_SZ_BYTES(qp_2rst_out); *in = kzalloc(*inlen, GFP_KERNEL); *out = kzalloc(*outlen, GFP_KERNEL); - if (!in || !out) + if (!*in || !*out) goto outerr; MLX5_SET(qp_2rst_in, *in, opcode, cmd); @@ -879,7 +879,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl *outlen = MLX5_ST_SZ_BYTES(rst2init_qp_out); *in = kzalloc(*inlen, GFP_KERNEL); *out = kzalloc(MLX5_ST_SZ_BYTES(rst2init_qp_out), GFP_KERNEL); - if (!in || !out) + if (!*in || !*out) goto outerr; MLX5_SET(rst2init_qp_in, *in, opcode, cmd); @@ -896,7 +896,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl *outlen = MLX5_ST_SZ_BYTES(init2rtr_qp_out); *in = kzalloc(*inlen, GFP_KERNEL); *out = kzalloc(MLX5_ST_SZ_BYTES(init2rtr_qp_out), GFP_KERNEL); - if (!in || !out) + if (!*in || !*out) goto outerr; MLX5_SET(init2rtr_qp_in, *in, opcode, cmd); @@ -914,7 +914,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl *outlen = MLX5_ST_SZ_BYTES(rtr2rts_qp_out); *in = kzalloc(*inlen, GFP_KERNEL); *out = kzalloc(MLX5_ST_SZ_BYTES(rtr2rts_qp_out), GFP_KERNEL); - if (!in || !out) + if (!*in || !*out) goto outerr; MLX5_SET(rtr2rts_qp_in, *in, opcode, cmd); @@ -927,16 +927,15 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl MLX5_SET(qpc, qpc, rnr_retry, 7); break; default: - goto outerr; + goto outerr_nullify; } - if (!*in || !*out) - goto outerr; return; outerr: kfree(*in); kfree(*out); +outerr_nullify: *in = NULL; *out = NULL; } -- 2.27.0