Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1924584pxa; Thu, 6 Aug 2020 21:01:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzw16BFeTgzoPOxChXuuLTVCrjDXt3D9hQBnbjCc+2dTfKb2r7oPj7sXLeU2kYCPlhnxTTO X-Received: by 2002:a05:6402:3130:: with SMTP id dd16mr444430edb.55.1596772898293; Thu, 06 Aug 2020 21:01:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596772898; cv=none; d=google.com; s=arc-20160816; b=wPPtNL5MK3UrJse0GlMpSJTZJ94G6kH0wv5Okd9op92qtrvssTYMrtSrbyyNpkK0dV MWK8KpTi7nqZ3hOlZS73o1ESYSlQ6x3I2jpd6s7sKj5pR0uZSElmnpIZawv4fniZP5Fp Svq8fz8IA+E7FEyMK3xPDpCGczNcYLcxwIp9cyxW+1eX0k00jaceg/hOhYWzI7FmeY9P GOdG4m6zdWjEcnuXPsUxZRZ1LHnfaa/mvdYHf00aUsAfTjztFvOTNLEOQTnbGn0aq0/v 4iUhjF7IRVOdB6YtDIPEEoDyRkOBoNKMYK/L2eOQxzVtJPvGVoc4nXMIEj/5P5ReKS9B xa+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=trd6XzNAFWlVlhnF00AGLAJ//+tyUA5NEjUQzobqU08=; b=vXOPtsr3po+5e/Lcc25PYSPo9kwoFyFRCOb6xhKA2bZ5wkjn6iaQtZ7Z/v2MCth3dC GKifZKXGwmx2FKHXgKtE16QX4DQayN79t/otU/fY1RamX0CDpiSowQON/axh8ZaKQiDn fnweOD1+W9dZZE2fP+kqfk42xsMiFI4+CFNXmofDPq1bAFDgHPDi61bHikU8HGOkV51c ZC0QdHfjIw1OOghkOiK4sZ/f6rdhg1pT26b2Z14db+99ull7/4Rr18I4NSeCaOwkbNtX 9O/Xs5veyJOi4WobORRfb87W9gC0cvQxLbSHeokZfB08u/kX43QP5/h6xE6z0VQWCIQi 6etw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MQjMvGzy; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si4501705edw.550.2020.08.06.21.01.15; Thu, 06 Aug 2020 21:01:38 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MQjMvGzy; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726401AbgHGD6g (ORCPT + 99 others); Thu, 6 Aug 2020 23:58:36 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:27069 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726066AbgHGD6g (ORCPT ); Thu, 6 Aug 2020 23:58:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596772714; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=trd6XzNAFWlVlhnF00AGLAJ//+tyUA5NEjUQzobqU08=; b=MQjMvGzyHpIfecOASrhi8Mr9viyxzrBMZ/IPaCWFcM2i8HBb2Q5mISn3zlYlSnK6lTLOYU 1jYariUWLjlOA/Oeikrlqcs0ExtRaJiPcVZsk/UhCh5D8JaPxGncHQQ/ekFfvIHRl6i3Wj LN4+TFHR/6cW6XsFDG3nfJTcBIe6VvY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-170-fVW1eGtFPm-D5zEmWHR_nA-1; Thu, 06 Aug 2020 23:58:30 -0400 X-MC-Unique: fVW1eGtFPm-D5zEmWHR_nA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 974998017FB; Fri, 7 Aug 2020 03:58:29 +0000 (UTC) Received: from [10.72.13.215] (ovpn-13-215.pek2.redhat.com [10.72.13.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12EA15F1EF; Fri, 7 Aug 2020 03:58:23 +0000 (UTC) Subject: Re: [PATCH][next] vdpa/mlx5: fix memory allocation failure checks To: Colin King , "Michael S . Tsirkin" , Eli Cohen , Parav Pandit , virtualization@lists.linux-foundation.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200806160828.90463-1-colin.king@canonical.com> From: Jason Wang Message-ID: Date: Fri, 7 Aug 2020 11:58:22 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200806160828.90463-1-colin.king@canonical.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/8/7 上午12:08, Colin King wrote: > 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 Acked-by: Jason Wang > --- > 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; > }